Repository navigation
Description
Client or integration
Other
Area
Other
Summary
A test process that bun starts without loading bunfig.toml can write OAuth credentials into the developer's real ~/.opencodex/auth.json. Bun resolves bunfig.toml from the current working directory, so cd elsewhere && bun test <repo>/tests/x.test.ts loads no tests/preload.ts: HOME/OPENCODEX_HOME are not sandboxed and the real-home write guard stays disarmed. bunfig.toml documents this, and tests/ci-workflows/test-home-guard.test.ts enforces a pinned OPENCODEX_HOME only for the destructive rmSync(getConfigDir()) case. Non-destructive credential-store writes (saveCredential, upsertCredentialByIdentity, account-set mutations through src/oauth/store.ts) are not covered. A test that writes the store without pinning OPENCODEX_HOME silently adds accounts to the real auth store and can change the active account when run from another directory.
This happened during review of #7397. A scratch reproduction was run with the working directory outside the repository root. It called saveCredential("anthropic", …) without pinning OPENCODEX_HOME and added a fixture Anthropic account to the real auth store, which it made active. It was repaired by hand. The test was not repository-tracked, but nothing in the repository would have stopped a tracked test from doing the same.
Expected: when the process is a test run (bun test) and the sandbox preload was not loaded, credential-store writes should refuse to target the real home. One option is for src/oauth/store.ts, or the config-dir resolver, to fail closed under bun test unless OPENCODEX_HOME is set explicitly. The other is to extend test-home-guard.test.ts to require a pinned OPENCODEX_HOME in any test file that writes the OAuth store, not only in destructive ones.
Reproduction
- From a directory outside the repository (so
bunfig.tomlis not loaded), run a test file that callssaveCredential("anthropic", { access: "x", refresh: "y", expires: Date.now() + 3600000, email: "[email protected]" })without setting OPENCODEX_HOME. - Inspect
~/.opencodex/auth.json: the fixture account is present and active.
Version
dev at 1cf98c0 (2.90.0 development)
Operating system
macOS (any platform; cwd-dependent bunfig resolution is Bun behavior)
Provider and model
N/A (test infrastructure; affects any OAuth provider store)
Logs or error output
None. The write succeeds silently.
Screenshots and supporting files
No response
Redacted configuration
No response
Checks
- I searched existing issues and documentation.
- I removed secrets, tokens, account details, request credentials, and personal data.
Activity
github-actions commentedon Oct 19, 2026
Automated translation bookkeeping — detected language: English.
Ingwannu commentedon Oct 20, 2026
Checked against trusted dev
12025981e5a304cdb6b1b54f525ba8554f623977. The reported mechanism matches the current guard: OAuth persistence calls assertNotRealHomeUnderTest, but isTestHomeGuardArmed requires the preload-owned OCX_TEST_HOME_GUARD=1. The guard explicitly promises to stay inert in production, including NODE_ENV=test, so broad environment guessing would change that contract. Keep this open for a fail-closed harness/entrypoint design and an outside-cwd regression with a fake protected home, explicit credential-store mutation coverage, and a production-inertness negative. I will not reproduce against a real auth store. A static destructive-removal scan alone does not cover the reported non-destructive write path.test(guard): cover spawned-child inheritance and no production refusa…
fix(guard): normalise a stray OCX_TEST_HOME_GUARD so spawned helpers …
test(guard): assert Kimi and Nous writers still persist in production (…
fix(test): arm the real-home write guard when bun test skips the preload
test(guard): cover spawned-child inheritance and no production refusa…
fix(guard): normalise a stray OCX_TEST_HOME_GUARD so spawned helpers …
test(guard): assert Kimi and Nous writers still persist in production (…
fix(test): arm the real-home write guard when bun test skips the prel…