The same GLM Coding Plan team seat was added twice: as a key provider the
user had named, and as a ZCode plugin account. The Usage page kept only the
account's card, which read "31****36@qq.com" or just "ZCode", and whenever
either read failed ("BigModel API keys: not JSON") or a window had no reset
yet, the key's card came back beside it.
Seat (the flicker): the old check returned "different" on any error. It
now returns same, different or unknown (seatMatch). A match is remembered in
seats.json beside quotas.json; while the remembered account is signed in an
unknown check keeps the key card hidden, windows that disagree forget it,
and a signed-out account brings the key card back (seatCards, used by
quotas, Allotted and CachedCards). A failed read is "unknown", never "not
the same".
Names: providers.json gains accountNames (by the account in lower case,
like accountCaps), set by provider.SetAccountName. They are magpie's own
and never written into the vendor's or a plugin's sign-in. Built-in and
plugin accounts both take one; key providers are refused. Each card carries
Alias (the user's name, else the seat) and Seat (the key provider's name,
and the key's when it has several).
- GUI: the editor's account row shows the name with the address beside
it, or the address with "≡ <key plan>"; a click or Enter renames it in
place (posted once to provider/accountname; Escape leaves it, empty
clears it). The name stays selectable text: dragging across it renames
nothing.
The Usage page's cards and the tray panel name the account the same way.
Hide accounts hides the name too. Strings in zh, zh-TW, ja, de.
- The tray tooltip says "ZCode · <name>".
- CLI: `magpie accounts alias <agent> <email> [<name>|--clear]`.
`magpie accounts` and `magpie quota` show the name; quota also matches
on it.
- /v1/magpie/quotas carries alias and seat.
Run:
- account_seats_test TestSeatKeptThroughAFailedRead fails on the old code
("a failed read brought the key's card back") and passes now.
TestAccountNameOfAPluginAccount uses the fake plugin and checks that
plugin-auth.json and logins.json are byte-for-byte unchanged.
TestAccountsAlias checks that Codex's auth.json is unchanged.
TestTrayNamesTheAccountByItsAlias.
- account-alias.test.cjs: Chromium and WebKit; en, zh, zh-TW, ja, de;
900 and 360px; 20/20 pass. It covers no scroll on a click, keyboard,
selectable text, no select, no stripe, no sideways scroll and masking.
With the post-once guard removed it goes red. account-arrange (text
selection) passes in both engines.
- Sandbox HOME, built binary, vendors behind a dead proxy:
- `magpie accounts alias codex Me@Example.com 某某·GLM高级版`, then
`magpie accounts` and `magpie quota` showed the name.
- An unknown account was refused.
- `magpie web` on spare ports: POST /api/provider/accountname saved
"Team seat" (whitespace folded), and an unknown account got an error.
- Gateway /v1/magpie/quotas and /api/usage/quotas carried the alias.
- auth.json's sha was unchanged throughout.
- go test -tags nogui ./... (temp HOME, load ~200): all ok except
TestSetAnswersWhileDevinAndProvidersHang (15.5s under load), which
passes alone 3/3 at ~250ms.
- gofmt -l; GOOS=linux and GOOS=windows go vet on internal/provider,
internal/gui and the root package.
- The whole GUI suite in Chromium and WebKit, each failed file rerun
alone. These are red on the parent commit 472b36cec as well:
mobile-web (9), usage-heatmap (11), old-webkit (Safari 15 :has and
:focus-visible rules), usage-alert on WebKit (2), and routing-proxy,
which flakes 2 of 3 runs on the base. Every other file passes alone.
Not run: a real GLM key plus a real ZCode account. The seat match against
real BigModel/ZCode answers is covered only by the fake-upstream tests.
81 lines
3.9 KiB
Go
81 lines
3.9 KiB
Go
package provider
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// #1515 (aindijrncom): a GLM team seat added as a key (「某某·GLM高级版」)
|
|
// and signed in through ZCode is shown once, on ZCode's card. ZCode's read
|
|
// failing ("BigModel API keys: not JSON") says nothing about which seat it
|
|
// is, so the key's card stays off rather than coming back for a minute;
|
|
// only the account signed out, or windows that now disagree, bring it back.
|
|
func TestSeatKeptThroughAFailedRead(t *testing.T) {
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
reset := time.Date(2026, 10, 12, 3, 0, 0, 0, time.UTC)
|
|
five := 5 * time.Hour
|
|
plan := SubscriptionQuota{Provider: "zhipu-team", Name: "某某·GLM高级版", glmPlan: true, Plan: "Pro",
|
|
Windows: []QuotaWindow{{Name: "5 hours", Span: five, Used: 12, ResetsAt: &reset}}}
|
|
acct := SubscriptionQuota{Provider: "zcode-plugin", Name: "ZCode", User: "31****36@qq.com",
|
|
Windows: []QuotaWindow{{Name: "5 hours", Span: five, Used: 12, ResetsAt: &reset}}}
|
|
if got := notShown([]SubscriptionQuota{plan}, []SubscriptionQuota{acct}); len(got) != 0 {
|
|
t.Fatalf("one seat on two cards: %+v", got)
|
|
}
|
|
failed := SubscriptionQuota{Provider: "zcode-plugin", Name: "ZCode", User: "31****36@qq.com",
|
|
Error: "BigModel API keys: not JSON"}
|
|
if got := notShown([]SubscriptionQuota{plan}, []SubscriptionQuota{failed}); len(got) != 0 {
|
|
t.Fatalf("a failed read brought the key's card back: %+v", got)
|
|
}
|
|
// nor does a window with no reset yet (the plan's not used since)
|
|
fresh := plan
|
|
fresh.Windows = []QuotaWindow{{Name: "5 hours", Span: five}}
|
|
if got := notShown([]SubscriptionQuota{fresh}, []SubscriptionQuota{failed}); len(got) != 0 {
|
|
t.Fatalf("an unused window brought the key's card back: %+v", got)
|
|
}
|
|
// signed out of ZCode: the key's card is the seat's only one
|
|
if got := notShown([]SubscriptionQuota{plan}, nil); len(got) != 1 {
|
|
t.Fatalf("signed out, the key's card is gone: %+v", got)
|
|
}
|
|
// windows that disagree: another seat after all, and forgotten
|
|
other := reset.Add(time.Hour)
|
|
moved := SubscriptionQuota{Provider: "zcode-plugin", User: "31****36@qq.com",
|
|
Windows: []QuotaWindow{{Name: "5 hours", Span: five, ResetsAt: &other}}}
|
|
if got := notShown([]SubscriptionQuota{plan}, []SubscriptionQuota{moved}); len(got) != 1 {
|
|
t.Fatalf("another seat's card hid the key's: %+v", got)
|
|
}
|
|
if got := notShown([]SubscriptionQuota{plan}, []SubscriptionQuota{failed}); len(got) != 1 {
|
|
t.Fatalf("a seat told apart is still remembered: %+v", got)
|
|
}
|
|
}
|
|
|
|
// The account's card standing in for a key's is named for it (Seat), and
|
|
// by the user's own name for the account first (Alias); the cards handed
|
|
// in are a cache's and stay as they were.
|
|
func TestSeatNamesTheAccountsCard(t *testing.T) {
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
reset := time.Date(2026, 10, 12, 3, 0, 0, 0, time.UTC)
|
|
w := []QuotaWindow{{Name: "5 hours", Span: 5 * time.Hour, ResetsAt: &reset}}
|
|
plan := SubscriptionQuota{Provider: "zhipu-team", Name: "某某·GLM高级版", glmPlan: true, Windows: w}
|
|
subs := []SubscriptionQuota{{Provider: "zcode", Name: "ZCode", User: "a@qq.com", Windows: w}}
|
|
shown, named := seatCards([]SubscriptionQuota{plan}, subs)
|
|
if len(shown) != 0 || named[0].Seat != "某某·GLM高级版" || subs[0].Seat != "" {
|
|
t.Fatalf("shown %+v named %+v subs %+v", shown, named, subs)
|
|
}
|
|
if got := withAccountNames(named); got[0].Alias != "某某·GLM高级版" {
|
|
t.Fatalf("alias %q", got[0].Alias)
|
|
}
|
|
// a provider of several keys names the key too
|
|
plan.User = "张三"
|
|
if _, named := seatCards([]SubscriptionQuota{plan}, subs); named[0].Seat != "某某·GLM高级版 · 张三" {
|
|
t.Fatalf("seat %q", named[0].Seat)
|
|
}
|
|
// the remembered seat survives a restart (seats.json)
|
|
seatMemo.Lock()
|
|
seatMemo.m = nil
|
|
seatMemo.Unlock()
|
|
failed := []SubscriptionQuota{{Provider: "zcode", User: "A@qq.com", Error: "not JSON"}}
|
|
if shown, named := seatCards([]SubscriptionQuota{plan}, failed); len(shown) != 0 || named[0].Seat == "" {
|
|
t.Fatalf("after a restart: shown %+v named %+v", shown, named)
|
|
}
|
|
}
|