Stop brew tests dirtying the working tree - #23800
Conversation
There was a problem hiding this comment.
馃煛 Changes recommended
Per-example cleanup introduces a cross-worker race, and the new environment redirect lacks regression coverage.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Redirects tool state away from the sandboxed test home and adds fallback cleanup.
Changes:
- Sets
XDG_STATE_HOMEto Homebrew鈥檚 test cache. - Removes residual
test/.localdata during teardown.
File summaries
| File | Description |
|---|---|
Library/Homebrew/dev-cmd/tests.rb |
Redirects test tool state. |
Library/Homebrew/test/spec_helper.rb |
Adds fallback state cleanup. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Balanced
馃挕 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
馃煛 Changes recommended
The fallback cleanup lacks regression coverage, and its comments reference a nonexistent API.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (2)
Library/Homebrew/dev-cmd/tests.rb:283
- This repeats a reference to the nonexistent
Cask::Utils.trash!; use the actual XDG-aware method name so the comment remains traceable to its implementation.
# `XDG_DATA_HOME` is deliberately left alone: `Cask::Utils.trash!` reads it.
Library/Homebrew/dev-cmd/tests.rb:227
- The new fallback cleanup is not covered by the added spec; that spec only checks
XDG_STATE_HOME. Add a#runexample that makes the RSpec subprocess fail and verifies this path is still removed, so the requiredensurebehaviour cannot regress unnoticed.
FileUtils.rm_rf HOMEBREW_LIBRARY_PATH/"test/.local"
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
bbf842a to
5a68830
Compare
5a68830 to
20d8df6
Compare
There was a problem hiding this comment.
馃煛 Changes recommended
The broad .local ignore masks future state leaks that the redirect is intended to prevent.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 2/3 changed files
- Comments generated: 0 new
- Review effort level: Balanced
20d8df6 to
9fcc4fe
Compare
- `brew tests` points `HOME` at `Library/Homebrew/test`, so any tool a spec shells out to writes into the checkout - `mise` left `.local/state/mise` and `.local/share/mise` behind - redirect `XDG_STATE_HOME`, as `XDG_CACHE_HOME` already is - `XDG_DATA_HOME` holds live tool installs rather than scratch, so ignore `test/.local/share` instead; `.local/state` stays visible so a regression in the redirect still shows up in `git status`
9fcc4fe to
eb961ac
Compare
brew testspointsHOMEatLibrary/Homebrew/testso local configuration cannot affect a run, which means any tool a spec shells out to writes into the checkout.miseleft.local/state/mise/tracked-configsand.local/share/mise/migrationsbehind, untracked and never cleaned up. The tool is incidental, since anything that respects$HOMEcan do this, and it cannot be fixed from the other side:bin/brewfilters the environment down to an allowlist, so exportedXDG_*andMISE_*never reach the spec subprocesses.The fix has two halves, each matching how brew already handles this.
XDG_CACHE_HOMEis redirected out of the test home on the line above, in 38ff362, soXDG_STATE_HOMEis redirected the same way; nothing in brew reads it.XDG_DATA_HOMEis deliberately not redirected, because unlike a cache or state directory it holds live tool installs, and pointing it elsewhere left amiseshim unable to resolve its own Ruby at all. What lands under it is gitignored instead, joining the six entries already there for tools that write into the test home:test/.gem,.cargo/,.homebrew/,.subversion,.npm/and.rdbg_history. The entry istest/.local/share/rather thantest/.local/on purpose, so that.local/state/stays visible and a regression in the redirect still surfaces ingit statusinstead of being silently ignored.Repro, with
miseinstalled:brew benchmarkresults.brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?AI/LLM disclosure: Claude Opus 5 via Claude Code helped trace the leak and draft the change; I reviewed it and confirmed the checkout stays clean across full test runs.