Repository navigation
ci(test): fail if tests leave files behind in the working tree - #2719
Merged
Merged
Conversation
`target/` is gitignored, so a clean run is `git status --porcelain`-empty. Untracked or modified paths after `wt hook pre-merge` mean a test wrote outside its sandbox. Sits between the test step and the artifact uploads (which already gate on `always()` / `!cancelled()`, so junit/codecov still upload when the guard fires). Motivated by a stray `default_*_<pid>.profraw` at the worktree root from an earlier session — `.gitignore` is intentionally left untouched so future leaks surface here rather than getting silently hidden. Co-Authored-By: Claude <[email protected]>
worktrunk-bot
approved these changes
May 11, 2026
7 tasks done
max-sixty
added a commit
that referenced
this pull request
May 12, 2026
…nherited (#2730) ## Summary Defaults `LLVM_PROFILE_FILE` to `std::env::temp_dir()/wt-test-profraw/cov-%m_%p.profraw` when nothing is inherited from the parent. `isolate_subprocess_env` previously only *propagated* the var (per #2713), leaving it unset under plain `cargo test`. An instrumented child — most commonly a stale `mock-stub` left instrumented by an earlier coverage build — then fell back to writing `default_<hash>_<pid>.profraw` into its cwd. For any `wt list` snapshot that spawns a mock, that cwd is the test worktree, so `git status --porcelain` saw the profraw as an untracked file and `wt list` rendered "Showing 5 worktrees, 1 with changes, …" instead of "Showing 5 worktrees, 4 ahead". Different subsets of the gitea CI-status tests would flake every parallel run. `default_llvm_profile_file()` is a thin wrapper over `default_llvm_profile_file_with(inherited)` (same outer/inner split as `isolate_subprocess_env` / `isolate_subprocess_env_from`) so a unit test exercises both the inherited and the temp-dir-fallback branches without mutating process env. `COVERAGE_ENV_VARS` is shrunk to `[CARGO_LLVM_COV, CARGO_LLVM_COV_TARGET_DIR]` — `LLVM_PROFILE_FILE` is no longer in it because it's now governed by `default_llvm_profile_file()` — and all three call sites (`isolate_subprocess_env`, `pass_coverage_env_to_pty_cmd`, `configure_pty_environment`) route through that helper plus the constant. Under `cargo llvm-cov`, behavior is unchanged: the inherited `LLVM_PROFILE_FILE` wins, and profraws still land at the path the runner chose. The `%m_%p` placeholders are expanded by the LLVM runtime in the instrumented child; uninstrumented children ignore the env var entirely. The CI guard from #2719 will catch any future helper that bypasses this contract. ## Test plan Verified against a deliberately-reinstalled instrumented `mock-stub` each time: - [x] 5× `cargo test --test integration -- ci_status::test_list_full_with_gitea` — 9/9 pass each run (was flaking ~50%) - [x] 5× `cargo nextest run --test integration ci_status` (67 tests, parallel) — all pass each run - [x] `cargo llvm-cov nextest --test integration ci_status::test_list_full_with_gitea_pr_status::case_1` — passes; profraws land in `target/llvm-cov-target/…` (cargo-llvm-cov's chosen path), not in the worktree - [x] `cargo test --test integration -- ci_status` (full 67) — pass - [x] `cargo test --lib testing::tests::default_llvm` — both new unit tests green (inherited branch + temp-dir fallback) - [x] `cargo clippy --workspace --tests --features shell-integration-tests -- -D warnings` — clean - [x] No stray `default_*.profraw` anywhere after the runs; redirected profraws land in `$TMPDIR/wt-test-profraw/cov-%m_%p.profraw` --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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
Adds a
git status --porcelaincheck afterwt hook pre-merge --yeson eachtest (linux/macos/windows)job. If anything's been written into the working tree (outsidetarget/), CI fails with the file list. Catches profraw strays, leftover hook logs, generated files tests forgot to clean, etc.Motivated by the
default_*_<pid>.profrawstray that prompted #2713 — that PR defended the helper, this PR detects future regressions of the same class (whatever the source)..gitignoreis intentionally untouched: future leaks surface here rather than being silently hidden.Test plan