Require an installable artifact when auditing casks

Signed-off-by: Patrick Linnane <patrick@linnane.io>
This commit is contained in:
Patrick Linnane
2026-08-11 22:29:38 -07:00
parent 88d6178c7d
commit 6549e8ff73
2 changed files with 49 additions and 4 deletions
+13 -4
View File
@@ -344,10 +344,19 @@ module Cask
add_error "a #{sym} stanza is required" unless cask.public_send(sym) add_error "a #{sym} stanza is required" unless cask.public_send(sym)
end end
add_error "at least one name stanza is required" if cask.name.empty? add_error "at least one name stanza is required" if cask.name.empty?
# TODO: specific DSL knowledge should not be spread around in various files like this
rejected_artifacts = [:uninstall, :zap] installable_artifact = if cask.on_system_blocks_exist?
installable_artifacts = cask.artifacts.reject { |k| rejected_artifacts.include?(k) } begin
add_error "at least one activatable artifact stanza is required" if installable_artifacts.empty? OnSystem::VALID_OS_ARCH_TAGS.any? do |tag|
cask.refresh_for_tag(tag) { cask.installable_artifact? }
end
ensure
cask.refresh
end
else
cask.installable_artifact?
end
add_error "at least one installable artifact stanza is required" unless installable_artifact
end end
sig { void } sig { void }
+36
View File
@@ -170,6 +170,42 @@ RSpec.describe Cask::Audit, :cask do
it { is_expected.to error_with(/#{stanza} stanza is required/) } it { is_expected.to error_with(/#{stanza} stanza is required/) }
end end
end end
context "when a cask has only uninstall artifacts" do
let(:cask) do
Cask::Cask.new("uninstall-only") do
version :latest
sha256 :no_check
url "https://brew.sh/foo.pkg"
name "Uninstall Only"
homepage "https://brew.sh/"
uninstall pkgutil: "org.example.foo"
zap trash: "~/Library/Caches/org.example.foo"
end
end
it { is_expected.to error_with("at least one installable artifact stanza is required") }
end
context "when a cask has an installable artifact only on Linux" do
let(:cask) do
Homebrew::SimulateSystem.with(os: :sequoia, arch: :arm) do
Cask::Cask.new("linux-only-artifact") do
version :latest
sha256 :no_check
url "https://brew.sh/foo"
name "Linux Only Artifact"
homepage "https://brew.sh/"
on_linux do
binary "foo"
end
end
end
end
it { is_expected.not_to error_with("at least one installable artifact stanza is required") }
end
end end
describe "checking homepage availability" do describe "checking homepage availability" do