Skip to content

ci(test): fail if tests leave files behind in the working tree - #2719

Merged
max-sixty merged 1 commit into
mainfrom
profraw-cleanup
May 11, 2026
Merged

max-sixty merged 1 commit into
mainfrom
profraw-cleanup

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Summary

Adds a git status --porcelain check after wt hook pre-merge --yes on each test (linux/macos/windows) job. If anything's been written into the working tree (outside target/), CI fails with the file list. Catches profraw strays, leftover hook logs, generated files tests forgot to clean, etc.

Motivated by the default_*_<pid>.profraw stray that prompted #2713 — that PR defended the helper, this PR detects future regressions of the same class (whatever the source). .gitignore is intentionally untouched: future leaks surface here rather than being silently hidden.

Test plan

  • CI passes on this PR (sanity check: the guard itself doesn't fire on a clean run).
  • If it does fire on something pre-existing, surface what and fix.

`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]>
@max-sixty
max-sixty merged commit bb92a3c into main May 11, 2026
33 checks passed
@max-sixty
max-sixty deleted the profraw-cleanup branch May 11, 2026 21:55
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]>
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.

2 participants