CrazyJal on X (tweet 2116833523604886006): Settings > Usage > Menu bar
windows, Cursor's pill had no choice for the Grok Bot window alone.
Why: the picker offered only the windows the menu bar shows unpicked
(trayWindows), which leaves out every window set aside. The Cursor
plugin reports Grok Bot aside (so it doesn't stop Cursor's models), so
it was never offered. And kinds were only a span ("7d"): Grok Bot and a
weekly plan's Weekly are both 7 days, as are Antigravity's two pools, so
two windows shared one kind, the GUI showed one of them, and picking it
picked both. The plugin reports the window fine; nothing changes there.
Fix (the class, every provider): trayChoices lists every window of a
card that the menu bar can say as a percent (trayCounted): the usual
ones first, then the rest (money aside, one model's window, Grok Bot),
marked TrayExtra and shown only when picked. Every choice has a kind of
its own: a usual window keeps its span's kind where it is the only one
of that span (so existing picks like claude:["5h"] keep working);
another of that span, and every extra, gets its model or name after it
("7d:grok bot", "7d:gemini · 7 days"). Unpicked, every card shows what
it showed before. The Settings pill offers the extras, and drops a pick
only when it is empty or exactly the usual windows.
Run (mote, at this tree, committed then as 0750aa783, on origin/main 15b035eef):
- go test -count=1 ./internal/gui ./internal/provider ./internal/settings:
provider ok, settings ok; gui red only on TestMainWindowCorners,
red the same on origin/main 15b035eef on mote (filed #3949).
- GOOS=windows go vet ./internal/gui ./internal/provider: ok. gofmt -l clean.
- win-run go test ./internal/gui -run 'TestTray|TestWithTrayKinds': ok.
- GUI (Chromium + WebKit, en/zh/zh-TW/ja/de, narrow): tray-windows 20/20;
with i18n-keys, old-webkit, tray-usages, tray-totals, tray-cost,
tray-logos, tray-inuse: every one ok but tray-windows' new subtest
before its names were read through t() (fixed, then 20/20).
- No size budget touched; traywindows.js is loaded only with the menu bar.
Broken by hand: trayChoices without the extras -> TestWithTrayKinds and
TestTrayWindowsPickAside red; the old save rule (v.length < ws.length)
-> tray-windows red in every language.
Not tried: a real Cursor account in the real menu bar (the fixture is the
plugin's own window shape, index.mjs botUsage: aside, 7 days); the Linux
gui package (wsl-run lacks webkitgtk-6.0 headers to build it). A user who
picked "7d" on a card with two 7-day usual windows (Antigravity's pools)
falls back to every window and picks again; that pick was ambiguous before.
Rebased on c0477aa72 (app.js, Providers reset rows; nothing in common)
and run again at the pushed head on mote: go test ./internal/gui -run
'Budget|Tray|Size' ok; tray-windows + i18n-keys (both engines, every
language) 24/24.
170 lines
7.0 KiB
Go
170 lines
7.0 KiB
Go
package gui
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// A subscription's card shows the windows Settings picked for it
|
|
// (settings.TrayWindows, StrikingRaw on X: Claude's 5 hours alone, not two
|
|
// small numbers squeezed together), named by how long they run, so a
|
|
// vendor's order doesn't matter; the tooltip still spells out every one,
|
|
// one picked that is gone shows every window rather than none, and a card
|
|
// of another provider is left as it was.
|
|
func TestTrayWindowsPicked(t *testing.T) {
|
|
now := time.Date(2026, 10, 30, 12, 0, 0, 0, time.UTC)
|
|
claude := provider.SubscriptionQuota{Provider: "claude", Name: "Claude", User: "a@b.c", Windows: []provider.QuotaWindow{
|
|
{Name: "7 days", Used: 70, Span: 7 * 24 * time.Hour}, // the vendor's order, longest first
|
|
{Name: "5 hours", Used: 42, Span: 5 * time.Hour},
|
|
{Name: "Opus", Used: 90, Span: 7 * 24 * time.Hour, Model: "opus"},
|
|
}}
|
|
codex := provider.SubscriptionQuota{Provider: "codex", Name: "Codex", User: "x@y.z", Windows: []provider.QuotaWindow{
|
|
{Name: "5 hours", Used: 10, Span: 5 * time.Hour},
|
|
{Name: "Weekly", Used: 20, Span: 7 * 24 * time.Hour},
|
|
}}
|
|
cards := []provider.SubscriptionQuota{claude, codex}
|
|
rows := func(pick map[string][]string) ([][]string, string) {
|
|
cells, _, tip := trayCardsView(cards, now, false, false, pick)
|
|
var out [][]string
|
|
for _, c := range cells {
|
|
out = append(out, c.Rows)
|
|
}
|
|
return out, tip
|
|
}
|
|
same := func(got, want [][]string) bool { return slices.EqualFunc(got, want, slices.Equal) }
|
|
|
|
all, allTip := rows(nil)
|
|
if !same(all, [][]string{{"42%", "70%"}, {"10%", "20%"}}) {
|
|
t.Fatalf("none picked: %q", all)
|
|
}
|
|
got, tip := rows(map[string][]string{"claude": {"5h"}})
|
|
if !same(got, [][]string{{"42%"}, {"10%", "20%"}}) {
|
|
t.Fatalf("5h alone: %q", got)
|
|
}
|
|
if tip != allTip {
|
|
t.Errorf("the tooltip lost a window:\n%s\nwant\n%s", tip, allTip)
|
|
}
|
|
if got, _ = rows(map[string][]string{"claude": {"7d"}, "codex": {"7d"}}); !same(got, [][]string{{"70%"}, {"20%"}}) {
|
|
t.Fatalf("7d alone: %q", got)
|
|
}
|
|
// a picked window gone (the vendor dropped it): every window, not an
|
|
// empty card
|
|
if got, _ = rows(map[string][]string{"claude": {"month"}}); !same(got, all) {
|
|
t.Fatalf("gone: %q", got)
|
|
}
|
|
// the Linux tray's text follows it too
|
|
if _, label, _ := trayCardsView(cards, now, true, false, map[string][]string{"claude": {"5h"}}); label != "58% | 90% · 80%" {
|
|
t.Fatalf("text: %q", label)
|
|
}
|
|
}
|
|
|
|
// Windows are named by how long they run; one whose span isn't known by
|
|
// the vendor's name for it.
|
|
func TestTrayWindowKind(t *testing.T) {
|
|
for _, c := range []struct {
|
|
w provider.QuotaWindow
|
|
want string
|
|
}{
|
|
{provider.QuotaWindow{Span: 5 * time.Hour}, "5h"},
|
|
{provider.QuotaWindow{Span: 5*time.Hour + 3*time.Second}, "5h"},
|
|
{provider.QuotaWindow{Span: 24 * time.Hour}, "1d"},
|
|
{provider.QuotaWindow{Span: 7 * 24 * time.Hour}, "7d"},
|
|
{provider.QuotaWindow{Span: 30 * 24 * time.Hour}, "month"},
|
|
{provider.QuotaWindow{Span: 31 * 24 * time.Hour}, "month"},
|
|
{provider.QuotaWindow{Span: 15 * time.Minute}, "15m"},
|
|
{provider.QuotaWindow{Name: " Credits "}, "name:credits"},
|
|
} {
|
|
if got := trayWindowKind(c.w); got != c.want {
|
|
t.Errorf("%+v: %q, want %q", c.w, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Settings is told every window the menu bar can say as a percent by a
|
|
// kind of its own: those it shows unpicked by their span, and one it shows
|
|
// only when picked (a single model's, money aside) by its model or name
|
|
// too, marked extra; a row of text gets none. The cards the cache keeps
|
|
// are left as they were.
|
|
func TestWithTrayKinds(t *testing.T) {
|
|
qs := []provider.SubscriptionQuota{{Provider: "claude", Windows: []provider.QuotaWindow{
|
|
{Name: "5 hours", Span: 5 * time.Hour},
|
|
{Name: "Opus", Span: 7 * 24 * time.Hour, Model: "opus"},
|
|
{Name: "Extra", Span: 30 * 24 * time.Hour, Aside: true, Used: 3},
|
|
{Name: "Note", Text: true, Aside: true},
|
|
}}, {Provider: "deepseek", Balance: "¥5"}}
|
|
out := withTrayKinds(qs)
|
|
ws := out[0].Windows
|
|
for i, want := range []struct {
|
|
kind string
|
|
extra bool
|
|
}{{"5h", false}, {"7d:opus", true}, {"month:extra", true}, {"", false}} {
|
|
if ws[i].TrayKind != want.kind || ws[i].TrayExtra != want.extra {
|
|
t.Fatalf("%s: %q extra %v, want %q %v", ws[i].Name, ws[i].TrayKind, ws[i].TrayExtra, want.kind, want.extra)
|
|
}
|
|
}
|
|
if qs[0].Windows[0].TrayKind != "" {
|
|
t.Fatal("the cache's window was written")
|
|
}
|
|
if out[1].Balance != "¥5" {
|
|
t.Fatalf("balance card: %+v", out[1])
|
|
}
|
|
}
|
|
|
|
// Every window a card reports can be picked alone (CrazyJal on X: Cursor's
|
|
// Grok Bot wasn't offered). Cursor's plugin reports Grok Bot aside, so it
|
|
// isn't stopping Cursor's models, with the same 7 days as a weekly plan's
|
|
// Included window: each gets a kind of its own, Grok Bot alone shows it
|
|
// alone, and unpicked the card is as it was, Grok Bot left out. Two
|
|
// windows shown unpicked with one span are told apart by name.
|
|
func TestTrayWindowsPickAside(t *testing.T) {
|
|
now := time.Date(2026, 10, 30, 12, 0, 0, 0, time.UTC)
|
|
week := 7 * 24 * time.Hour
|
|
cursor := provider.SubscriptionQuota{Provider: "cursor", Name: "Cursor", User: "a@b.c", Windows: []provider.QuotaWindow{
|
|
{Name: "Weekly", Used: 30, Span: week},
|
|
{Name: "Grok Bot", Used: 64, Span: week, Aside: true},
|
|
{Name: "Free usage", Display: "+$5 on us", Aside: true},
|
|
{Name: "Total", Used: 30, Aside: true},
|
|
}}
|
|
out := withTrayKinds([]provider.SubscriptionQuota{cursor})[0].Windows
|
|
if out[0].TrayKind != "7d" || out[1].TrayKind != "7d:grok bot" || !out[1].TrayExtra || out[2].TrayKind != "" || out[3].TrayKind != "name:total" {
|
|
t.Fatalf("kinds: %+v", out)
|
|
}
|
|
rows := func(pick []string) []string {
|
|
cells, _, _ := trayCardsView([]provider.SubscriptionQuota{cursor}, now, false, false, map[string][]string{"cursor": pick})
|
|
return cells[0].Rows
|
|
}
|
|
if got := rows(nil); !slices.Equal(got, []string{"30%"}) {
|
|
t.Fatalf("unpicked: %q", got)
|
|
}
|
|
if got := rows([]string{"7d:grok bot"}); !slices.Equal(got, []string{"64%"}) {
|
|
t.Fatalf("Grok Bot alone: %q", got)
|
|
}
|
|
if got := rows([]string{"7d"}); !slices.Equal(got, []string{"30%"}) {
|
|
t.Fatalf("Weekly alone: %q", got)
|
|
}
|
|
if got := rows([]string{"7d", "7d:grok bot"}); !slices.Equal(got, []string{"30%", "64%"}) {
|
|
t.Fatalf("both: %q", got)
|
|
}
|
|
_, _, tip := trayCardsView([]provider.SubscriptionQuota{cursor}, now, false, false, map[string][]string{"cursor": {"7d:grok bot"}})
|
|
if !strings.Contains(tip, "Grok Bot 64%") {
|
|
t.Fatalf("tooltip: %q", tip)
|
|
}
|
|
|
|
// two windows shown unpicked, one span: each picked alone
|
|
two := provider.SubscriptionQuota{Provider: "x", Name: "X", Windows: []provider.QuotaWindow{
|
|
{Name: "Requests", Used: 10, Span: week},
|
|
{Name: "Tokens", Used: 20, Span: week},
|
|
}}
|
|
if ws := withTrayKinds([]provider.SubscriptionQuota{two})[0].Windows; ws[0].TrayKind != "7d:requests" || ws[1].TrayKind != "7d:tokens" {
|
|
t.Fatalf("one span twice: %+v", ws)
|
|
}
|
|
cells, _, _ := trayCardsView([]provider.SubscriptionQuota{two}, now, false, false, map[string][]string{"x": {"7d:tokens"}})
|
|
if !slices.Equal(cells[0].Rows, []string{"20%"}) {
|
|
t.Fatalf("Tokens alone: %q", cells[0].Rows)
|
|
}
|
|
}
|