Files
magpie/internal/gui/fetched_count_test.go
T
yetone 06c3370b74 gui: Fetch models' "{p}: {n} models" counts the models the editor lists, not the vendor's ids (#2069)
liangxyz's Antigravity refetch said "Antigravity: 23 个模型" over 17 chips.
The toast counted the ids the vendor listed, while the editor shows a
model Antigravity lists once per thinking level (gemini-3.7-flash-high,
-low, -medium) as one model with those levels, as Cursor's and Devin's
lists are folded too. Two numbers for one list read as models gone.

The count is now the models the provider offers after the refetch
(Provider.Available, what the editor's chips are drawn from), the ids
only when it offers none.

TestFetchedCountIsTheEditorsModels saves an Antigravity list of six ids,
three models, and fails on the old count (6, want 3).

Run (macOS): the test red with fetchedCount returning the ids, green with
it; TestProviderTypedKey still counts a relay's two; go test -tags nogui
./internal/gui: one run of the whole package failed in a 208s run whose
output I didn't keep, while a fork was running other suites on this
machine; three runs after it passed, so its cause is not known. gofmt
clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows clean. No GUI
change (app.js shows r.count as before), so the GUI suite wasn't run. Not
tried against a real Antigravity account.
2026-10-14 13:31:10 +08:00

42 lines
1.5 KiB
Go

package gui
import (
"os"
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/provider"
)
// A refetch's "{p}: {n} models" counts the models the editor lists, not
// the vendor's ids: Antigravity's ids of one model at several levels are
// one chip, and the toast said 23 over 17 chips (#2069).
func TestFetchedCountIsTheEditorsModels(t *testing.T) {
t.Setenv("HOME", t.TempDir())
t.Setenv("USERPROFILE", os.Getenv("HOME"))
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
t.Setenv("XDG_CACHE_HOME", t.TempDir())
ids := []catalog.Model{
{ID: "gemini-3.7-flash-high", Name: "Gemini 3.7 Flash (High)"},
{ID: "gemini-3.7-flash-low", Name: "Gemini 3.7 Flash (Low)"},
{ID: "gemini-3.7-flash-medium", Name: "Gemini 3.7 Flash (Medium)"},
{ID: "gemini-3.1-pro-high", Name: "Gemini 3.1 Pro (High)"},
{ID: "gemini-3.1-pro-low", Name: "Gemini 3.1 Pro (Low)"},
{ID: "gpt-oss-120b-medium", Name: "GPT-OSS 120B (Medium)"},
}
if err := catalog.SaveLive("antigravity", "", ids); err != nil {
t.Fatal(err)
}
p := provider.Provider{ID: "antigravity"}
if n := len(p.Available()); n != 3 {
t.Fatalf("the editor lists %d models, want 3: %+v", n, p.Available())
}
if got := fetchedCount(p, len(ids)); got != 3 {
t.Fatalf("toast counts %d, want the editor's 3", got)
}
// a provider that offers nothing says the ids it was given
if got := fetchedCount(provider.Provider{ID: "nothing-here"}, 4); got != 4 {
t.Fatalf("empty provider: %d", got)
}
}