Files
magpie/internal/provider/plugin_usage_pool_host_test.go
T
yetone 016763f237 plugins: host.js passes a usage window's pool and family on, so Antigravity's card shows its pools (plugins#935)
mk311 (plugins#935): the Antigravity plugin's Usage card listed every
model's own window (13 rows, each Gemini one at 85.1%, Claude and
GPT-OSS at 100%), then a bare "7 days" and "5 hours" twice. The plugin
(0.1.0) already groups them as the built-in did: each model's window
carries its family and its pool ("Gemini", "Claude & GPT"), each pool's
own 5 hours and 7 days carry the pool. f92c0a2bd taught
plugin.UsageWindow and quotaOfPlugin to read the two fields, but
host.js's usageOf builds each window from a fixed list of fields and
left them out, so nothing reached Go: its test hands quotaOfPlugin a
plugin.Usage directly, past the host. Now host.js passes family and
pool on, and the card, menu bar rings, TUI page (PooledWindows), quota
alerts, caps and routing's pool holds treat the plugin's pools as the
built-in's. Only the antigravity plugin sends these fields (grep of the
plugins repo). The plugin docs (en, zh, ja, llms-full.txt) name them.

TestPluginAntigravityPoolsReachTheCard goes through the real plugin host
(bun, the fake plugin's FAKE_WINDOWS) with the windows the antigravity
plugin's own usage() returns for the reporter's literal figures (each
Gemini model 85.1% left resetting 20:31 +08, Claude and GPT-OSS 100%
resetting 11-11 00:24:47 +08, Gemini 7 days 91.8% left; the Claude & GPT
week isn't in the screenshots and is set to 100% left), kept in
testdata/antigravity-plugin-usage-935.json. The card's lines are then
Gemini · 7 days, Gemini · 5 hours, Claude & GPT · 7 days, Claude & GPT ·
5 hours.

A cap a user set on the plugin's bare "7 days" (two pools under one
name) is now keyed "Gemini · 7 days", as the built-in's was.

Run (mote refused SSH, kex reset; wsl-run in magpie-desktop at this
commit on 6886da1ca):
- gofmt -l: clean; go vet linux, windows, darwin: ok
- go test ./internal/provider, targeted -run with the new test: ok
- go test ./internal/plugin: ok (219s)
- site worker.test.mjs: 38 pass, 0 fail
- GUI quota-pools, quota-pool-model, quota-pool-order, window-cap-pool
  (chromium + webkit, every language): 52/52, also 52/52 at 9c39edb92
  and 4a9142ccd. A first run at 9c39edb92 had one red in window-cap-pool
  (chromium 420 de, each pool's caps); it passed 40/40 alone and on every
  rerun, filed as #5949.
- The antigravity plugin's own usage() (plugins repo, unchanged) run on
  the reporter's figures produced the testdata file.

Broken by hand: host.js with pool dropped: the new test is red with the
reporter's card (13 model rows, then "7 days", "5 hours" twice, no pool).

Not tried: a real Antigravity account through the plugin in the GUI;
macOS and Windows runs (mote down).
2026-11-10 20:32:38 +08:00

58 lines
2.1 KiB
Go

package provider
import (
"os"
"path/filepath"
"slices"
"testing"
)
// plugins#935 (mk311): the Antigravity plugin groups its models' windows
// into the pools they share ("Gemini", "Claude & GPT"), as the built-in
// did, but host.js passed neither a window's family nor its pool on (the
// Go side, quotaOfPlugin, already read them: TestPluginWindowsKeepPoolAndFamily
// hands it a plugin.Usage past the host), so the card showed every
// model's window and two "7 days" with no pool named. testdata/antigravity-plugin-usage-935.json is what the plugin
// (0.1.0) sends for the reporter's figures: each Gemini model 85.1% left
// resetting at 20:31 +08, Claude and GPT-OSS 100% resetting 11-11 00:24:47
// +08, and a 7 days at 91.8% left. Through the host, the card is each
// pool's 5 hours and 7 days in place of its models'.
func TestPluginAntigravityPoolsReachTheCard(t *testing.T) {
ws, err := os.ReadFile("testdata/antigravity-plugin-usage-935.json")
if err != nil {
t.Fatal(err)
}
windows := filepath.Join(t.TempDir(), "windows.json")
if err := os.WriteFile(windows, []byte(`{"a@fake": `+string(ws)+`}`), 0o600); err != nil {
t.Fatal(err)
}
q := fakePluginUsage(t, windows)["a@fake"]
if len(q.Windows) != 17 {
t.Fatalf("windows: %d, want 17: %+v", len(q.Windows), q.Windows)
}
for _, w := range q.Windows {
if w.Pool == "" {
t.Errorf("%q has no pool", w.Name)
}
if (w.Model != "") != (w.Family != "") {
t.Errorf("%q: model %q, family %q", w.Name, w.Model, w.Family)
}
}
var lines []string
for _, w := range PooledWindows(q.Windows) {
lines = append(lines, w.Name)
}
want := []string{"Gemini · 7 days", "Gemini · 5 hours", "Claude & GPT · 7 days", "Claude & GPT · 5 hours"}
if !slices.Equal(lines, want) {
t.Errorf("the card's lines: %q, want %q", lines, want)
}
// the Claude & GPT pool's windows hold its models, and only them
for _, w := range q.Windows {
if w.PoolWindow() && w.Pool == "Claude & GPT" {
if !w.CountsIn(q.Windows, "gpt-oss-120b-medium") || !w.CountsIn(q.Windows, "claude-opus-4-6-thinking") || w.CountsIn(q.Windows, "gemini-3.8-flash") {
t.Errorf("%s counts the wrong models", w.LineName())
}
}
}
}