Claude Code's model field appended its own models to the list it keeps
of magpie's (claudeViaShared), a copy of the whole catalog on every
call, as withVia did for the other agents until cdfdb62c6. With real
accounts, 40 window polls spent 9 MB flat in that append.
withVia's cache is now joinedVia, keyed by the caller, and the field
reads through it, here and in a distro asleep (wsl.go). withVia still
gives the shared list itself when there are no own models; joinedVia
always gives a list apart from via, so a write to the model field's
options never reaches the list kept (TestClaudeViaMagpieKept).
Run on mote (macOS), at this tree:
- gofmt clean; go vet ./internal/agent for darwin, windows and linux.
- TestClaudeModelFieldKeepsTheJoinedList, TestWithVia*, TestClaudeVia*
and TestSameOption* alone 3/3 ok.
- Broken by hand: the plain append back -> "Claude Code's own models
joined its list from magpie again"; joinedVia handing out via with no
own models -> TestClaudeViaMagpieKept "a write to the model field's
options reached the options kept (folded true)".
- go test ./internal/agent ./internal/tui ./internal/cli: ok.
- go test ./internal/gui: red only on #4514 and #3949, as before.
- Real-account sandbox, 40 window polls against the GroupFinder tree:
Agent.Picks 56.4 -> 42.6 MB, gui.state 138.0 -> 130.0 MB; /api/state
and drift output byte-identical; phys_footprint_peak 139 MB.
Not run: the whole ./... suite; a real WSL distro.
77 lines
2.5 KiB
Go
77 lines
2.5 KiB
Go
package agent
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"strconv"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// Claude Code's magpie list is kept as viaMagpie is: its model and tier
|
|
// fields asked it each poll, for the picker and again for Drift, built
|
|
// anew each time (30 MB of forty polls with real accounts). Each caller
|
|
// still has a copy of its own, and a provider saved since is offered.
|
|
func TestClaudeViaMagpieKept(t *testing.T) {
|
|
syncHome(t)
|
|
models := []string{"claude-opus-5-5", "gpt-5.4"}
|
|
for i := range 100 {
|
|
models = append(models, "m"+strconv.Itoa(i))
|
|
}
|
|
if err := provider.Save(provider.Provider{ID: "oa", Name: "OA", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: models}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
values := func() map[string]bool {
|
|
out := map[string]bool{}
|
|
for _, o := range claudeViaMagpie(false) {
|
|
out[o.Value] = true
|
|
}
|
|
return out
|
|
}
|
|
if got := values(); !got["oa/gpt-5.4"] {
|
|
t.Fatalf("oa's models not offered: %v", got)
|
|
}
|
|
built := testing.AllocsPerRun(5, func() { buildClaudeVia(false) })
|
|
kept := testing.AllocsPerRun(20, func() { claudeViaMagpie(false) })
|
|
if kept > 20 || kept*5 > built {
|
|
t.Fatalf("Claude Code's options already built took %.0f allocations, building them %.0f", kept, built)
|
|
}
|
|
mine := claudeViaMagpie(false)
|
|
for i := range mine {
|
|
mine[i].Value = "x"
|
|
}
|
|
if got := values(); !got["oa/gpt-5.4"] {
|
|
t.Fatalf("a caller's write reached the options kept: %v", got)
|
|
}
|
|
// the model field joins the list kept to its own models: its
|
|
// options are never the kept list itself, even with no own models
|
|
home := os.Getenv("HOME")
|
|
writeFile(t, filepath.Join(home, ".claude", "settings.json"), `{}`)
|
|
field := claude(home).Field("model").Options(map[string]string{})
|
|
if !slices.ContainsFunc(field, func(o Option) bool { return o.Value == "oa/gpt-5.4" }) {
|
|
t.Fatal("the model field doesn't offer oa's models")
|
|
}
|
|
for i := range field {
|
|
field[i].Value = "x"
|
|
}
|
|
for _, fold := range []bool{false, true} {
|
|
if slices.ContainsFunc(claudeViaMagpie(fold), func(o Option) bool { return o.Value == "x" }) {
|
|
t.Fatalf("a write to the model field's options reached the options kept (folded %v)", fold)
|
|
}
|
|
}
|
|
// folded and not are kept apart
|
|
for _, o := range claudeViaMagpie(true) {
|
|
if o.Value == "x" {
|
|
t.Fatal("the folded list is the other one")
|
|
}
|
|
}
|
|
if err := provider.Save(provider.Provider{ID: "nb", Name: "NB", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"y"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !values()["nb/y"] {
|
|
t.Fatal("a provider saved since is not offered")
|
|
}
|
|
}
|