Fix test setup crash when multiple package APIs are cached#23016
Merged
Conversation
Signed-off-by: Patrick Linnane <patrick@linnane.io>
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request hardens the RSpec per-example sandbox setup in spec_helper.rb to avoid crashes when the real Homebrew API cache contains multiple per-tag package API files (a legitimate state after --os/--arch usage or OS upgrades). It makes API cache setup resilient by selecting a single package API source to fan out into the sandbox and by making the copy/link steps idempotent.
Changes:
- Introduces a single selected
packages.*.jws.jsonsource (prefer current running tag; otherwise first available) and fans out tag aliases from that one file to prevent collisions. - Excludes
packages.*from the genericapi/internalcopy/link loop to avoidErrno::EEXISTwhen multiple package files exist. - Adds
target.exist?guards to make cache setup safe across repeated setup passes (e.g., retries) without raising.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8 tasks
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.
The per-example RSpec setup links the real API cache into the sandbox cache.
Library/Homebrew/test/spec_helper.rbtreated everypackages.*.jws.jsonin the source cache as a fan-out source, so when the real cache held more than one tag (for examplepackages.arm64_golden_gate.jws.jsonandpackages.arm64_tahoe.jws.json) the first source created the alias for the second source's target, and linking the second source then raisedErrno::EEXISTduring setup and brokebrew tests.Setup now picks a single package source, preferring the running tag (
Homebrew::SimulateSystem.current_tag) and falling back to the first available, skipspackages.*files in the generic copy/link loop, and fans out the per-tag aliases once from that one source. Non-package cache files keep the existing copy/link behavior, now guarded by an existence check so a repeated setup pass is idempotent.Holding package APIs for multiple tags is a legitimate cache state that any
--os/--archrun or OS upgrade can produce, so this is test-helper resilience rather than abrew cleanupchange.brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?Claude Code (Opus 4.8) diagnosed the setup crash and produced the fix; I reviewed the diff and verified with
brew lgtmplus targeteddev-cmd/testsand rubocop specs.