Repository navigation
fix(test): keep the suite from deleting the developer's Claude credentials via CLAUDE_CONFIG_DIR - #19889
fix(test): keep the suite from deleting the developer's Claude credentials via CLAUDE_CONFIG_DIR#19889starnetdev0 wants to merge 1 commit into
Conversation
A Claude Code session exports CLAUDE_CONFIG_DIR for its account, and Orca's claude-accounts code honours it. Run from such a session, the runtime-auth tests inherit the variable and - believing they use a temp dir - delete the real account's .credentials.json, rewrite it with test tokens and drop oauthAccount from .claude.json, logging out every session on that account. Their only visible trace was 76 "Unexpected Claude config dir" failures that looked like an environment quirk. A vitest setup file now deletes the variable before any test runs (tests that need it set it themselves), and the e2e launcher strips it with the other restricted home keys, next to CODEX_HOME. Checked on a decoy config dir: without the setup file the decoy's .credentials.json is deleted and 76 tests fail; with it the decoy is untouched and all 209 tests in src/main/claude-accounts pass. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L4p7iWdvZPkMh7TsuVkEi6
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe Vitest setup removes Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The change prevents tests from reaching a developer’s real Claude credentials while preserving explicit test isolation paths. The covered Vitest and Electron behaviors show no remaining merge-blocking risk. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This PR stops the test suite from writing through a host Claude Code session's CLAUDE_CONFIG_DIR by deleting the variable before any test module loads, and closes the same hole in the e2e Electron launcher. The fix is minimal, correctly scoped, and well justified.
- Vitest setup isolation — new
config/scripts/vitest-claude-env-isolation.tsdeletesprocess.env.CLAUDE_CONFIG_DIR, registered first insetupFilesso it runs before any test module resolves it. - Regression guard —
config/scripts/vitest-claude-env-isolation.test.tsfails if any test can observe the host variable. - E2E isolation —
CLAUDE_CONFIG_DIRjoinsRESTRICTED_ENV_KEYS, so the launcher strips it frominheritedEnvand rejects it inlaunchEnv/extraEnv, with unit coverage for both the inherited and passed-through cases.
I verified the mechanism end to end: ClaudeRuntimePathResolver.getRuntimePaths() reads process.env.CLAUDE_CONFIG_DIR instead of the mocked homedir(), so the runtime-auth-service-*.test.ts files (which mock homedir() to a temp dir) fall back to the temp fakeHomeDir/.claude once the variable is gone. Tests that genuinely need the variable set it themselves via explicit env fixtures, and the only config that runs these tests is the fixed one (the performance config inherits its setupFiles and scopes include elsewhere). No production code is touched.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
Thank you for the clear write-up of how CLAUDE_CONFIG_DIR could cause tests to wipe real Claude credentials. This is now covered by the write guard in #23979 (shipped in v1.4.219), which handles CLAUDE_CONFIG_DIR and fails any unit test that writes under a real agent home. Closing as superseded, and we appreciate the report. |

ELI5
Running Orca's tests from inside a Claude Code session can log you out of Claude Code. The session tells its child processes where your Claude account lives through
CLAUDE_CONFIG_DIR; the test runner inherits it, Orca's code honours it, and the claude-accounts tests — which believe they are working in a temporary folder — delete and rewrite your real credentials. This PR removes that variable from the test environment.What Changed
config/scripts/vitest-claude-env-isolation.ts(new, first insetupFiles): deletesCLAUDE_CONFIG_DIRbefore any test module loads. Tests that need the variable already set it themselves.tests/e2e/helpers/electron-home-isolation.ts: addsCLAUDE_CONFIG_DIRto the restricted keys, next toCODEX_HOME, so the e2e Electron app — and the agents it spawns — never inherit the host account either.CLAUDE_CONFIG_DIRboth inherited and passed throughlaunchEnv.Why
Claude Code sessions (and multi-account launchers) export
CLAUDE_CONFIG_DIR=<account dir>.vitestinherits the parent environment, andsrc/main/claude-accounts/runtime-auth-service-*.test.tsresolve the Claude config dir from it. Run that way, the tests:.credentials.jsonin the real account directory,oauthAccountfrom.claude.json,after which every Claude Code session on that account fails its next request with
Not logged in · Please run /login. The only trace in the test output is 76 failures readingUnexpected Claude config dir: <real path>, which looks like an environment quirk rather than data loss — which is how it went unnoticed while it logged a developer out about twenty times over two days.A setup file is the smallest change that protects every test at once, including ones added later; fixing individual tests would leave the next claude-accounts test exposed. The e2e launcher already strips
CODEX_HOMEfor the same reason.Linked Issue
No separate issue — the problem, reproduction and evidence are in this PR.
Visual Proof
N/A — test-environment change only; no UI or runtime behaviour changes.
Testing
Reproduction with a decoy config dir, so no real credentials are at risk:
main(f2d5711), before this change: the decoy's.credentials.jsonis deleted,.claude.jsonis rewritten withoutoauthAccount, and 76 tests fail in 7 files withUnexpected Claude config dir.src/main/claude-accounts, the new guard and the e2e isolation test pass.Platforms: tested on Linux. The change is platform-neutral — it deletes an environment variable, and Node's
process.envis case-insensitive on Windows, so it holds there too.AI Disclosure
Written with Claude Code (Claude Opus 5). The failure was found while investigating repeated Claude Code logouts on a developer's machine; the fix and the decoy verification above were run locally.
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Security: stops the test suite from destroying a developer's real credentials. Cross-platform: platform-neutral. SSH/remote, mobile, backwards compatibility and performance: unaffected — test environment only.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred) — ran the affected tests andoxlinton the changed files; CI will cover the rest.🤖 Generated with Claude Code
https://claude.ai/code/session_01L4p7iWdvZPkMh7TsuVkEi6