Skip to content

test: isolate saveState pruning test from shared git-repo state dir - #133

Closed
JiayuuWang wants to merge 1 commit into
openai:mainfrom
JiayuuWang:contribot/fix-state-test-isolation
Closed

JiayuuWang wants to merge 1 commit into
openai:mainfrom
JiayuuWang:contribot/fix-state-test-isolation

Conversation

@JiayuuWang

Copy link
Copy Markdown

Summary

  • Fixes a flaky/failing test: saveState prunes dropped job artifacts when indexed jobs exceed the cap
  • The test was failing because resolveWorkspaceRoot() calls ensureGitRepository(), which climbs to the nearest git root. When tests run inside this plugin's own repository, every fresh makeTempDir() workspace resolves to the same repo root — collapsing all tests onto one shared state directory.
  • Artifact files written by runtime.test.mjs (e.g. review-live.log, task-live.json) bleed into the pruning test's jobs directory, causing the directory-contents deepEqual assertion to fail with unexpected extra files.

Fix: Set CLAUDE_PLUGIN_DATA to the isolated temp workspace for the duration of the test (with env-var cleanup in a finally block), so resolveStateDir roots state under the per-test temp dir. This is the same pattern already used by the resolveStateDir uses CLAUDE_PLUGIN_DATA when it is provided test in the same file.

Test plan

  • node --test tests/state.test.mjs passes (all 3 tests green)
  • node --test tests/state.test.mjs tests/render.test.mjs tests/git.test.mjs passes
  • No other test files are affected

🤖 Generated with Claude Code

resolveWorkspaceRoot() calls ensureGitRepository() which climbs to the
nearest git root. When tests run inside the plugin repository, every
temp workspace resolves to the same repo root, collapsing all tests
onto one shared state directory. Artifact files written by runtime
tests (review-live.log, task-live.json, etc.) then bleed into the
pruning test and cause the directory-contents assertion to fail.

Fix: set CLAUDE_PLUGIN_DATA to the isolated temp workspace for the
duration of the pruning test (with cleanup in a finally block). This
forces resolveStateDir to root state under the temp dir, preventing
cross-test pollution. Follows the same pattern used in the existing
CLAUDE_PLUGIN_DATA test.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@JiayuuWang
JiayuuWang requested a review from a team April 3, 2026 13:46
@dkundel-openai dkundel-openai added the duplicate This issue or pull request already exists label Aug 11, 2026 — with ChatGPT Codex Connector

Copy link
Copy Markdown
Collaborator

Duplicate of #456.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants