Files
magpie/internal/agent/drift_options_test.go
T
yetone c1457f2eec agent: Drift makes a field's options once a look
Drift asked magpieValue up to three times a field: once to find the
field on magpie's models, then for magpie's record and the value now.
Each ask made the field's options anew, and Claude Code's (its own
models and claudeViaMagpie) are long. fieldOptions keeps each field's
options, by key, for one Drift; magpieValue is unchanged for the other
callers.

Run on mote at this tree:
- gofmt clean; go vet ./internal/agent ok on darwin, GOOS=windows and
  GOOS=linux.
- TestDriftMakesAFieldsOptionsOnce ok 3 of 3 alone. Broken by hand
  (opts left nil in Drift): "one Drift made the field's options 3
  times, want once".
- go test ./internal/agent: ok (324.6s).

Real accounts (sandbox copy of the owner's config, network blocked,
40 rounds of /api/drift, /api/state, /api/providers), v0.1.2488 tree
against this one:
- Drift 54.3 -> 45.3 MB, magpieValue 47.1 -> 42.6 MB, claudeIn.func57
  39.7 -> 33.8 MB; total 613 -> 587 MB (totals move +-25 MB between
  runs).
- /api/state and /api/drift byte for byte the same.
- footprint peak 138 MB, RSS 180 MB: unchanged.

Not run: the gui suite (gui is not touched).

Run at 573b21f4b; picked onto 3f2faef62 after it (11 commits, in
internal/agent only dsh.go and a Responses test), not run again there.
2026-11-01 06:30:39 +08:00

36 lines
1.1 KiB
Go

package agent
import "testing"
// Drift asked a field's options up to three times, once a field to find
// the one on magpie and twice to compare it with magpie's record, and
// Claude Code's were made anew each time (35 MB of forty polls with real
// accounts). They are made once a look now.
func TestDriftMakesAFieldsOptionsOnce(t *testing.T) {
v, made := "", 0
a := &Agent{ID: "drift-options", Name: "X", Fields: []Field{{Key: "model", Label: "Model",
Get: func() string { return v },
Set: func(s string) error { v = s; return nil },
Options: func(map[string]string) []Option {
made++
return []Option{
{Value: "nowhere-relay/m1", Ref: "nowhere-relay/m1"},
{Value: "nowhere-relay/m2", Ref: "nowhere-relay/m2"},
}
},
}}}
if err := a.Apply("model", "nowhere-relay/m1"); err != nil {
t.Fatal(err)
}
// another of magpie's models, picked in the agent: not drift, and every
// comparison read the options
v = "nowhere-relay/m2"
made = 0
if d := a.Drift(); d != nil {
t.Fatalf("one magpie model for another drifted: %+v", d)
}
if made != 1 {
t.Fatalf("one Drift made the field's options %d times, want once", made)
}
}