livecheck: add content parameter to strategies, expand test coverage#21505
Open
livecheck: add content parameter to strategies, expand test coverage#21505
Conversation
18c43ef to
feac8ac
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR renames the provided_content parameter to content across all livecheck strategies for brevity and consistency. It also adds the content parameter to strategies that previously lacked it, enabling future caching functionality. The changes expand test coverage to 100% for both lines and branches across all livecheck strategies.
Changes:
- Renamed
provided_contenttocontentin all strategyfind_versionsmethods and theStrategicinterface - Added
contentparameter to strategies that didn't have it (e.g., Xorg, Sourceforge, Launchpad, etc.) - Removed
allow_incompatible: truefrom strategy signatures now aligned withStrategic - Updated GithubReleases and GithubLatest to use
GitHub::API.open_restwithparse_json: false - Fixed Launchpad regex default handling to use
regex || DEFAULT_REGEXpattern - Improved Sparkle's
minimum_system_versionhandling with defensive nil checking - Updated Xorg caching to always cache content
- Expanded test coverage across all strategies with new test cases
Reviewed changes
Copilot reviewed 45 out of 45 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| strategic.rb | Updated interface signature to use content parameter |
| yaml.rb | Renamed parameter, simplified content fetching logic |
| xorg.rb | Added content parameter, simplified caching logic |
| xml.rb | Renamed parameter, simplified content fetching logic |
| sparkle.rb | Added content parameter, improved nil checking for minimum_system_version |
| sourceforge.rb | Added content parameter, updated PageMatch call |
| pypi.rb | Renamed parameter in delegation to Json strategy |
| page_match.rb | Renamed parameter, added T.absurd for exhaustive matching |
| npm.rb | Renamed parameter, simplified content handling |
| launchpad.rb | Added content parameter, fixed default regex handling |
| json.rb | Renamed parameter, simplified content fetching logic |
| header_match.rb | Renamed parameter |
| hackage.rb | Added content parameter |
| gnu.rb | Added content parameter |
| gnome.rb | Added content parameter, renamed version_data to match_data |
| github_releases.rb | Added content parameter, changed to use parse_json: false, updated versions_from_content signature |
| github_latest.rb | Added content parameter, switched to direct API.open_rest call with parse_json: false |
| git.rb | Renamed parameter, updated documentation |
| electron_builder.rb | Renamed parameter in Yaml delegation |
| crate.rb | Renamed parameter |
| cpan.rb | Added content parameter |
| bitbucket.rb | Added content parameter |
| apache.rb | Added content parameter, changed suffix handling to use T.must |
| All test files | Added comprehensive test coverage including fetched content tests, expanded test data |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
MikeMcQuaid
approved these changes
Feb 3, 2026
Member
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Thanks, looks good, could of T.must questions.
This renames `provided_content` parameters in livecheck strategy `find_versions` methods to `content` (for the sake of brevity) and adds the parameter to those without it. This will be used to implement a caching solution in the future, to avoid fetching duplicate URLs more than once in a given run. In the interim time, this allows us to expand tests for `find_versions` methods, which brings some of these strategies up to 100% code coverage. This change also allows us to remove `allow_incompatible: true` from related `find_versions` method signatures, as they align with what's outlined in `Strategic`. The only exception is `ExtractPlist#find_versions`, which will always differ due to having a `cask` parameter and the `url` parameter being optional (other strategies require a URL to function). Other notable changes: * `GithubReleases.find_versions` calls `GitHub::API.open_rest` and that parses the JSON response by default, so we have to use a `parse_json: false` argument to ensure that `content` is a string and handle the JSON parsing in the strategy. * Similarly, `GithubLatest` uses `GitHub.get_latest_release`, which doesn't support options like `parse_json: false`. `get_latest_release` generates the API URL from the GitHub username and repository before calling `GitHub::API.open_rest` and we already generate the same URL in the strategy, so this switches to an `open_rest` call instead. * `Launchpad.find_versions` uses `DEFAULT_REGEX` as the `regex` parameter's default value but this only applies if the `regex` argument is omitted. If `regex: nil` is used in the `find_versions` call, then `regex` is `nil` instead of the default regex, which isn't what we want. This sets the `regex` parameter's default value to `nil` and uses `regex || DEFAULT_REGEX` in the `PageMatch.find_versions` arguments instead, aligning with other strategies. * The `Xorg` strategy has its own built-in caching (which will be replaced by the general caching solution in the future), so it uses `content || cached_content` for now.
This improves test coverage for livecheck strategies by adding more tests, removing conditional logic that is never true (based on type signatures), refactoring, etc. This brings every strategy up to 100% line and branch coverage.
This tidies up various `versions_from_content` method documentation comments to standardize them a bit more. This also modifies `T.must` usage in the `Sparkle` method to ensure that it's called when defining `item` instead of when `item` is referenced. I tried to get rid of `T.must` usage here but Sorbet simply won't accept that `items` isn't empty. It knows that `items` isn't `nil` and `items.empty?` ensures that `items` isn't empty but it won't accept that `items.first` (or `items[0]`) isn't `nil`.
The `find_versions` methods in the `ExtractPlist` and `HeaderMatch` strategies use `T.must(content)` as `if match_data[:cached]` isn't enough to tell Sorbet that `content` exists. This modifies these conditions to directly use `if content`, which achieves the same goal but allows us to remove related `T.must` usage. Note that we still use `unless match_data[:cached]` later in the method body because we shadow the `content` variable (i.e., `unless content` doesn't work the same way at that point).
feac8ac to
0a72b1a
Compare
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.
brew lgtm(style, typechecking and tests) with your changes locally?This renames
provided_contentparameters in livecheck strategyfind_versionsmethods tocontent(for the sake of brevity) and adds the parameter to those without it. This will be used to implement a caching solution in the future, to avoid fetching duplicate URLs more than once in a given run. In the interim time, this allows us to expand tests forfind_versionsmethods, bringing all of the strategies up to 100% coverage for both lines and branches.This change also allows us to remove
allow_incompatible: truefrom relatedfind_versionsmethod signatures, as they align with what's outlined inStrategic. The only exception isExtractPlist#find_versions, which will always differ due to having acaskparameter and theurlparameter being optional (other strategies require a URL to function).Other notable changes:
GithubReleases.find_versionscallsGitHub::API.open_restand that parses the JSON response by default, so we have to use aparse_json: falseargument to ensure thatcontentis a string and handle the JSON parsing in the strategy.GithubLatestusesGitHub.get_latest_release, which doesn't support options likeparse_json: false.get_latest_releasegenerates the API URL from the GitHub username and repository before callingGitHub::API.open_restand we already generate the same URL in the strategy, so this switches to anopen_restcall instead.Launchpad.find_versionsusesDEFAULT_REGEXas theregexparameter's default value but this only applies if theregexargument is omitted. Ifregex: nilis used in thefind_versionscall, thenregexisnilinstead of the default regex, which isn't what we want. This sets theregexparameter's default value toniland usesregex || DEFAULT_REGEXin thePageMatch.find_versionsarguments instead, aligning with other strategies.Xorgstrategy has its own built-in caching (which will be replaced by the general caching solution in the future), so it usescontent || cached_contentfor now.versions_from_contentmethods to better align them across strategies.