Skip to content

fix(tests): give git-worktree fixtures unique sibling paths#357

Merged
pofallon merged 1 commit into
mainfrom
fix/worktree-test-shared-path-race
Jul 22, 2026
Merged

fix(tests): give git-worktree fixtures unique sibling paths#357
pofallon merged 1 commit into
mainfrom
fix/worktree-test-shared-path-race

Conversation

@pofallon

Copy link
Copy Markdown
Contributor

Summary

Fixes an intermittent Windows CI failure in test_resolve_workspace_root_detects_worktree (from-subdir assertion) — surfaced while validating #180's PR2 (unrelated code; the Windows re-run went green, confirming a flake).

Root cause

Four tests in crates/core/tests/integration_worktree.rs created their worktree at a fixed shared path: main_path.join("../worktree-feature") resolves to <system-temp>/worktree-feature (and ../worktree1/../worktree2) regardless of the unique per-test TempDir. nextest runs each test in its own process, so concurrent worktree tests collided on that one path — one process's git worktree add/cleanup clobbered another's worktree directory, so during the walk-up the worktree's .git file was missing. resolve_workspace_root then found no git root and returned the subdirectory unchanged:

left:  ...\worktree-feature\src      # returned subdir, unchanged
right: ...\worktree-feature          # expected worktree root

Windows' slower, file-locking filesystem widens the race window, which is why it flaked there and not on Linux/macOS.

Fix

Derive each worktree's sibling name from the main repo's unique TempDir basename (main_path.file_name()), so parallel test processes never share a worktree path. Behavior is otherwise unchanged (still a sibling of the main repo, still canonicalized before use).

Testing

  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo nextest run -E 'binary(=integration_worktree)' — 5/5 pass, repeated 3× with no flake ✓

🤖 Generated with Claude Code

Four tests in integration_worktree.rs created their worktree at a fixed
`<system-temp>/worktree-feature` (and `worktree{1,2}`) sibling path. nextest
runs each test in its own process, so concurrent worktree tests collided on
that single shared path — one process's `git worktree add`/cleanup interfered
with another's, leaving the worktree's `.git` file missing during the walk-up.
`resolve_workspace_root` then found no git root and returned the subdirectory
unchanged. This surfaced as an intermittent Windows failure
(`test_resolve_workspace_root_detects_worktree`, from-subdir assertion), where
the slower/locking filesystem widens the race window.

Derive each worktree's sibling name from the main repo's unique TempDir
basename so parallel test processes never share a path. Behavior is otherwise
identical (still a sibling of the main repo, still canonicalized).

Verified: 5/5 pass locally and across repeated nextest runs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019vhr7Tcf8ybvSZSE1owqBT
@github-actions github-actions Bot added the fix Bug fix label Jul 22, 2026
@pofallon
pofallon merged commit a0b965b into main Jul 22, 2026
14 checks passed
@pofallon
pofallon deleted the fix/worktree-test-shared-path-race branch July 22, 2026 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant