Goose's model field asked ownOptions each poll, for the picker and again for Drift, and each provider's models were made into options anew (catalog.Provider, options, group, its icon): ownOptionsFrom was 21.2 MB of forty polls with real accounts. For agents without a registry of their own (native == nil), each provider's options are now kept in ownBuilt per provider.StampNow (a minute at most) and copied into the caller's list; Pi's and omp's, which read their own registries, are built as before (ownProvider is the old loop body). TestOwnOptionsKept: a catalog of 200 OpenAI models; asking again takes a fifth or less of the allocations building does, a caller's write doesn't reach what is kept, and a model the catalog lists since is offered. Run on mote atc1457f2eeplus this commit and the next one (Goose's own options kept), together: - gofmt; go vet darwin, windows, linux: ok - TestClaudeViaMagpieKept and TestOwnOptionsKept alone 3/3 ok - go test ./internal/agent -timeout 45m: ok (267.7s) - real accounts, sandbox HOME, network blocked, 40 polls, both commits againstc1457f2ee: state and drift answers byte for byte the same; footprint peak 134 MB, RSS at end 177 MB - broken by hand (ownOptionsFrom builds each time): red, "took 211 allocations, building them 202" - ownOptionsFrom 21.2 -> 7.0 MB, gooseIn.func10 28.9 -> 16.0 MB; Picks 134 -> 118 MB with the commit before Not run: the GUI suite (no GUI file changed), Windows and Linux test runs. Picked ontoef63ef4a2(withef63ef4a2, Codex's subagent models kept, and gateway, redact and GUI commits; none in internal/agent); not run again there.
60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
package agent
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
)
|
|
|
|
// A provider's options an agent reaches on its own are kept while
|
|
// nothing changed: Goose's model field asked them each poll, for the
|
|
// picker and again for Drift, each provider's models made into options
|
|
// anew (20 MB of forty polls with real accounts). Each caller still has
|
|
// a list of its own, and a catalog read since is offered.
|
|
func TestOwnOptionsKept(t *testing.T) {
|
|
syncHome(t)
|
|
writeCatalog := func(extra string) {
|
|
var ms []string
|
|
for i := range 200 {
|
|
ms = append(ms, fmt.Sprintf(`"m%d": {"id":"m%d","name":"M%d"}`, i, i, i))
|
|
}
|
|
if extra != "" {
|
|
ms = append(ms, fmt.Sprintf(`"%s": {"id":"%s","name":"%s"}`, extra, extra, extra))
|
|
}
|
|
if err := os.WriteFile(catalog.CachePath(), []byte(`{"openai": {"name":"OpenAI","models": {`+strings.Join(ms, ",")+`}}}`), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
catalog.Reset()
|
|
}
|
|
writeCatalog("")
|
|
values := func() map[string]bool {
|
|
out := map[string]bool{}
|
|
for _, o := range ownOptions("", "", "openai") {
|
|
out[o.Value] = true
|
|
}
|
|
return out
|
|
}
|
|
if got := values(); !got["openai/m7"] || len(got) < 200 {
|
|
t.Fatalf("openai's models not offered: %d", len(got))
|
|
}
|
|
built := testing.AllocsPerRun(5, func() { ownProvider(nil, "openai") })
|
|
kept := testing.AllocsPerRun(20, func() { ownOptions("", "", "openai") })
|
|
if kept*5 > built {
|
|
t.Fatalf("a provider's options already built took %.0f allocations, building them %.0f", kept, built)
|
|
}
|
|
mine := ownOptions("", "", "openai")
|
|
for i := range mine {
|
|
mine[i].Value = "x"
|
|
}
|
|
if got := values(); !got["openai/m7"] {
|
|
t.Fatal("a caller's write reached the options kept")
|
|
}
|
|
writeCatalog("fresh")
|
|
if !values()["openai/fresh"] {
|
|
t.Fatal("a model the catalog lists since is not offered")
|
|
}
|
|
}
|