Commit Graph
2 Commits
Author SHA1 Message Date
yetone ce8b67de37 gui tests: a page's first load gets a minute, not a click's 5s (#4470)
claude-switch-only set page.setDefaultTimeout(5000) and then called
page.goto with no timeout of its own, so Playwright held the first load
of app.js, i18n.js and the plugins to the 5s bar meant for clicks. On a
busy box (a whole-suite run at load 130-160) that load took longer and
goto timed out. The same pattern is in 988 GUI test files (1174 pages):
every one of them now also sets setDefaultNavigationTimeout(60000) on
the same page, right after its default, so goto, reload and waitForURL
wait on the load itself with room, while clicks and waits keep their
short bar. group-from-model-add's own 20s navigation bar is raised to the
same minute. claude-switch-only also gives its first provider row (drawn
from the page's first reads) a minute before clicking it.

nav-timeout.test.cjs (no browser) reads every GUI test file and names
each page given a default under a minute without a navigation timeout of
at least a minute, so a new file can't bring the pattern back.

What was run (WSL magpie-desktop, Playwright 1.62.0, load 70-260 from
other sessions):
- node --check on every file in internal/gui/tests: all parse.
- nav-timeout.test.cjs against origin/main's test files: red (names the
  1174 pages); against this tree: its only reds were my own probe copies
  of the old files, since removed.
- By hand: claude-switch-only with app.js served 7s late (a busy box's
  first load), --test-name-pattern "1100 en": origin/main's file 4 of 4
  red with "page.goto: Timeout 5000ms exceeded"; this file 4 of 4 green.
- claude-switch-only.test.cjs, both engines, en/zh/ja/de, 1100 and 420:
  32 of 32. group-from-model-add, usage-access-key-card and i18n-keys:
  green. agent-plugin-agents: Chromium green; WebKit's de 420 subtest red
  on a 5s waitForFunction at line 115 (a wait after load, not the
  navigation), at load ~230.

Not tried: the whole GUI suite (about 1000 files; the change is one
mechanical line per page), Windows or mote (mote's browsers, #4125).
2026-10-31 02:09:18 +08:00
yetone 8ebf9cbea9 claude: add an account from a setup-token (CLAUDE_CODE_OAUTH_TOKEN)
sfss5362 on X asked "支持 CLAUDE_CODE_OAUTH_TOKEN 吗". It didn't work
before: cleanClaudeEnv strips the variable everywhere, and the import
flow needs a refresh token and an email.

A Claude account can now be added from the token `claude setup-token`
prints. In the window: the sign-in's "Use a setup-token instead…" and
the accounts list's "Add an account by setup-token…", which post to
POST /api/signin/claude-token.

The token is kept in logins.json as {"setupToken":…}. The real Claude
Code gets it in CLAUDE_CODE_OAUTH_TOKEN, and only for runs in that
account's own config directory (inClaudeDir via
provider.ClaudeDirToken). It never goes on the command line or into a
log. magpie never asks Anthropic anything with it. The bridge, the
sdk-cli entrypoint and the weighting are unchanged.

What such a token can't do: it has the inference scope only.
- Claude Code's `auth status` gives no email or plan. The account is
  named "Claude setup-token <6 hex of its hash>".
- Its /usage prints the API cost view. /usage is never run for it, so
  its allowance is unknown (errClaudeSetupToken, which `passing` keeps
  as saying nothing about the account), not zero. Windows heard on
  real replies still fill it in.
- Its config directory holds no .credentials.json, so Claude Code has
  no sign-in to fall back to if the token is refused.
- Claude Code itself is never signed in to it. addLogin, switchLogin,
  putClaudeLogin, SetKeepLoginAs, NextLogin and signInToFirst all pass
  it over. Its row shows Remove and "magpie only", and the switch menu
  leaves it out.
New strings are in zh, zh-TW, ja and de. Docs: providers-accounts.md
and claude-subscription-bridge.md.

Run:
- mote: gofmt -l (clean); go vet ./internal/...; GOOS=linux go vet
  -tags nogui and GOOS=windows go vet of provider, gateway and gui; go
  build ./...
- mote: go test of provider and gateway, -run on SetupToken, Claude
  usage, warm-up, saved, account, logins, switch and keep-login: ok.
- New tests, with a fake claude binary in a sandbox HOME:
  - TestClaudeSetupTokenAccount, TestClaudeSetupTokenSignsClaudeCodeInToNothing,
    TestClaudeSetupTokenAllowanceUnknown and TestCheckClaudeSetupToken
    in provider;
  - TestClaudeSetupTokenReachesItsOwnRunsOnly in gateway: the token
    reaches only its account's run, not "" or another dir, even with
    the shell's CLAUDE_CODE_OAUTH_TOKEN=leaked, and never in args;
  - claude-setup-token.test.cjs: Chromium on mote and WebKit on
    xiaomi-gpu, each in en, zh, zh-TW, ja and de.
- GUI files the change reaches (signin-link, signin-web-blocked,
  signin-closes-sheet, revoked-signin-account, account-eye,
  account-row-line, i18n-keys and the new one): 73/73 on xiaomi-gpu
  Chromium.
- On mote, 33 account, sign-in and i18n files had 96 reds. mote was
  overloaded by another session's full GUI suite. Six of those files
  fail 58 of 64 the same way at origin/main dafe4af82 there, and pass
  on xiaomi-gpu. WebKit on mote timed out on the untouched
  copilot-ghe.test.cjs too.

Size: app.js was 2,885 bytes over its budget after the rebase. The
new comments were cut, and the budgets were raised to the measured sizes
(app.js 1,317,705, core 1,539,423) with no room added, as
core_budget_test.go says. After the rebase onto origin/main 969868ccd,
these were run on mote at this head: TestCoreScriptBudget and the
SetupToken tests ok, and claude-setup-token plus i18n-keys in Chromium
9/9.

Broken by hand (each went red):
- without the token line in inClaudeDir, the gateway test;
- with addLogin allowed to sign Claude Code in, two provider tests;
- with /usage run for a token account, AllowanceUnknown ("told no
  allowance").
- With switchLogin's guard removed, the tests stay green, because
  putClaudeLogin still refuses.

Not tried: a real setup-token against Anthropic. The full Go and GUI
suites will be run after the push.
2026-10-30 14:50:44 +08:00