Skip to content

test/os/mac/keg: require macho - #23334

Merged
carlocab merged 1 commit into
mainfrom
keg-spec-require-macho
Jul 28, 2026
Merged

test/os/mac/keg: require macho#23334
carlocab merged 1 commit into
mainfrom
keg-spec-require-macho

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

  1) Keg#codesign_patched_binary signs patched binaries using ruby-macho
     Failure/Error: expect(MachO).to receive(:codesign!).with(file)

     NameError:
       uninitialized constant MachO
     # ./test/os/mac/keg_spec.rb:48:in 'block (3 levels) in <top (required)>'

https://github.com/Homebrew/brew/actions/runs/30348581931/job/90241094273?pr=23333#step:12:56

`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
Copilot AI review requested due to automatic review settings July 28, 2026 10:29
@carlocab
carlocab enabled auto-merge July 28, 2026 10:30

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 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" to Library/Homebrew/test/os/mac/keg_spec.rb so expect(MachO)... doesn’t raise NameError.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@carlocab
carlocab added this pull request to the merge queue Jul 28, 2026
Merged via the queue into main with commit 6937a1e Jul 28, 2026
44 checks passed
@carlocab
carlocab deleted the keg-spec-require-macho branch July 28, 2026 11:06
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