Files
magpie/internal/provider/first_off_test.go
T
yetone 219b60f494 accounts: the first account of a gateway-served subscription ticks off (Rime_Nan on X)
Rime_Nan on X: in WorkBuddy's account list the first account (First) couldn't be ticked off; it took dragging another account above it first. For a subscription the gateway serves itself (plugins, Copilot, ChatGPT API, Gemini, Antigravity), First is only the order the gateway tries accounts in; no agent is signed in to it. setSideLoginOn still refused it ("put another account first"), and the GUI drew its tick fixed.

Now, unticking the first account hands First to the next ticked account that hasn't lapsed and turns this one off. If no other account is ticked, it is still refused, with "tick another to stop using it", and the GUI's fixed tick says the same. An account the user left off is never ticked on. Claude and Codex (pausable) are unchanged.

To keep the core scripts in their budget without raising it, the bytes were paid for by cutting renderAccounts' comment to one line: app.js is +20 bytes, under 1,533,802.

TestCopilotAccounts asserted the old refusal; it now checks the handover and that the only account in use still can't be ticked off.

Run (mote, macOS 27, at f9dda0d3e on origin/main f0e0385a0):
- go test ./internal/provider: ok.
- internal/gui: TestCoreScriptBudget and TestI18n ok.
- gofmt clean; GOOS=windows go vet ./internal/provider ok; at the earlier base, GOOS=linux go vet ./internal/provider and GOOS=windows go vet ./internal/gui ok.
- GUI first-untick.test.cjs (both engines, en/zh/zh-TW/ja/de) and i18n-keys: 24/24.
- Earlier base 694f4a6d6: the whole internal/gui package on mote, red only in TestMainWindowCorners (#3949, macOS 27) and the budget, since fixed. internal/provider passed on Linux (WSL); internal/gui doesn't build there (no gtk4/webkitgtk-6.0 dev packages).
- GUI keep-login, settings-tabs-stick, view-no-sideways, *account*, *plugin*, *copilot* at the earlier base: 1773/1783. The reds, run alone, are red on origin/main 694f4a6d6 as well: plugin-move-unserved's Try again (#4410) and account-eye's Usage card subtest (filed #5052).

Broken by hand: with the old setSideLoginOn, TestFirstTickedOffHandsFirstOn and TestOwnFirstCopilotTickedOff fail ("magpie uses a@x.com first; put another account first"). With the old app.js, first-untick.test.cjs fails 10/10 in Chromium.

Not tried: unticking with a real WorkBuddy plugin account in the app; the tests use Antigravity and Copilot saved logins, and the GUI test uses a stubbed Copilot provider.
2026-11-03 16:43:12 +08:00

77 lines
2.8 KiB
Go

package provider
import (
"encoding/json"
"path/filepath"
"testing"
)
// Rime_Nan on X: the first account of a subscription magpie's gateway
// serves could be ticked off only after dragging it down the list ("put
// another account first"). First is only the gateway's order there, so
// ticked off it hands first to the next ticked account; with no other
// ticked, it stays, as one account is always used.
func TestFirstTickedOffHandsFirstOn(t *testing.T) {
claudeHome(t)
auth := func(r string) json.RawMessage {
b, _ := json.Marshal(googleAuth{RefreshToken: r})
return b
}
saveLogins(t,
savedLogin{Agent: "antigravity", User: "a@x.com", Auth: auth("ra"), On: true, First: true},
savedLogin{Agent: "antigravity", User: "b@x.com", Auth: auth("rb")},
savedLogin{Agent: "antigravity", User: "c@x.com", Auth: auth("rc"), On: true})
ForgetAccounts()
// b is off: the next ticked one, c, takes first, and b stays off
if err := SetLoginOn("antigravity", "a@x.com", false); err != nil {
t.Fatalf("ticking the first off with another ticked: %v", err)
}
ForgetAccounts()
ls := Logins("antigravity")
if len(ls) != 3 || ls[0].User != "c@x.com" || !ls[0].Active || !ls[0].On {
t.Fatalf("c is not first: %+v", ls)
}
for _, l := range ls[1:] {
if l.On || l.Active {
t.Fatalf("%s is still in use: %+v", l.User, ls)
}
}
// c is the only one ticked now: it stays, said why
if err := SetLoginOn("antigravity", "c@x.com", false); err == nil {
t.Fatalf("the only account in use was ticked off: %+v", Logins("antigravity"))
}
ForgetAccounts()
if ls := Logins("antigravity"); ls[0].User != "c@x.com" || !ls[0].Active || !ls[0].On {
t.Fatalf("after a refused tick off: %+v", ls)
}
}
// The editors' own Copilot account is first with no account marked so;
// ticked off, the next ticked one of magpie's is first, and the own one
// is listed off, not first again.
func TestOwnFirstCopilotTickedOff(t *testing.T) {
signIn(t)
writeFile(t, filepath.Join(copilotConfigDir(), "github-copilot", "apps.json"), map[string]any{"github.com": map[string]any{"user": "octo", "oauth_token": "gho_own"}})
tok := func(s string) json.RawMessage { return json.RawMessage(`{"oauth_token":"` + s + `"}`) }
saveLogins(t,
savedLogin{Agent: "copilot", User: "octo", On: true},
savedLogin{Agent: "copilot", User: "other", Auth: tok("gho_o"), On: true})
ForgetAccounts()
if ls := Logins("copilot"); len(ls) != 2 || ls[0].User != "octo" || !ls[0].Active {
t.Fatalf("logins before: %+v", ls)
}
if err := SetLoginOn("copilot", "octo", false); err != nil {
t.Fatalf("ticking the own first account off: %v", err)
}
ForgetAccounts()
ls := Logins("copilot")
if len(ls) != 2 || ls[0].User != "other" || !ls[0].Active {
t.Fatalf("other is not first: %+v", ls)
}
if ls[1].User != "octo" || ls[1].On || ls[1].Active {
t.Fatalf("octo is still in use: %+v", ls)
}
}