Skip to content

Keep generic tool caches out of the sandboxed test home#23026

Merged
MikeMcQuaid merged 1 commit into
mainfrom
tests-xdg-cache-home
Jul 9, 2026
Merged

Keep generic tool caches out of the sandboxed test home#23026
MikeMcQuaid merged 1 commit into
mainfrom
tests-xdg-cache-home

Conversation

@p-linnane

Copy link
Copy Markdown
Member

brew tests points HOME at Library/Homebrew/test to sandbox local configuration, but leaves XDG_CACHE_HOME unset. Tools that honor the XDG defaults, e.g. RuboCop, then resolve their cache to $HOME/.cache and leave a stray Library/Homebrew/test/.cache directory inside the working tree after a test run.

setup_environment! now pins XDG_CACHE_HOME to HOMEBREW_CACHE/tests right after it sandboxes HOME, mirroring how brew style already redirects RuboCop's cache to HOMEBREW_CACHE/style. A regression spec asserts the value and that it does not live under the sandboxed home.

This only steers third-party tools that honor XDG_CACHE_HOME; Homebrew's own cache is unaffected because HOMEBREW_CACHE is always exported and takes precedence over the XDG-derived default. The cache now lives outside the git tree, so a test run no longer pollutes the checkout.


  • 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 Hyperfine benchmarks.
  • 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?

  • AI was used to generate or assist with generating this PR.

Claude Code (Opus 4.8) reviewed the change and suggested the explanatory comment; I wrote the fix and specs and verified with brew lgtm --online plus targeted dev-cmd/tests specs.


Signed-off-by: Patrick Linnane <patrick@linnane.io>
Copilot AI review requested due to automatic review settings July 9, 2026 05:54

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.

Pull request overview

This pull request ensures brew tests doesn’t leave third-party tool caches inside the sandboxed test HOME (and therefore inside the working tree) by explicitly setting XDG_CACHE_HOME to a location under HOMEBREW_CACHE.

Changes:

  • Pin XDG_CACHE_HOME to #{HOMEBREW_CACHE}/tests immediately after HOME is sandboxed in Homebrew::DevCmd::Tests#setup_environment!.
  • Add a regression spec asserting XDG_CACHE_HOME is set as expected and is not under the sandboxed Dir.home.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Library/Homebrew/dev-cmd/tests.rb Sets XDG_CACHE_HOME to a cache directory under HOMEBREW_CACHE after sandboxing HOME, preventing $HOME/.cache pollution in the checkout.
Library/Homebrew/test/dev-cmd/tests_spec.rb Adds a spec to validate setup_environment! redirects XDG_CACHE_HOME outside the sandboxed test home.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@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.

Thanks!

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Jul 9, 2026
Merged via the queue into main with commit 1f291d5 Jul 9, 2026
43 checks passed
@MikeMcQuaid MikeMcQuaid deleted the tests-xdg-cache-home branch July 9, 2026 07:41
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.

4 participants