test: isolate saveState pruning test from shared git-repo state dir#133
Open
JiayuuWang wants to merge 1 commit intoopenai:mainfrom
Open
test: isolate saveState pruning test from shared git-repo state dir#133JiayuuWang wants to merge 1 commit intoopenai:mainfrom
JiayuuWang wants to merge 1 commit intoopenai:mainfrom
Conversation
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>
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
saveState prunes dropped job artifacts when indexed jobs exceed the capresolveWorkspaceRoot()callsensureGitRepository(), which climbs to the nearest git root. When tests run inside this plugin's own repository, every freshmakeTempDir()workspace resolves to the same repo root — collapsing all tests onto one shared state directory.runtime.test.mjs(e.g.review-live.log,task-live.json) bleed into the pruning test's jobs directory, causing the directory-contentsdeepEqualassertion to fail with unexpected extra files.Fix: Set
CLAUDE_PLUGIN_DATAto the isolated temp workspace for the duration of the test (with env-var cleanup in afinallyblock), soresolveStateDirroots state under the per-test temp dir. This is the same pattern already used by theresolveStateDir uses CLAUDE_PLUGIN_DATA when it is providedtest in the same file.Test plan
node --test tests/state.test.mjspasses (all 3 tests green)node --test tests/state.test.mjs tests/render.test.mjs tests/git.test.mjspasses🤖 Generated with Claude Code