Repository navigation
test: run unit tests against a throwaway home - #129
Open
behruznassre wants to merge 1 commit into
Open
behruznassre wants to merge 1 commit into
behruznassre wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tests/support/isolated-codex-home.mjs, preloaded withnode --importby thetestandtest:cross-platformscriptsnode --testapplies the preload to every test file's process; each one gets its own temporaryHOME/USERPROFILEwithCODEX_HOMEcleared, removed on exitCODEX_HOMEand are untouchedWhy HOME rather than CODEX_HOME
My first version set
CODEX_HOMEto a temporary directory. That broke 30 tests inhooks,install-hooks,installer-cliandunread-result-hook. Those tests already isolate themselves by spawning hooks with a fakeHOME, and an inheritedCODEX_HOMEoverrode it. Isolating at theHOMElevel matches what those tests do and needs no changes to them.Validation
main(19e5651) lists fixtures under~/.codex/plugins/data/cc/state/…(test-status-*,tracked-race-job.json,j1.log,stop-review-history.jsonl)npm run checkandnpm run test:cross-platformrun with the realHOME, and a before/after listing of~/.codex/plugins/datais identical; onmainthe same run created seven fixture filescc-plugin-codex-test-home-*directories remain after the runnpm run check: unit 514 passed, integration 45 passed, Codex E2E 23 passed;test:cross-platform261 passed; lint, typecheck, version-sync and changelog OKNot verified: the Windows CI job.
USERPROFILEis set foros.homedir()there, but I ran it only on macOS.Fixes #127
🤖 Generated with Claude Code