cask/audit: fix nil crash in min_os check#23268
Merged
Merged
Conversation
`audit_min_os` compares `depends_on_min_os` and `cask_min_os` against `HOMEBREW_MACOS_OLDEST_ALLOWED` without nil guards. Both are nil for a cask with no `depends_on macos:` and no versioned on_system block, so when the artifact's minimum macOS exceeds the floor the audit raises `undefined method '>' for nil` (reported as "exception while auditing <cask>") instead of the intended "cask declared no minimum macOS version" error. macOS-only casks always declare a minimum OS requirement using the `depends_on macos:` syntax, so the nil path was only exposed by cross-platform casks that scope macOS artifacts in an `on_macos` block and declare no macOS version. This guards the nil cases so the audit doesn't crash and add a regression test for an app requiring a newer macOS with no declared minimum.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a crash in Cask::Audit’s minimum macOS version audit when a cask has neither a depends_on macos: stanza nor a versioned on_system minimum, ensuring the audit reports the intended error instead of raising an exception.
Changes:
- Add nil guards around
depends_on_min_os/cask_min_oscomparisons and logging inaudit_min_os. - Add a regression spec covering a macOS-scoped artifact with no declared minimum macOS version, where the artifact requires a newer macOS.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| Library/Homebrew/cask/audit.rb | Adds nil-safe handling in audit_min_os to prevent nil > ... crashes and keep the audit reporting a proper error. |
| Library/Homebrew/test/cask/audit_spec.rb | Adds a regression test for the nil-minimum-OS path to ensure the audit errors cleanly instead of crashing. |
💡 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?I identified the crash when working on the
lm-studiocask, debugged with Opus 4.8 and tested both by Opus and by hand. Tests run usingbrew lgtm --onlineaudit_min_oscomparesdepends_on_min_osandcask_min_osagainstHOMEBREW_MACOS_OLDEST_ALLOWEDwithout nil guards. Both are nil for a cask with nodepends_on macos:and no versionedon_systemblock, so when the artifact's minimum macOS exceeds the floor the audit raisesundefined method '>' for nil(reported as "exception while auditing ") instead of the intended "cask declared no minimum macOS version" error.macOS-only casks declare a minimum OS requirement using the
depends_on macos:syntax, so the nil path was only exposed by cross-platform casks that scope macOS artifacts in anon_macosblock and declare no macOS version.This guards the nil cases so the audit doesn't crash and add a regression test for an app requiring a newer macOS with no declared minimum.