Skip to content

tap: require trust in Tap#to_hash - #23333

Merged
MikeMcQuaid merged 1 commit into
mainfrom
worktree-tap-info-crash
Jul 28, 2026
Merged

tap: require trust in Tap#to_hash#23333
MikeMcQuaid merged 1 commit into
mainfrom
worktree-tap-info-crash

Conversation

@carlocab

Copy link
Copy Markdown
Member
  • 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 Opus 5 xhigh with manual review and testing.


Fixes

❯ /opt/homebrew/bin/brew tap-info --installed --json=v1
Error: uninitialized constant Homebrew::Trust
/opt/homebrew/Library/Homebrew/tap.rb:1173:in 'Tap#to_hash'
/opt/homebrew/Library/Homebrew/utils.rb:88:in 'block (2 levels) in Utils.parallel_map'
Please report this issue:
  https://docs.brew.sh/Troubleshooting

Also, adjust the tests to ensure this is caught next time. Unit tests can't
catch this because the missing require from #to_hash is required during
the tests.

`brew tap-info --json=v1 --installed` crashed with `uninitialized
constant Homebrew::Trust` because `Tap#to_hash` referenced
`Homebrew::Trust` without requiring it. It only worked because
`require "api"` transitively loaded `trust` via `download_queue`,
`resource`, `livecheck` and `cask/cask`. That chain went away when
`api.rb` started requiring `download_queue` only under
`HOMEBREW_SORBET_RUNTIME`.

`trust.rb` requires `tap`, so require it lazily like
`Tap#apply_redirected_remote!` already does rather than at the top of the
file.

The existing `tap-info` integration test runs the exact failing command
but passed regardless: `brew tests` sets `HOMEBREW_SORBET_RUNTIME`, which
restores the `download_queue` require and hides the missing one. Run its
subprocess without the Sorbet runtime so it exercises the same require
graph as a real `brew tap-info`. Setting `HOMEBREW_NO_GITHUB_API` stops
`Tap#private?` querying the API, which is the only network access on this
path, so the test no longer needs `:needs_network` and now runs in the
`tests (no Sorbet)` job too.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VH4v2Gfo9kSezLs92eT8KF
Copilot AI review requested due to automatic review settings July 28, 2026 09: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 fixes a runtime error in brew tap-info --installed --json=v1 by ensuring the Trust subsystem is loaded before Tap#to_hash references Homebrew::Trust, and updates the existing integration spec so the missing-require regression is exercised under a more production-like require graph.

Changes:

  • Require trust inside Tap#to_hash to avoid uninitialized constant Homebrew::Trust when JSON tap info is generated.
  • Adjust the tap-info integration spec to run the command with Sorbet runtime disabled and GitHub API disabled (avoiding network dependency) so the missing require would be caught.

Reviewed changes

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

File Description
Library/Homebrew/tap.rb Ensures trust is loaded before computing the trusted field in Tap#to_hash.
Library/Homebrew/test/cmd/tap-info_spec.rb Strengthens the integration test to reproduce the real-world require graph that triggered the error, without requiring network access.

💡 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 enabled auto-merge July 28, 2026 10:09
@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Jul 28, 2026
Merged via the queue into main with commit 66d096f Jul 28, 2026
66 of 67 checks passed
@MikeMcQuaid
MikeMcQuaid deleted the worktree-tap-info-crash branch July 28, 2026 10:48
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