Skip to content

livecheck: add content parameter to strategies, expand test coverage#21505

Open
samford wants to merge 4 commits intomainfrom
livecheck/expand-cached-content-support
Open

livecheck: add content parameter to strategies, expand test coverage#21505
samford wants to merge 4 commits intomainfrom
livecheck/expand-cached-content-support

Conversation

@samford
Copy link
Member

@samford samford commented Feb 2, 2026

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

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, bringing all of the strategies up to 100% coverage for both lines and branches.

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 tidies up the documentation comments for versions_from_content methods to better align them across strategies.

Copilot AI review requested due to automatic review settings February 2, 2026 18:46
@samford samford force-pushed the livecheck/expand-cached-content-support branch from 18c43ef to feac8ac Compare February 2, 2026 18:46
Copy link
Contributor

Copilot AI left a comment

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 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_content to content in all strategy find_versions methods and the Strategic interface
  • Added content parameter to strategies that didn't have it (e.g., Xorg, Sourceforge, Launchpad, etc.)
  • Removed allow_incompatible: true from strategy signatures now aligned with Strategic
  • Updated GithubReleases and GithubLatest to use GitHub::API.open_rest with parse_json: false
  • Fixed Launchpad regex default handling to use regex || DEFAULT_REGEX pattern
  • Improved Sparkle's minimum_system_version handling 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.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).
@samford samford force-pushed the livecheck/expand-cached-content-support branch from feac8ac to 0a72b1a Compare February 4, 2026 16:59
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.

2 participants