Files
magpie/internal/agent/agy_effort_test.go
T
yetone 1a37cc8516 agent: Antigravity CLI's thinking effort is picked in its row, and the gateway asks it of Gemini
xyenon on Discord: agy's effort can't be set for magpie's models. agy 1.5.3
has --effort for one session only, and turns it away for a custom model
(/effort says "not adjustable"); settings.json has no key for it (--settings
rejects every name tried as an unknown setting). Its requests ask
thinkingConfig {"includeThoughts":true,"thinkingBudget":-1}, the model's own
choice. So the pick lives in magpie, as the Antigravity app's and Cursor
Private Inference's do: agy's row gets an effort field
(provider.AgentEffort("agy")), shown while agy is on magpie's models, with
the levels the model lists. Nothing picked leaves agy's requests as today.

The gateway had no Gemini case in withFixedEffort, so a pick, a fixed member,
a rule's effort or a mapped level did nothing on a Gemini-wire request.
withGeminiEffort writes the thinkingConfig as the model takes it, from
vertexBudgets: a Gemini 2.5 gets a budget in its range (it refuses a level;
none is its least, or 0 for flash), a Gemini 3 a level from low to high
(minimal kept), a Gemini before 2.5 is left alone. includeThoughts is kept as
asked. The effort block and the needs-reasoning retry call it with the
upstream model (withModelEffort).

At a stopped WSL distro the field reads nothing (#3896), as
TestWSLColdPlaceOpensNothing asks.

Run on mote (mote-run), at the pushed head (rebased on 192d2eda8):
- gofmt -l: clean. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: clean.
- go test ./internal/agent ./internal/gateway, whole packages: ok
  (gateway 943s) before the rebase; internal/agent again whole after the
  cold fix: ok. At the head: -run "Agy|WSLCold|AntigravityEffort" and
  -run "Agy|Effort": ok.
- GUI: agy-effort.test.cjs (new; window and panel, chromium and webkit,
  en zh zh-TW ja de) and cursor-local-effort: 54 pass, 0 fail.
  agent-field-names, agent-layout pass; i18n-keys' "a plugin's words are
  its own" is red as on main (#5332).

Broken by hand, each red then restored:
- withModelEffort returning the body as sent: TestAgyAgentEffort red
  (thinkingBudget -1 sent at high).
- agy's effort field taken out: TestAgyEffort red ("no effort field").
- 2.5's budgets taken from vertexBudgets: TestAgyAgentEffort and
  TestWithGeminiEffort red (thinkingLevel sent to gemini-2.5-flash).
- the field's cold check taken out (its first version):
  TestWSLColdPlaceOpensNothing red, stat of agy's settings.json.

Not tried: the full ./... suite (the suite lock on mote had ~10 runs queued,
some for 9h; agent and gateway were run whole instead); the real agy binary
against a sandbox gateway (TestAgyAgentEffort sends agy 1.5.3's captured
request body); a real Gemini API with a pick; a real stopped distro.

Reported-by: xyenon
2026-11-09 04:48:46 +08:00

77 lines
2.5 KiB
Go

package agent
import (
"os"
"path/filepath"
"slices"
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/provider"
)
// agy has no effort magpie can write (xyenon on Discord): settings.json has
// no key for it and --effort, for one session, is turned away for magpie's
// models. Its row picks one, kept in magpie (provider.AgentEffort "agy"),
// among the levels its models have, offered only while agy is on magpie's;
// settings.json is never touched for it.
func TestAgyEffort(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
if err := provider.Save(provider.Provider{ID: "think", Name: "Think", Chat: "https://think.test/v1", Key: "key", Models: []string{"gemini-3.8-flash"}}); err != nil {
t.Fatal(err)
}
if err := catalog.SaveLive("think", "https://think.test/v1", []catalog.Model{{ID: "gemini-3.8-flash", Efforts: []string{"low", "high"}}}); err != nil {
t.Fatal(err)
}
path := filepath.Join(home, ".gemini", "antigravity-cli", "settings.json")
os.MkdirAll(filepath.Dir(path), 0o755)
os.WriteFile(path, []byte(`{"model":"mine","modelProvider":"vertex"}`), 0o644)
a, err := Find("agy")
if err != nil {
t.Fatal(err)
}
f := a.Field("effort")
if f == nil {
t.Fatal("no effort field")
}
values := func() []string {
var out []string
for _, o := range f.Options(map[string]string{}) {
out = append(out, o.Value)
}
return out
}
if got := values(); got != nil {
t.Fatalf("offered %q while on the user's own model", got)
}
if err := a.Apply("model", "magpie/think/gemini-3.8-flash"); err != nil {
t.Fatal(err)
}
if got := values(); !slices.Equal(got, []string{"", "low", "high"}) {
t.Fatalf("offered %q", got)
}
before, _ := os.ReadFile(path)
if err := f.Set("high"); err != nil {
t.Fatal(err)
}
if got, kept := f.Get(), provider.AgentEffort("agy"); got != "high" || kept != "high" {
t.Fatalf("picked high: shown %q, kept %q", got, kept)
}
if provider.AgentEffort("antigravity") != "" {
t.Fatal("agy's pick went to Antigravity's app")
}
if after, _ := os.ReadFile(path); string(after) != string(before) {
t.Errorf("the pick touched settings.json:\n%s\nwas\n%s", after, before)
}
if err := f.Set("hard"); err == nil {
t.Fatal("a word that isn't a level was kept")
}
if err := f.Set(""); err != nil || provider.AgentEffort("agy") != "" {
t.Fatalf("back to the default: %v, kept %q", err, provider.AgentEffort("agy"))
}
}