Skip to content

test(cli): fix git env-var leak in git-repo integration tests#57

Open
TAJD wants to merge 2 commits into
mainfrom
wt/cd6-perf
Open

test(cli): fix git env-var leak in git-repo integration tests#57
TAJD wants to merge 2 commits into
mainfrom
wt/cd6-perf

Conversation

@TAJD

@TAJD TAJD commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • advise_diff.rs and orphan_since_report_scope.rs build a disposable git repo in a temp dir and then shell out to git and to the cofferdam binary itself (which internally shells out to git for --diff/--since).
  • When these tests run inside a git hook invoked from a linked worktree (e.g. pre-push), git exports GIT_DIR/GIT_WORK_TREE/GIT_INDEX_FILE pointing at the real repository. Those vars leaked into the child git calls, hijacking git init/git commit away from the test's temp dir and onto the real repo's branch ref — in one run this actually repointed this worktree's own branch at a bogus 1-file commit (recovered locally via git reset --mixed back onto the real commit; no data was lost since blobs/commits stayed in the object store).
  • Fix: clear the three env vars on every git invocation in the test helpers, and add a run_cofferdam() helper in advise_diff.rs that does the same for the binary-under-test, since it shells out to git too.

Discovered while verifying crates/cofferdam-engine's CD-6 perf fixes (Arc-wrapped cache values, corpus deep-clone removal, lock-poison recovery) already merged to main — this PR only contains the test-harness follow-up.

Test plan

  • cargo build --workspace
  • cargo test --workspace (advise_diff + orphan_since_report_scope pass in isolation and via the pre-push hook)
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo fmt --all -- --check

🤖 Generated with Claude Code

https://claude.ai/code/session_01CpKPA1x3bodpMELHY6ag3U

TAJD and others added 2 commits July 4, 2026 07:59
…t helpers

advise_diff.rs and orphan_since_report_scope.rs shell out to `git init`/
`git commit` in a disposable temp dir. When these tests run inside a git
hook invoked from a linked worktree (e.g. pre-push), git exports
GIT_DIR/GIT_WORK_TREE/GIT_INDEX_FILE pointing at the real repo, and those
leak into the child `git` calls -- hijacking them away from the temp dir
and onto the real repo's ref. Clearing the three vars before each `git`
invocation keeps the tests isolated regardless of caller environment.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CpKPA1x3bodpMELHY6ag3U
The prior commit fixed the test harness's own `git init`/`git commit`
calls but missed that these tests also spawn the `cofferdam` binary
itself, which shells out to git internally for --diff/--since. That
inherited the same leaked GIT_DIR/GIT_WORK_TREE/GIT_INDEX_FILE, making
cofferdam analyze the real repo's history instead of the test's temp
repo and report zero findings. Route every advise_diff.rs invocation
through a new run_cofferdam() helper that clears the same three vars,
and do the same for orphan_since_report_scope.rs's single call site.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CpKPA1x3bodpMELHY6ag3U
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.

1 participant