Skip to content

fix(tests): repo-mutation guard classifies sibling-worktree activity instead of blaming the suite - #220

Merged
fdaviddpt merged 1 commit into
mainfrom
fix/219-worktree-guard-false-positive
Jul 29, 2026
Merged

fdaviddpt merged 1 commit into
mainfrom
fix/219-worktree-guard-false-positive

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

The bug

tests/conftest.py's session-scoped _guard_launching_repo_is_not_mutated fingerprints four things, one of which — git worktree list — is repo-wide rather than worktree-local. The fixture brackets the whole run, so any commit or checkout in any worktree of the same clone during those ten minutes changes the string and fails the suite, with:

Test suite mutated the repo it was launched from — this is the exact GIT_DIR-leak class of bug tracked by _sanitize_ambient_git_env. DO NOT ignore this.

The guard observed "the clone's state changed". It reported "this suite changed it, and here is the defect class". Parallel worktrees are the normal working mode here, so this keeps firing — at the end of a ten-minute run, after all the work.

The fix — classify, don't compare

Deleting the worktrees= line would fix the false positive by deleting coverage: an escaped test registering a pytest tmp dir as a live worktree is exactly what the 2026-07 incident did. So the fingerprint became structured (RepoFingerprint) and the before/after pair is classified (_classify_repo_change) into three states rather than two, per the ok / finding / cannot tell contract:

verdict what changed outcome
ok nothing pass
concurrent only other worktrees' HEADs pass, warns naming the worktrees that moved
mutated bareness, this worktree's HEAD / status / toplevel / own worktree entry fail, original GIT_DIR-leak wording verbatim
unattributable the worktree set gained or lost an entry fail, says plainly it cannot attribute it

mutated is evaluated first, so a real mutation concurrent with sibling activity is still reported as a mutation. unattributable fails — an escaped worktree add and a human git worktree add are indistinguishable from here, and an unexplained change to the clone must never be waved through; what changes is that the guard says which question it could not answer instead of asserting the most alarming one.

Why this does not weaken the guard

  • Every field the old blob compared is still compared. Nothing was dropped; toplevel was added.
  • The only path that now passes is a change confined to worktree entries other than this one, where this worktree's HEAD, status and bareness are all byte-identical. A mutation of the launching worktree cannot land there.
  • tests/test_repo_mutation_guard.py pins it from both sides: stray commit, core.bare flip, dirty working tree, deleted tracked file, and mutation-plus-concurrent-activity all assert mutated; and the fixture is driven end-to-end in a throwaway clone — an inner suite whose test commits into its own launching repo still fails the inner run with GIT_DIR-leak / DO NOT ignore this, while an inner suite whose test only moves a sibling worktree passes.

Verification

  • New file red before the fix (classifier absent); the false positive was also reproduced against the pre-fix conftest.py at fixture level — the sibling-only inner run failed on a worktrees= line differing solely in the sibling's SHA.
  • Full suite: 960 passed, 41 skipped, coverage 93.98%.

Closes #219

The session-scoped mutation guard fingerprinted `git worktree list`, which
is repo-wide, so a sibling worktree of the same clone committing during the
run failed the suite with a GIT_DIR-leak accusation it had no evidence for.

Fingerprint is now structured and the before/after pair classified into three
states: mutation of the launching worktree (fails, original wording kept),
concurrent sibling activity (warns, passes), and an unattributable change to
the worktree set (fails, says it cannot attribute it).

Closes #219

Co-Authored-By: Max <noreply>
@fdaviddpt
fdaviddpt merged commit fb3c910 into main Jul 29, 2026
12 checks passed
@fdaviddpt
fdaviddpt deleted the fix/219-worktree-guard-false-positive branch July 29, 2026 13:57
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.

tests: the repo-mutation guard fails the run when a sibling worktree moves, and blames the suite

2 participants