livecheck: prevent unnecessary boolean args#22823
Merged
Merged
Conversation
I recently added a boolean `compressed` option to the `Livecheck.url` method but it should only be used with a `false` value, as livecheck uses compression for `page_content` fetches by default. Similarly, `homebrew_curl` is another boolean option but it should only be `true` or omitted, as brewed curl isn't used by default. This adds additional guards to `Livecheck.url` to prevent unnecessary values from being set as `url` options. This also modifies the related property types in `Livecheck::Options` to only allow the correct types. Under normal circumstances, users should only see the errors from `Livecheck.url` (not Sorbet type errors) as they prevent the method from setting `Options` values that would trigger a type error. The stricter `Options` property types are a safeguard to ensure that we don't use incorrect values when setting these options in livecheck itself. For example, we have some code in livecheck that infers whether a check should use brewed curl and this sets the `homebrew_curl` option value. That logic should only be exercised if `use_homebrew_curl?` returns `true` but the stricter type would catch a `false` value if we were less careful.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens Livecheck.url’s option handling so callers can’t provide redundant/invalid boolean values for options that are effectively “default-on” (compressed) or “opt-in” (homebrew_curl). It also makes Livecheck::Options types reflect those stricter semantics and adds coverage to ensure the new guards raise user-facing ArgumentErrors.
Changes:
- Add runtime guards in
Livecheck#urlto rejectcompressed: trueandhomebrew_curl: false. - Narrow
Livecheck::OptionsSorbet prop types to only allowcompressed: false(or nil) andhomebrew_curl: true(or nil). - Add RSpec examples covering the new
ArgumentErrorcases.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Library/Homebrew/test/livecheck_spec.rb | Adds regression tests ensuring invalid boolean values raise ArgumentError. |
| Library/Homebrew/livecheck/options.rb | Tightens option prop types to enforce “set-only” semantics for compressed/homebrew_curl. |
| Library/Homebrew/livecheck.rb | Adds argument guards in Livecheck#url to prevent setting unsupported boolean values. |
💡 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 recently added a boolean
compressedoption to theLivecheck.urlmethod but it should only be used with afalsevalue, as livecheck uses compression forpage_contentfetches by default. Similarly,homebrew_curlis another boolean option but it should only betrueor omitted, as brewed curl isn't used by default.This adds additional guards to
Livecheck.urlto prevent unnecessary values from being set asurloptions. This also modifies the related property types inLivecheck::Optionsto only allow the correct types. Under normal circumstances, users should only see the errors fromLivecheck.url(not Sorbet type errors) as they prevent the method from settingOptionsvalues that would trigger a type error.The stricter
Optionsproperty types are a safeguard to ensure that we don't use incorrect values when setting these options in livecheck itself. For example, we have some code in livecheck that infers whether a check should use brewed curl and this sets thehomebrew_curloption value. That logic should only be exercised ifuse_homebrew_curl?returnstruebut the stricter type would catch afalsevalue if we were less careful.