Skip to content

cask/audit: require "macho" before use - #23337

Merged
MikeMcQuaid merged 1 commit into
Homebrew:mainfrom
chenrui333:cask-audit-require-macho
Jul 28, 2026
Merged

cask/audit: require "macho" before use#23337
MikeMcQuaid merged 1 commit into
Homebrew:mainfrom
chenrui333:cask-audit-require-macho

Conversation

@chenrui333

@chenrui333 chenrui333 commented Jul 28, 2026

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.

Fixes uninitialized constant Cask::Audit::MachO raised during online cask audits.

What

Cask::Audit#min_os_from_bundle calls MachO.open (added in #20119) but the macho gem was never required in this scope, so the constant is undefined when the min-OS binary check runs. This loads the gem lazily inline, matching the existing pattern in os/mac/mach.rb (which requires it at point of use to keep it off the Linux load path).

Why

Any brew audit --cask --online that reaches the binary min-OS check crashes instead of auditing. This is currently breaking automated cask bump CI.

Reproduce

Surfaced by Homebrew/homebrew-cask#277654 (failed CI run):

brew audit --cask --online emacs-app@nightly
...
exception while auditing emacs-app@nightly: uninitialized constant Cask::Audit::MachO

After this change the same command audits without raising.

Fixes "uninitialized constant Cask::Audit::MachO" during online audits. The min-OS binary check calls MachO.open but the gem was never required in this scope; load it lazily inline, matching os/mac/mach.rb.

Signed-off-by: Rui Chen <rui@chenrui.dev>

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

Fixes Cask::Audit online cask audits raising uninitialized constant Cask::Audit::MachO by ensuring the macho gem is required before MachO.open is called in the bundle minimum-OS audit path.

Changes:

  • Lazily require "macho" immediately before calling MachO.open in cask_bundle_min_os.
  • Prevents online brew audit --cask --online from crashing when this code path is exercised.

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

Comment thread Library/Homebrew/cask/audit.rb

@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 13:56
@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Jul 28, 2026
Merged via the queue into Homebrew:main with commit b80014d Jul 28, 2026
45 checks passed
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