Keep generic tool caches out of the sandboxed test home#23026
Merged
Conversation
Signed-off-by: Patrick Linnane <patrick@linnane.io>
Contributor
There was a problem hiding this comment.
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_HOMEto#{HOMEBREW_CACHE}/testsimmediately afterHOMEis sandboxed inHomebrew::DevCmd::Tests#setup_environment!. - Add a regression spec asserting
XDG_CACHE_HOMEis set as expected and is not under the sandboxedDir.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.
carlocab
approved these changes
Jul 9, 2026
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.
brew testspointsHOMEatLibrary/Homebrew/testto sandbox local configuration, but leavesXDG_CACHE_HOMEunset. Tools that honor the XDG defaults, e.g. RuboCop, then resolve their cache to$HOME/.cacheand leave a strayLibrary/Homebrew/test/.cachedirectory inside the working tree after a test run.setup_environment!now pinsXDG_CACHE_HOMEtoHOMEBREW_CACHE/testsright after it sandboxesHOME, mirroring howbrew stylealready redirects RuboCop's cache toHOMEBREW_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 becauseHOMEBREW_CACHEis 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.brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?Claude Code (Opus 4.8) reviewed the change and suggested the explanatory comment; I wrote the fix and specs and verified with
brew lgtm --onlineplus targeteddev-cmd/testsspecs.