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.
This commit is contained in:
Andrew Nesbitt committed 2026-07-28 10:29:31 +01:00
1 parent e2c5553eb5
commit 6525bc11ff
6 files changed
+29 -29

No files matched your search

@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "cmd/shared_examples/args_parse"
+8 -8
View File
@@ -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
+9 -9
View File
@@ -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
+1 -1
View File
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "vulns/identify"
+1 -1
View File
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "vulns/purl"
+9 -9
View File
@@ -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