test/os/mac/keg: require macho - #23334
Merged
Merged
Conversation
`Keg#codesign_patched_binary signs patched binaries using ruby-macho`
sets an expectation on `MachO` before calling the method that requires
it, so it only passes when something earlier in the same process has
already loaded `macho`. Which examples run first depends on the RSpec
seed and how `parallel_tests` groups files, so this fails intermittently:
$ brew tests --only=os/mac/keg:45
Failure/Error: expect(MachO).to receive(:codesign!).with(file)
uninitialized constant MachO
`MachOShim` used to require `macho` at the top of `os/mac/mach.rb`, which
made the constant reliably available; it now requires it inside
`#initialize` and `#macho` instead. Require it from the spec rather than
undoing that, since the production code paths do require it before use.
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 PR fixes a failing macOS-specific Keg spec by explicitly loading the ruby-macho gem so the MachO constant is defined when setting expectations, aligning the test setup with Keg#codesign_patched_binary’s runtime dependency on ruby-macho.
Changes:
- Add
require "macho"toLibrary/Homebrew/test/os/mac/keg_spec.rbsoexpect(MachO)...doesn’t raiseNameError.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
MikeMcQuaid
approved these changes
Jul 28, 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.
brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?Claude Opus 5 xhigh with manual review and testing.
Fixes
https://github.com/Homebrew/brew/actions/runs/30348581931/job/90241094273?pr=23333#step:12:56