From 6525bc11ffcb76d38539b89079f35bd2de721d47 Mon Sep 17 00:00:00 2001 From: Andrew Nesbitt Date: Tue, 28 Jul 2026 09:54:34 +0100 Subject: [PATCH] vulns: raise spec files to typed: true Sorbet rejects described_class::CONST at typed: true, so those references are spelled out. The expect { loaded = ... } capture pattern gets an explicit T.let so the block reassignment does not narrow to nil. match_spec.rb stays typed: false pending its rewrite for per-evidence range evaluation. --- .../test/dev-cmd/advisory-match_spec.rb | 2 +- Library/Homebrew/test/utils/repology_spec.rb | 16 ++++++++-------- Library/Homebrew/test/vulns/cpan_sec_spec.rb | 18 +++++++++--------- Library/Homebrew/test/vulns/identify_spec.rb | 2 +- Library/Homebrew/test/vulns/purl_spec.rb | 2 +- Library/Homebrew/test/vulns/repology_spec.rb | 18 +++++++++--------- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Library/Homebrew/test/dev-cmd/advisory-match_spec.rb b/Library/Homebrew/test/dev-cmd/advisory-match_spec.rb index e29f44810d..3da6a25164 100644 --- a/Library/Homebrew/test/dev-cmd/advisory-match_spec.rb +++ b/Library/Homebrew/test/dev-cmd/advisory-match_spec.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "cmd/shared_examples/args_parse" diff --git a/Library/Homebrew/test/utils/repology_spec.rb b/Library/Homebrew/test/utils/repology_spec.rb index c6933dac58..288da0d1fd 100644 --- a/Library/Homebrew/test/utils/repology_spec.rb +++ b/Library/Homebrew/test/utils/repology_spec.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "utils/repology" @@ -16,10 +16,10 @@ RSpec.describe Repology do it "URL-encodes the project name and passes --fail" do expect(Utils::Curl).to receive(:curl_output) do |*args, **| - expect(args).to include("--fail", "#{described_class::API_BASE}/project/gtk%2B3") + expect(args).to include("--fail", "#{Repology::API_BASE}/project/gtk%2B3") stub_curl(success: true, stdout: "[]") end - expect(described_class.single_package_query("gtk+3", repository: described_class::HOMEBREW_CORE)) + expect(described_class.single_package_query("gtk+3", repository: Repology::HOMEBREW_CORE)) .to eq({ "gtk+3" => [] }) end @@ -27,13 +27,13 @@ RSpec.describe Repology do allow(Utils::Curl).to receive(:curl_output).and_return( stub_curl(success: false, exit_status: 22, stderr: "The requested URL returned error: 503"), ) - expect(described_class.single_package_query("curl", repository: described_class::HOMEBREW_CORE)) + expect(described_class.single_package_query("curl", repository: Repology::HOMEBREW_CORE)) .to be_nil end it "returns nil on invalid JSON" do allow(Utils::Curl).to receive(:curl_output).and_return(stub_curl(success: true, stdout: "not json")) - expect(described_class.single_package_query("curl", repository: described_class::HOMEBREW_CORE)) + expect(described_class.single_package_query("curl", repository: Repology::HOMEBREW_CORE)) .to be_nil end end @@ -41,11 +41,11 @@ RSpec.describe Repology do describe ".query_api" do it "URL-encodes the pagination cursor" do expect(Utils::Curl).to receive(:curl_output) do |*args, **| - expect(args.last).to eq "#{described_class::API_BASE}/projects/gtk%2B3/" \ - "?inrepo=#{described_class::HOMEBREW_CORE}&outdated=1" + expect(args.last).to eq "#{Repology::API_BASE}/projects/gtk%2B3/" \ + "?inrepo=#{Repology::HOMEBREW_CORE}&outdated=1" instance_double(SystemCommand::Result, stdout: "{}") end - described_class.query_api("gtk+3", repository: described_class::HOMEBREW_CORE) + described_class.query_api("gtk+3", repository: Repology::HOMEBREW_CORE) end end end diff --git a/Library/Homebrew/test/vulns/cpan_sec_spec.rb b/Library/Homebrew/test/vulns/cpan_sec_spec.rb index 261fff8c30..7368decccc 100644 --- a/Library/Homebrew/test/vulns/cpan_sec_spec.rb +++ b/Library/Homebrew/test/vulns/cpan_sec_spec.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "vulns/cpan_sec" @@ -13,7 +13,7 @@ RSpec.describe Homebrew::Vulns::CPANSec do bad = Pathname(dir)/"cpansa.json" bad.write "not json" expect { described_class.from_file(bad) } - .to raise_error(described_class::Error, /Failed to parse cpansa\.json/) + .to raise_error(Homebrew::Vulns::CachedFeed::Error, /Failed to parse cpansa\.json/) end end end @@ -21,12 +21,12 @@ RSpec.describe Homebrew::Vulns::CPANSec do describe "#initialize" do it "raises Error when the dists key is missing" do expect { described_class.new({ "meta" => {} }) } - .to raise_error(described_class::Error, /missing 'dists' key/) + .to raise_error(Homebrew::Vulns::CachedFeed::Error, /missing 'dists' key/) end it "raises Error when the top-level value is not a JSON object" do - expect { described_class.new([]) }.to raise_error(described_class::Error, /not a JSON object/) - expect { described_class.new(nil) }.to raise_error(described_class::Error, /not a JSON object/) + expect { described_class.new([]) }.to raise_error(Homebrew::Vulns::CachedFeed::Error, /not a JSON object/) + expect { described_class.new(nil) }.to raise_error(Homebrew::Vulns::CachedFeed::Error, /not a JSON object/) end it "treats a null or absent meta as an empty hash" do @@ -131,10 +131,10 @@ RSpec.describe Homebrew::Vulns::CPANSec do original = stale.read expect(Utils::Curl).to receive(:curl_download) .and_raise(ErrorDuringExecution.new(["curl"], status: 22)) - loaded = nil + loaded = T.let(nil, T.nilable(Homebrew::Vulns::CPANSec)) expect { loaded = described_class.load(cache:) } .to output(/Failed to refresh cpansa\.json/).to_stderr - expect(loaded.distributions).to include "DBI" + expect(loaded&.distributions).to include "DBI" expect(stale.read).to eq original end end @@ -147,10 +147,10 @@ RSpec.describe Homebrew::Vulns::CPANSec do FileUtils.touch stale, mtime: Time.now - 100_000 original = stale.read expect(Utils::Curl).to receive(:curl_download) { |*_args, to:| to.write "not json" } - loaded = nil + loaded = T.let(nil, T.nilable(Homebrew::Vulns::CPANSec)) expect { loaded = described_class.load(cache:) } .to output(/Failed to refresh cpansa\.json/).to_stderr - expect(loaded.distributions).to include "DBI" + expect(loaded&.distributions).to include "DBI" expect(stale.read).to eq original expect(cache.children).to eq [stale] end diff --git a/Library/Homebrew/test/vulns/identify_spec.rb b/Library/Homebrew/test/vulns/identify_spec.rb index b7701aeda0..12f17edcd4 100644 --- a/Library/Homebrew/test/vulns/identify_spec.rb +++ b/Library/Homebrew/test/vulns/identify_spec.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "vulns/identify" diff --git a/Library/Homebrew/test/vulns/purl_spec.rb b/Library/Homebrew/test/vulns/purl_spec.rb index acd1a594a9..40b5ff291a 100644 --- a/Library/Homebrew/test/vulns/purl_spec.rb +++ b/Library/Homebrew/test/vulns/purl_spec.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "vulns/purl" diff --git a/Library/Homebrew/test/vulns/repology_spec.rb b/Library/Homebrew/test/vulns/repology_spec.rb index db9f80bd73..feff989a7e 100644 --- a/Library/Homebrew/test/vulns/repology_spec.rb +++ b/Library/Homebrew/test/vulns/repology_spec.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "vulns/repology" @@ -10,12 +10,12 @@ RSpec.describe Homebrew::Vulns::Repology do describe "#initialize" do it "raises Error when the top-level value is not a JSON object" do expect { described_class.new([]) } - .to raise_error(described_class::Error, /not a JSON object/) + .to raise_error(Homebrew::Vulns::CachedFeed::Error, /not a JSON object/) end it "raises Error when the formulae key is missing" do expect { described_class.new({ "meta" => {} }) } - .to raise_error(described_class::Error, /missing 'formulae' key/) + .to raise_error(Homebrew::Vulns::CachedFeed::Error, /missing 'formulae' key/) end end @@ -240,8 +240,8 @@ RSpec.describe Homebrew::Vulns::Repology do it "propagates fetch errors rather than treating them as a miss" do allow(described_class).to receive(:fetch_project) - .and_raise(described_class::Error, "Repology API request failed") - expect { described_class.lookup("curl") }.to raise_error(described_class::Error) + .and_raise(Homebrew::Vulns::CachedFeed::Error, "Repology API request failed") + expect { described_class.lookup("curl") }.to raise_error(Homebrew::Vulns::CachedFeed::Error) end end @@ -261,13 +261,13 @@ RSpec.describe Homebrew::Vulns::Repology do it "raises Error when the underlying query fails (returns nil)" do allow(Repology).to receive(:single_package_query).and_return(nil) expect { described_class.fetch_project("curl") } - .to raise_error(described_class::Error, /request for "curl" failed/) + .to raise_error(Homebrew::Vulns::CachedFeed::Error, /request for "curl" failed/) end it "raises Error on an unexpected response shape" do allow(Repology).to receive(:single_package_query).and_return({ "curl" => { "oops" => true } }) expect { described_class.fetch_project("curl") } - .to raise_error(described_class::Error, /unexpected shape/) + .to raise_error(Homebrew::Vulns::CachedFeed::Error, /unexpected shape/) end end @@ -289,10 +289,10 @@ RSpec.describe Homebrew::Vulns::Repology do FileUtils.touch stale, mtime: Time.now - (described_class.default_max_age + 1) expect(Utils::Curl).to receive(:curl_download) .and_raise(ErrorDuringExecution.new(["curl"], status: 22)) - loaded = nil + loaded = T.let(nil, T.nilable(Homebrew::Vulns::Repology)) expect { loaded = described_class.load(cache:) } .to output(/Failed to refresh repology\.json/).to_stderr - expect(loaded.formulae).to include "curl" + expect(loaded&.formulae).to include "curl" end end end