Skip to content

fix(tests): keep the suite hermetic inside a live Claude Code session#456

Open
Caleb0796 wants to merge 1 commit into
openai:mainfrom
Caleb0796:fix/hermetic-test-env
Open

fix(tests): keep the suite hermetic inside a live Claude Code session#456
Caleb0796 wants to merge 1 commit into
openai:mainfrom
Caleb0796:fix/hermetic-test-env

Conversation

@Caleb0796

Copy link
Copy Markdown

Fixes #455.

Problem

npm test run 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 fake codex-plugin-test-* workspaces / ~420 job records per two runs). Two inherited variables cause it:

  • CLAUDE_PLUGIN_DATA → in-process state writes and spawned companions (buildEnv spreads process.env) resolve state into the real data dir instead of the temp fallback; the resolveStateDir fallback test also fails.
  • CODEX_COMPANION_SESSION_ID (set by the plugin's own session hook) → status/result session-filter fixture-seeded jobs that carry no sessionId, so those tests render empty output.

Full evidence trail in #455.

Fix (2 files, tests only)

  • tests/helpers.mjs: pin CLAUDE_PLUGIN_DATA to a fresh mkdtemp root 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 clear CODEX_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/restores CLAUDE_PLUGIN_DATA locally, exactly like its uses CLAUDE_PLUGIN_DATA when provided sibling already does.

Deliberately did NOT strip CLAUDE* wholesale in buildEnv: broker-mode tests rely on CLAUDE_ENV_FILE, and blanket stripping breaks 4 other tests (verified) while still missing the in-process leak path.

Testing

  • Inside a live Claude Code session (14 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).
  • Under a clean env (env -i PATH HOME): 91/91 before and after — no behavior change for CI.

🤖 Generated with Claude Code

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>
@Caleb0796 Caleb0796 requested a review from a team July 8, 2026 08:42
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 suite is not hermetic inside a live Claude Code session: 4 failures at HEAD + fixture state leaks into the user's real plugin data dir

1 participant