tap: require trust in Tap#to_hash - #23333
Merged
Merged
Conversation
`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
Contributor
There was a problem hiding this comment.
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
trustinsideTap#to_hashto avoiduninitialized constant Homebrew::Trustwhen JSON tap info is generated. - Adjust the
tap-infointegration 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.
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.
brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?Claude Opus 5 xhigh with manual review and testing.
Fixes
Also, adjust the tests to ensure this is caught next time. Unit tests can't
catch this because the missing
requirefrom#to_hashisrequired duringthe tests.