Commit Graph
9 Commits
Author SHA1 Message Date
yetone 58b6ad2e80 claude: with CLAUDE_CONFIG_DIR set, the keychain item read and written is the one Claude Code keeps there (#1842)
What changed: magpie read and wrote Claude Code's own sign-in under the
service "Claude Code-credentials" whatever CLAUDE_CONFIG_DIR said. Claude
Code 2.1.296 names its item "Claude Code-credentials-<sha256(dir)[:8]>"
when CLAUDE_CONFIG_DIR is set (j$ in its secure storage: the suffix is
dropped only when CLAUDE_CONFIG_DIR is unset), which is what
claudeDirService already computes for saved accounts' directories. Now
claudeHomeService gives that name for the read (both the account's item
and by service alone) and for saveClaudeCredential.

Why now: the previous commit asks the account's item before the file, so
with CLAUDE_CONFIG_DIR set the plain "Claude Code-credentials" item — the
default directory's sign-in, maybe another account — would have beaten the
.credentials.json in CLAUDE_CONFIG_DIR. It was already wrong before that
commit (a sign-in was written to an item Claude Code under that directory
never reads), only less visible.

Run (tip of both commits, sandbox HOME, fake `security` on PATH, private
GOCACHE): TestClaudeConfigDirKeychainItem fails with claudeHomeService
ignoring CLAUDE_CONFIG_DIR (it read "home-item") and passes with it.
gofmt -l clean; go vet ./... on darwin, GOOS=linux -tags nogui and
GOOS=windows pass; go test -count=1 ./internal/provider ok (116s);
go test -race -count=5 on the keychain tests ok.
Not run: no real Keychain, no real Claude Code run under CLAUDE_CONFIG_DIR
(the name rule is read from the 2.1.296 binary), no other package's tests
(only internal/provider changed).
2026-10-13 00:43:08 +08:00
ggbdpqandyetone 31956b92f0 claude: a fresh sign-in goes into the keychain item Claude Code reads, not beside it (#1742, #1842, iefnaf)
What changed: readClaudeCredential asked the Keychain only when the
credentials file held no sign-in. On a Mac whose "Claude Code-credentials"
item is there but emptied (what Claude Code leaves of a sign-in Anthropic
refused to refresh), an older, parseable ~/.claude/.credentials.json was
taken for the sign-in: a sign-in made in magpie was written into that file,
the dead item stayed, Claude Code stayed signed out, and a minute later
claudeIdentity's loggedIn: false lapsed the account and took the provider
out. Now the item under the account ($USER) is read first, emptied or not,
as Claude Code reads it: its own storage asks the Keychain first and reads
the file only when the item is absent, empty or no JSON — the rule
readClaudeDir already applies, with its own test, to the item in a saved
account's config directory. putClaudeLogin, reusing what was found, puts a
fresh sign-in into the item. The item is asked by service alone only after
the file has no sign-in, as before (an earlier sign-in's leftover,
58b67666).

Amended in review (yetone): the patch as sent took an item magpie wrote
over lines, which `security -w` prints as hex (#70), for the sign-in ahead
of the file and rewrote it on one line. Claude Code 2.1.296's keychain leg
JSON-parses what `security` prints, so hex reads as no item and it goes by
the file: the account's hex item now comes after the file, and is only
rewritten when the file has no sign-in either, as before. The two reads are
one claudeKeychainItem value instead of a four-result helper.
TestClaudeHexKeychainItemIsNoneBesideAFile covers it.

Checked against Claude Code 2.1.296's binary: its secure storage is
M(keychain, plaintext); the fallback leg's read returns the keychain's
result whenever it is not null, and the keychain leg returns
JSON.parse(`security find-generic-password -a $USER -w -s
"Claude Code-credentials"`) when that prints anything, else null (a parse
error is caught as null). Every HOME reader in magpie (liveLogin,
claudeAccount, Usage, claude_auth, putClaudeLogin) goes through
readClaudeCredential via claudeCredential, so they all follow the one order.

Run: TestClaudeEmptiedKeychainItemIsTheSignInBesideAFile fails with main's
order (the account's item not asked first) and passes with the change;
TestClaudeHexKeychainItemIsNoneBesideAFile fails with the patch as sent
(hex item taken over the file) and passes with the amendment;
TestClaudeFileSignInWhenNoKeychainItem guards the file fallback. All with a
sandbox HOME and a fake `security` on PATH. Full checks are in the next
commit's body. Not run: no real Keychain, no real emptied item, no real
sign-in from the GUI.

Co-authored-by: yetone <yetoneful@gmail.com>
2026-10-13 00:38:09 +08:00
yetone 06420a7121 tests: a fake program is a file macOS has already let run (testenv.Program), so a fake's first start no longer eats a test's wait under load
macOS checks a newly written executable before its first exec: 0.27s
alone, 2-5s while other new programs start (a go test ./... starting its
test binaries). The same file again takes 0.009s, and the pass is kept
across a rename and an in-place rewrite. 108852b4 worked round this for one
test with /bin/sh -c; the class was every test that writes a `#!/bin/sh`
fake and times its answer.

testenv.Program(t, path, script) replaces os.WriteFile(path, script, 0o755)
for fakes. On macOS it renames a file that has run once from a pool to path
and writes the script into it in place; at the test's cleanup the file goes
back to the pool (only a path the test created; a stand-in it wrote over
stays). Fakes still end with their tests: nothing about how they are
started or waited on changed. Run (and gateway's TestMain) remove the pool
at the end. TestMain's PATH stand-ins are run once in the background
(testenv.StandIns). Other systems write the file as before.

Converted every `#!/bin/sh` fake written by tests under internal/ (agent,
gateway, gui, library, plugin, proc, provider, update). Windows, binary
and node/bun fakes are unchanged.

Under the same load (3 loops each starting 8 freshly written scripts at a
time), 4 rounds each, before (108852b4 / origin/main) vs after:
- provider TestSavedButSignedOutClaudeServed: 4/4 fail (8.01s) -> 4/4 pass
- provider TestClaudeSignInOverStaleCredentials: 4/4 fail (5.00s) -> 4/4 pass
- provider TestDevinSignedInOnlyInMagpie: 3/4 fail ("CLI's own []") -> 4/4 pass
- gateway TestClaudeRunEndsWhenTheClientLeaves: 4/4 fail -> 4/4 pass
  (and 3/3 fail -> 3/3 pass at a third of that load)
- gateway TestClientGoneRecordedAsCanceled: 4/4 fail -> 4/4 pass
- gui TestProvidersAnswerWhileListsComeIn ("cursor found false" at 3.03s):
  4/4 fail -> 4/4 pass. The same class, not bfe8bcaf's test order.
- proc TestUserPath (login shell's PATH never came, 7.01s): 4/4 fail ->
  4/4 pass
Unloaded, every touched package passes; no pool directory or process is
left after a run.
2026-10-07 03:00:47 +08:00
yetone 41d50e15c8 claude: the Claude accounts saved in magpie are served while Claude Code is logged out, and none is dropped (StringKe on Discord: CC(API) -> Magpie -> CC Subscription, and as soon as I /logout in Claude Code all six accounts I manage in magpie disappear) — magpie served its saved Claude accounts only beside the one Claude Code was signed in to: claudeAccount gave no provider without Claude Code's own credentials (or with claude auth status saying no one is signed in), so the gateway had no Claude account at all and the page said the saved ones "are only offered beside the account it is signed in to". Claude Code itself tells the user to log out: with magpie's ANTHROPIC_AUTH_TOKEN beside a claude.ai sign-in it warns "ANTHROPIC_AUTH_TOKEN overriding Claude subscription login · unset it or /logout to sign it out". magpie keeps every account's sign-in in logins.json, so a logout now signs none of them out of magpie: the account seen last (the one Claude Code was signed in to until then, which magpie saw every 30s) stands in its place, run in a config directory of its own as the others on are, listed on, and it can be paused behind another as Claude Code's own could; the others on are served behind it, the Usage page reads it as a saved account, and the saved-but-signed-out notice is no longer given for Claude. An account whose saved sign-in is unreadable is listed as signed out ("its sign-in is gone; sign in again"), never dropped, and isn't picked to stand in while another has one. An account signed in in magpie while Claude Code is logged out and magpie has Claude accounts no longer signs Claude Code back in (which only brought back its warning); it is magpie's alone, on, and the one served first till then stays on behind it. Prompts, identity lines and headers are unchanged; magpie still never refreshes a Claude sign-in nor asks Anthropic anything itself. TestClaudeAccountsOutliveLogout, TestClaudeSignInWhileLoggedOut and TestSavedButSignedOutClaudeServed fail without the change; TestSavedButSignedOutCanBeRemoved now removes the account from the list. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass (TestFetchNewLeavesListedPlugins, a bun plugin test, failed once under load and passes alone and in a rerun of the package). 2026-10-01 20:13:58 +08:00
yetone a2714f7506 claude: a Claude account's usage resets are read in the zone /usage names on Windows too, and the provider tests pass whole on Windows (goal: 插件订阅 provider 跟内置的所有逻辑都要一模一样, run on Windows and Linux) — Windows has no time zone database, so "resets Oct 1 at 3:30pm (Asia/Shanghai)" was read in the machine's own zone, hours off for anyone not in that zone; magpie now carries the database (time/tzdata). The provider tests set HOME but not USERPROFILE, which Windows takes the home from, so on Windows they read the test box's own agent sign-ins (Gemini models in a list, an extra provider, a Cursor version); every test home sets both now. Tests whose fake CLI is a shell script (Claude Code's auth status, codex --version, macOS's security) skip on Windows, as the fake devin did, and file mode bits go unchecked there. TestParseClaudeUsage fails on Windows without the change. On Windows and on Linux (WSL) the provider package passes whole, three times on Windows (15 failed before), the plugin package and the move/plugin/Grok/Devin/usage tests five times over on Linux. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass. 2026-10-01 13:51:24 +08:00
yetone 782380a7f5 gui: a Claude account saved in magpie can be removed while Claude Code is signed out (𝕏 user on Discord: a banned account logged out, and its line in Providers had nothing to remove it with) — saved accounts are listed only beside the one the agent is signed in to, so with none signed in the line saying they are saved was all there was. It now names them and has Remove, which asks first and forgets magpie's own copies only (login/forget, one each): the agent's files, keychain and the account itself are left as they are. TestSavedButSignedOutCanBeRemoved and saved-signedout-remove.test.cjs (Chromium, WebKit, en/zh) fail without the change. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass (TestClaudeSignedOut, a load flake, passes alone); old-webkit, own-signin-remove pass. 2026-09-30 17:29:54 +08:00
yetone 58b676663b claude: its sign-in is read from the keychain under its account, as Claude Code reads it (@taresky: claude auth status loggedIn, the keychain item there, magpie still said not signed in) — magpie asked for "Claude Code-credentials" by service alone, and with more than one item for it (one an earlier sign-in left, say) the keychain may hand back one that isn't the sign-in in use; now it asks under $USER first, as Claude Code does, and by service alone only when that finds none that reads 2026-09-29 13:08:36 +08:00
yetone 1d6b415a68 providers: a saved Claude account left out says which check found no sign-in (@taresky: Claude 账号不显示, cc cli works) — on a Mac the note named only ~/.claude/.credentials.json, where Claude Code never keeps its sign-in there, so every cause read the same. Now it says whether no "Claude Code-credentials" could be read from the keychain (and nothing at that file), the credentials are there but claude auth status says no one is signed in, or neither ~/.claude.json nor the CLI names the account 2026-09-29 12:56:58 +08:00
yetone 5f839eae99 provider: saved Claude or Codex accounts that are not offered say why — under a HOME where the agent is not signed in (a magpie serve with its own HOME, no ~/.codex/auth.json or ~/.claude/.credentials.json there) they went missing without a word; magpie serve, magpie providers and the Providers view now tell 2026-09-26 14:32:48 +08:00