Skip to content

Stop brew tests dirtying the working tree - #23800

Merged
dduugg merged 1 commit into
mainfrom
test-local-mise-leak
Sep 5, 2026
Merged

Stop brew tests dirtying the working tree#23800
dduugg merged 1 commit into
mainfrom
test-local-mise-leak

Conversation

@dduugg

@dduugg dduugg commented Sep 5, 2026

Copy link
Copy Markdown
Member

brew tests points HOME at Library/Homebrew/test so local configuration cannot affect a run, which means any tool a spec shells out to writes into the checkout. mise left .local/state/mise/tracked-configs and .local/share/mise/migrations behind, untracked and never cleaned up. The tool is incidental, since anything that respects $HOME can do this, and it cannot be fixed from the other side: bin/brew filters the environment down to an allowlist, so exported XDG_* and MISE_* never reach the spec subprocesses.

The fix has two halves, each matching how brew already handles this. XDG_CACHE_HOME is redirected out of the test home on the line above, in 38ff362, so XDG_STATE_HOME is redirected the same way; nothing in brew reads it. XDG_DATA_HOME is deliberately not redirected, because unlike a cache or state directory it holds live tool installs, and pointing it elsewhere left a mise shim 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 is test/.local/share/ rather than test/.local/ on purpose, so that .local/state/ stays visible and a regression in the redirect still surfaces in git status instead of being silently ignored.

Repro, with mise installed:

HOME="$PWD/Library/Homebrew/test" mise current
ls Library/Homebrew/test/.local

  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include brew benchmark results.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

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.


Copilot AI balanced review requested due to automatic review settings September 5, 2026 04:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃煛 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_HOME to Homebrew鈥檚 test cache.
  • Removes residual test/.local data 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.

Comment thread Library/Homebrew/test/spec_helper.rb Outdated
Comment thread Library/Homebrew/dev-cmd/tests.rb Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃煛 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 #run example that makes the RSpec subprocess fail and verifies this path is still removed, so the required ensure behaviour cannot regress unnoticed.
        FileUtils.rm_rf HOMEBREW_LIBRARY_PATH/"test/.local"
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread Library/Homebrew/dev-cmd/tests.rb Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃煝 Approval recommended

The cleanup is correctly scoped after worker completion and the new behaviour has focused regression coverage.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@dduugg
dduugg force-pushed the test-local-mise-leak branch from bbf842a to 5a68830 Compare September 5, 2026 05:32
@dduugg
dduugg requested a balanced review from Copilot September 5, 2026 05:33
@dduugg
dduugg force-pushed the test-local-mise-leak branch from 5a68830 to 20d8df6 Compare September 5, 2026 05:35
@dduugg dduugg changed the title Keep tool state out of the sandboxed test home Stop tools writing into the sandboxed test home Sep 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃煛 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

- `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`
@dduugg
dduugg force-pushed the test-local-mise-leak branch from 9fcc4fe to eb961ac Compare September 5, 2026 05:44
@dduugg dduugg changed the title Stop tools writing into the sandboxed test home Stop brew tests dirtying the working tree Sep 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃煝 Approval recommended

The functional change is focused and covered, with only a non-blocking test-convention adjustment remaining.

Review details
  • Files reviewed: 2/3 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread Library/Homebrew/test/dev-cmd/tests_spec.rb
@dduugg
dduugg enabled auto-merge September 5, 2026 06:26

@MikeMcQuaid MikeMcQuaid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, thanks again!

@dduugg
dduugg added this pull request to the merge queue Sep 5, 2026
Merged via the queue into main with commit 08feadd Sep 5, 2026
85 of 86 checks passed
@dduugg
dduugg deleted the test-local-mise-leak branch September 5, 2026 08:12
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.

3 participants