Repository navigation
fix(testing): propagate LLVM coverage env from isolate_subprocess_env - #2713
Merged
Merged
Conversation
Move the `LLVM_PROFILE_FILE` / `CARGO_LLVM_COV*` passthrough loop into `isolate_subprocess_env` and hoist the env-var list to a shared `COVERAGE_ENV_VARS` constant. `configure_cli_command` already did this re-apply, but the test-side superset isn't the only caller — benches use `isolate_subprocess_env` directly per its docstring, so any future caller that does `env_clear()` before us would silently drop coverage env, and an instrumented child would write `default_<hash>_<pid>_*.profraw` next to its cwd instead of the path `cargo llvm-cov` chose. The PTY helpers (`pass_coverage_env_to_pty_cmd`, `progressive_output::configure_pty_environment`) now iterate the same constant so the three lists stay in sync. Co-Authored-By: Claude <[email protected]>
worktrunk-bot
approved these changes
May 11, 2026
worktrunk-bot
left a comment
Collaborator
There was a problem hiding this comment.
One doc nit: the COVERAGE_ENV_VARS rustdoc still describes the PTY helpers as a "mirrored" list to keep in sync, but the same PR makes them iterate this constant directly. Suggestion inline.
Comment on lines
+298
to
+303
| /// LLVM coverage env vars that the parent's `cargo llvm-cov` / `cargo affected` | ||
| /// run sets to point spawned binaries at the right `.profraw` file. Mirrored | ||
| /// in `tests/common/mod.rs::pass_coverage_env_to_pty_cmd` for PTY tests that | ||
| /// `env_clear()`. Keep both lists in sync — dropping `LLVM_PROFILE_FILE` makes | ||
| /// an instrumented child fall back to LLVM's default `default_*.profraw` in | ||
| /// the child's cwd, leaving stray files at the repo root. |
Collaborator
There was a problem hiding this comment.
Suggested change
| /// LLVM coverage env vars that the parent's `cargo llvm-cov` / `cargo affected` | |
| /// run sets to point spawned binaries at the right `.profraw` file. Mirrored | |
| /// in `tests/common/mod.rs::pass_coverage_env_to_pty_cmd` for PTY tests that | |
| /// `env_clear()`. Keep both lists in sync — dropping `LLVM_PROFILE_FILE` makes | |
| /// an instrumented child fall back to LLVM's default `default_*.profraw` in | |
| /// the child's cwd, leaving stray files at the repo root. | |
| /// LLVM coverage env vars that the parent's `cargo llvm-cov` / `cargo affected` | |
| /// run sets to point spawned binaries at the right `.profraw` file. The PTY | |
| /// helpers (`pass_coverage_env_to_pty_cmd`, `configure_pty_environment`) | |
| /// iterate this same list to re-apply it after `env_clear()`. Dropping | |
| /// `LLVM_PROFILE_FILE` makes an instrumented child fall back to LLVM's default | |
| /// `default_*.profraw` in the child's cwd, leaving stray files at the repo root. |
2 tasks
max-sixty
added a commit
that referenced
this pull request
May 11, 2026
## 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. Co-authored-by: Claude <[email protected]>
3 tasks done
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
Move the
LLVM_PROFILE_FILE/CARGO_LLVM_COV*passthrough loop intoisolate_subprocess_envand hoist the env-var list to a sharedCOVERAGE_ENV_VARSconstant. Today the passthrough only runs insideconfigure_cli_command(the test-side superset). Benches useisolate_subprocess_envdirectly per its docstring, so any future caller thatenv_clear()s before us would silently drop the coverage env and the instrumented child would writedefault_<hash>_<pid>_*.profrawnext to its cwd instead of the pathcargo llvm-covchose.The original report was a stray
default_*.profrawat the worktree root from an earlier session. I could not deterministically reproduce the leak undercargo llvm-cov --benchesorcargo llvm-cov --test integrationafter auditing the test/bench call sites, so this is defense-in-depth at the helper that owns the contract rather than a targeted root-cause fix — flagged in commentary above the new const.Changes
src/testing/mod.rs— newpub const COVERAGE_ENV_VARS;isolate_subprocess_envre-applies them at the end; matching block removed fromconfigure_cli_command.tests/common/mod.rs,tests/common/progressive_output.rs— the PTY helpers (pass_coverage_env_to_pty_cmd,configure_pty_environment) iterate the same constant..gitignoreis intentionally untouched so a future regression surfaces ingit statusinstead of getting silently hidden.Test plan
cargo run -- hook pre-merge --yes— green (3627 tests passed, pre-commit hooks clean, doctest + cargo doc clean).cargo llvm-cov --benches --no-report -- skeleton/warm/1— green, no stray*.profrawat repo root.cargo llvm-cov --test integration --no-report -- 'integration_tests::shell_wrapper::...test_bash_completion_produces_correct_output' '...user_hooks::test_var_flag_invalid_format_fails' '...readme_sync' '...help::'— 61 passed, no stray*.profraw.isolate_subprocess_env_scrubs_git_and_worktrunk_keysunit test still passes.