From 6549e8ff73eb9cfef22dd5300c509cb12de4a6e9 Mon Sep 17 00:00:00 2001 From: Patrick Linnane Date: Tue, 11 Aug 2026 22:29:38 -0700 Subject: [PATCH] Require an installable artifact when auditing casks Signed-off-by: Patrick Linnane --- Library/Homebrew/cask/audit.rb | 17 ++++++++--- Library/Homebrew/test/cask/audit_spec.rb | 36 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index c0d6f600ba..44291f05a1 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -344,10 +344,19 @@ module Cask add_error "a #{sym} stanza is required" unless cask.public_send(sym) end 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_artifacts = cask.artifacts.reject { |k| rejected_artifacts.include?(k) } - add_error "at least one activatable artifact stanza is required" if installable_artifacts.empty? + + installable_artifact = if cask.on_system_blocks_exist? + begin + 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 sig { void } diff --git a/Library/Homebrew/test/cask/audit_spec.rb b/Library/Homebrew/test/cask/audit_spec.rb index 5f68157726..b4d556fc93 100644 --- a/Library/Homebrew/test/cask/audit_spec.rb +++ b/Library/Homebrew/test/cask/audit_spec.rb @@ -170,6 +170,42 @@ RSpec.describe Cask::Audit, :cask do it { is_expected.to error_with(/#{stanza} stanza is required/) } 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 describe "checking homepage availability" do