fix(tests): keep the suite hermetic inside a live Claude Code session#456
Open
Caleb0796 wants to merge 1 commit into
Open
fix(tests): keep the suite hermetic inside a live Claude Code session#456Caleb0796 wants to merge 1 commit into
Caleb0796 wants to merge 1 commit into
Conversation
Running npm test from a shell inside a live Claude Code session fails 4 tests at HEAD and silently pollutes the user's real plugin data: ~150 fake 'codex-plugin-test-*' workspaces and ~420 job records per two runs land in $CLAUDE_PLUGIN_DATA/state, because: - CLAUDE_PLUGIN_DATA is inherited by in-process state writes and by spawned companions (buildEnv spreads process.env), so fixture state goes to the real data dir instead of the temp fallback, and 'resolveStateDir uses a temp-backed per-workspace directory' fails; - CODEX_COMPANION_SESSION_ID (set by the plugin's own session hook) makes status/result session-filter fixture-seeded jobs that carry no sessionId, failing the status/result tests. Fix: helpers.mjs pins CLAUDE_PLUGIN_DATA to a fresh temp root per test process and clears CODEX_COMPANION_SESSION_ID (session-scoped tests set it explicitly); the fallback-path state test now manages the variable locally like its CLAUDE_PLUGIN_DATA sibling already does. Validated: suite run from inside a live Claude Code session (14 CLAUDE*/CODEX* vars present) goes 87/91 -> 91/91 with zero new entries in the real plugin state dir. Co-Authored-By: Claude Fable 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.
Fixes #455.
Problem
npm testrun from inside a live Claude Code session fails 4 tests at HEAD and leaks fixture state into the user's real plugin data dir (~150 fakecodex-plugin-test-*workspaces / ~420 job records per two runs). Two inherited variables cause it:CLAUDE_PLUGIN_DATA→ in-process state writes and spawned companions (buildEnvspreadsprocess.env) resolve state into the real data dir instead of the temp fallback; theresolveStateDirfallback test also fails.CODEX_COMPANION_SESSION_ID(set by the plugin's own session hook) →status/resultsession-filter fixture-seeded jobs that carry nosessionId, so those tests render empty output.Full evidence trail in #455.
Fix (2 files, tests only)
tests/helpers.mjs: pinCLAUDE_PLUGIN_DATAto a freshmkdtemproot for the test process (in-process writers and spawned companions then agree on a temp-backed root, so state handling is still exercised end-to-end), and clearCODEX_COMPANION_SESSION_ID— every session-scoped test already sets it explicitly in the env it composes (sess-current/sess-other).tests/state.test.mjs: the fallback-path test now saves/deletes/restoresCLAUDE_PLUGIN_DATAlocally, exactly like itsuses CLAUDE_PLUGIN_DATA when providedsibling already does.Deliberately did NOT strip
CLAUDE*wholesale inbuildEnv: broker-mode tests rely onCLAUDE_ENV_FILE, and blanket stripping breaks 4 other tests (verified) while still missing the in-process leak path.Testing
CLAUDE*/CODEX*vars in the env): 87/91 → 91/91, and the real plugin state dir gains zero new entries across the run (was ~75 fake workspaces per run before).env -i PATH HOME): 91/91 before and after — no behavior change for CI.🤖 Generated with Claude Code