Skip to content

test: run unit tests against a throwaway home - #129

Open
behruznassre wants to merge 1 commit into
sendbird:mainfrom
behruznassre:fix/tests-isolate-codex-home
Open

behruznassre wants to merge 1 commit into
sendbird:mainfrom
behruznassre:fix/tests-isolate-codex-home

Conversation

@behruznassre

Copy link
Copy Markdown
Contributor

Summary

  • new tests/support/isolated-codex-home.mjs, preloaded with node --import by the test and test:cross-platform scripts
  • node --test applies the preload to every test file's process; each one gets its own temporary HOME/USERPROFILE with CODEX_HOME cleared, removed on exit
  • no test files change; integration and e2e already set CODEX_HOME and are untouched

Why HOME rather than CODEX_HOME

My first version set CODEX_HOME to a temporary directory. That broke 30 tests in hooks, install-hooks, installer-cli and unread-result-hook. Those tests already isolate themselves by spawning hooks with a fake HOME, and an inherited CODEX_HOME overrode it. Isolating at the HOME level matches what those tests do and needs no changes to them.

Validation

  • the issue's reproduction on main (19e5651) lists fixtures under ~/.codex/plugins/data/cc/state/… (test-status-*, tracked-race-job.json, j1.log, stop-review-history.jsonl)
  • with the fix, npm run check and npm run test:cross-platform run with the real HOME, and a before/after listing of ~/.codex/plugins/data is identical; on main the same run created seven fixture files
  • no cc-plugin-codex-test-home-* directories remain after the run
  • npm run check: unit 514 passed, integration 45 passed, Codex E2E 23 passed; test:cross-platform 261 passed; lint, typecheck, version-sync and changelog OK

Not verified: the Windows CI job. USERPROFILE is set for os.homedir() there, but I ran it only on macOS.

Fixes #127

🤖 Generated with Claude Code

Plugin state defaults to ~/.codex, and several unit tests create jobs
and stop-review history without overriding HOME or CODEX_HOME, so every
local `npm test` left fixtures in the developer's real plugin data. Some
stay in running or cancelling state, and data written to the legacy
`cc` namespace is merged into the installed plugin's namespace on its
next run.

Preload a small module with `node --import` in the unit test scripts.
node --test applies it to each test file's process, which gets its own
temporary HOME/USERPROFILE with CODEX_HOME cleared, removed on exit.
Tests that spawn hooks with their own HOME keep working unchanged. The
integration and e2e suites already set CODEX_HOME themselves.

Fixes sendbird#127

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: npm test writes job fixtures into the developer's real ~/.codex plugin state

1 participant