Each /api/providers poll asked gateway.Drawers for each provider's image
models, and Drawers read the provider's model list again (p.Available)
though providerInfoWith already had it in the kept Listing. In a
real-account heap profile (20 warm rounds of drift, state and providers)
Drawers was 14.4 MB of what was allocated.
DrawersOf takes the list as a func, called only on the paths that read
it (a Google sign-in's, a plugin's), and the Providers page passes its
Listing's Available, which is p.Available() kept (Provider.Listing).
Drawers itself is DrawersOf(p, p.Available) for every other caller.
Real use: the owner's real-account sandbox, offline (proxy to :9), 20
warm rounds of /api/drift, /api/state and /api/providers, at this head:
- Drawers 14.4 MB -> DrawersOf 3.1 MB.
- /api/state and /api/drift bytes identical to 6712e367e's (cmp);
/api/providers differs only in each provider's "fetched" time.
Run on mote (mote-run, Go 1.26.8):
- gofmt clean; go vet ok, also GOOS=windows and GOOS=linux.
- TestDrawersOfTheCallersList alone, 3 times: ok.
- Broken by hand (DrawersOf reading p.Available()): red, "drawers [],
want gemini-3.1-flash-image alone".
- go test -timeout 45m ./internal/gateway: ok (669s). ./internal/gui:
FAIL on TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
TestMainWindowCorners (#3949), both red on main and filed. That run
was at dd7442f28; this head is it rebased on 6712e367e (the stash and a
Claude account-switch change, neither in gateway's draw path), built
and run for the numbers above.
27 lines
788 B
Go
27 lines
788 B
Go
package gateway
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// The image models a Google sign-in can draw with come from the model list
|
|
// the caller has (the Providers page's), read once, not from a list read
|
|
// again for them.
|
|
func TestDrawersOfTheCallersList(t *testing.T) {
|
|
p := provider.Provider{ID: "antigravity", Account: &provider.Account{Agent: "antigravity"}}
|
|
calls := 0
|
|
got := DrawersOf(p, func() []catalog.Model {
|
|
calls++
|
|
return []catalog.Model{{ID: "gemini-3-pro"}, {ID: agDrawer}}
|
|
})
|
|
if len(got) != 1 || got[0].ID != agDrawer || got[0].Provider != "antigravity" {
|
|
t.Fatalf("drawers %+v, want %s alone", got, agDrawer)
|
|
}
|
|
if calls != 1 {
|
|
t.Fatalf("the list was read %d times", calls)
|
|
}
|
|
}
|