Merge pull request #22061 from Homebrew/fix-audit-livecheck-throttle-days

audit: respect `livecheck` throttle days
This commit is contained in:
Bevan Kay authored and GitHub committed 2026-04-23 06:07:57 +00:00
commit c256c58d27
3 files changed
+98 -2

No files matched your search

+7 -2
View File
@@ -806,8 +806,13 @@ module Cask
)
if result
throttle = cask.livecheck.throttle
throttle ||= referenced_cask.livecheck.throttle if referenced_cask
latest_version = throttle ? result[:latest_throttled] : result[:latest]
throttle_days = cask.livecheck.throttle_days
if referenced_cask
throttle ||= referenced_cask.livecheck.throttle
throttle_days ||= referenced_cask.livecheck.throttle_days
end
latest_version = (throttle || throttle_days) ? result[:latest_throttled] : result[:latest]
end
if latest_version && (cask.version.to_s == latest_version.to_s)
+8
View File
@@ -1193,10 +1193,18 @@ module Homebrew
end
return if sourcefile.nil?
default_branch = Utils.popen_read(
Utils::Git.git,
"symbolic-ref",
"refs/remotes/origin/HEAD",
"--short",
).chomp.delete_prefix("origin/").presence || "main"
relative_sourcefile = sourcefile.relative_path_from(tap.path).to_s
timestamp = Utils.popen_read(
Utils::Git.git,
"log",
default_branch,
"-1",
"--format=%ct",
"--",
+83
View File
@@ -637,6 +637,37 @@ RSpec.describe Cask::Audit, :cask do
end
end
context "when the Cask has a `livecheck` block using `throttle days:`" do
let(:cask_token) { "livecheck-throttle-days" }
let(:cask) do
tmp_cask cask_token.to_s, <<~RUBY
cask "#{cask_token}" do
version "1.2.5"
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
url "https://brew.sh/#{cask_token}-1.2.5.dmg"
name "Throttle Days"
homepage "https://brew.sh/#{cask_token}"
livecheck do
url :homepage
throttle days: 7
end
app "#{cask_token}.app"
end
RUBY
end
it do
allow(Homebrew::Livecheck).to receive(:latest_version).and_return({
latest: Version.new("1.2.6"),
latest_throttled: Version.new("1.2.5"),
})
expect(run).not_to error_with(message)
end
end
context "when the Cask has a `livecheck` block referencing a Cask that uses `throttle`" do
let(:cask_token) { "livecheck-throttle-reference" }
@@ -648,6 +679,58 @@ RSpec.describe Cask::Audit, :cask do
expect(run).not_to error_with(message)
end
end
context "when the Cask has a `livecheck` block referencing a Cask that uses `throttle days:`" do
let(:cask_token) { "livecheck-throttle-days-reference" }
let(:referenced_cask) do
tmp_cask "livecheck-throttle-days-source", <<~RUBY
cask "livecheck-throttle-days-source" do
version "1.2.5"
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
url "https://brew.sh/livecheck-throttle-days-source-1.2.5.dmg"
name "Throttle Days Source"
homepage "https://brew.sh/livecheck-throttle-days-source"
livecheck do
url :homepage
throttle days: 7
end
app "livecheck-throttle-days-source.app"
end
RUBY
end
let(:cask) do
tmp_cask cask_token.to_s, <<~RUBY
cask "#{cask_token}" do
version "1.2.5"
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
url "https://brew.sh/#{cask_token}-1.2.5.dmg"
name "Throttle Days Reference"
homepage "https://brew.sh/#{cask_token}"
livecheck do
cask "livecheck-throttle-days-source"
end
app "#{cask_token}.app"
end
RUBY
end
it do
allow(Homebrew::Livecheck).to receive_messages(
resolve_livecheck_reference: [referenced_cask, nil],
latest_version: {
latest: Version.new("1.2.6"),
latest_throttled: Version.new("1.2.5"),
},
)
expect(run).not_to error_with(message)
end
end
end
describe "when the Cask stanza requires uninstall" do