Skip to content

Fix test setup crash when multiple package APIs are cached#23016

Merged
MikeMcQuaid merged 1 commit into
mainfrom
spec-helper-package-api-collision
Jul 9, 2026
Merged

Fix test setup crash when multiple package APIs are cached#23016
MikeMcQuaid merged 1 commit into
mainfrom
spec-helper-package-api-collision

Conversation

@p-linnane

Copy link
Copy Markdown
Member

The per-example RSpec setup links the real API cache into the sandbox cache. Library/Homebrew/test/spec_helper.rb treated every packages.*.jws.json in the source cache as a fan-out source, so when the real cache held more than one tag (for example packages.arm64_golden_gate.jws.json and packages.arm64_tahoe.jws.json) the first source created the alias for the second source's target, and linking the second source then raised Errno::EEXIST during setup and broke brew tests.

Setup now picks a single package source, preferring the running tag (Homebrew::SimulateSystem.current_tag) and falling back to the first available, skips packages.* 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/--arch run or OS upgrade can produce, so this is test-helper resilience rather than a brew cleanup change.


  • 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) diagnosed the setup crash and produced the fix; I reviewed the diff and verified with brew lgtm plus targeted dev-cmd/tests and rubocop specs.


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

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 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.json source (prefer current running tag; otherwise first available) and fans out tag aliases from that one file to prevent collisions.
  • Excludes packages.* from the generic api/internal copy/link loop to avoid Errno::EEXIST when 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.

@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 0e01bc7 Jul 9, 2026
43 checks passed
@MikeMcQuaid MikeMcQuaid deleted the spec-helper-package-api-collision branch July 9, 2026 07:29
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