Skip to content

Commit 471c947

Browse files
committed
Fix Sorbet runtime type errors in TestBot
Fix two runtime type errors found in CI after the initial strict typing PR: 1. `Test#test` arguments parameter: Accept `T.any(String, Pathname)` and convert to strings via `.map(&:to_s)` before passing to `Step.new`. Callers like `TestCleanup` pass `repository` (a `Pathname`) directly. 2. `BottlesFetch#fetch_bottles!` tag parameter: Accept `Utils::Bottles::Tag` (what `collector.tags` actually returns) instead of `Symbol`.
1 parent ec8f058 commit 471c947

File tree

5 files changed

+45
-5
lines changed

5 files changed

+45
-5
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
require "test_bot"
4+
require "dev-cmd/test-bot"
5+
6+
RSpec.describe Homebrew::TestBot::BottlesFetch do
7+
describe "#fetch_bottles!" do
8+
it "accepts Utils::Bottles::Tag objects from the bottle collector" do
9+
# Regression test: bottle_specification.collector.tags returns Utils::Bottles::Tag objects,
10+
# not Symbols. The fetch_bottles! signature must accept Tag, not Symbol.
11+
fetch = described_class.new(tap: nil, git: nil, dry_run: true, fail_fast: false, verbose: false)
12+
allow(fetch).to receive(:cleanup_during!)
13+
tag = Utils::Bottles::Tag.new(system: :sequoia, arch: :arm64)
14+
15+
fetch.send(:fetch_bottles!, tag, Set["some-formula"], args: instance_double(Homebrew::Cmd::TestBotCmd::Args))
16+
17+
expect(fetch.steps.last).to be_passed
18+
expect(fetch.steps.last.command).to include("--bottle-tag=#{tag}")
19+
end
20+
end
21+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
require "test_bot"
4+
5+
RSpec.describe Homebrew::TestBot::Test do
6+
describe "#test" do
7+
it "converts Pathname arguments to strings" do
8+
# Regression test: callers like TestCleanup pass Pathname objects (e.g. repository)
9+
# as positional arguments. The `test` method must coerce them to String before
10+
# forwarding to Step.new, which expects T::Array[String].
11+
test_instance = described_class.new(dry_run: true)
12+
13+
step = test_instance.send(:test, "git", "-C", Pathname.new("/some/path"), "status")
14+
15+
expect(step.command).to eq(["git", "-C", "/some/path", "status"])
16+
expect(step).to be_passed
17+
end
18+
end
19+
end

Library/Homebrew/test_bot/bottles_fetch.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def run!(args:)
2121

2222
private
2323

24-
sig { returns(T::Hash[Symbol, T::Set[String]]) }
24+
sig { returns(T::Hash[Utils::Bottles::Tag, T::Set[String]]) }
2525
def formulae_by_tag
2626
tags = Hash.new { |hash, key| hash[key] = Set.new }
2727

@@ -41,7 +41,7 @@ def formulae_by_tag
4141
tags
4242
end
4343

44-
sig { params(tag: Symbol, formulae: T::Set[String], args: Homebrew::Cmd::TestBotCmd::Args).void }
44+
sig { params(tag: Utils::Bottles::Tag, formulae: T::Set[String], args: Homebrew::Cmd::TestBotCmd::Args).void }
4545
def fetch_bottles!(tag, formulae, args:)
4646
test_header(:BottlesFetch, method: "fetch_bottles!(#{tag})")
4747

Library/Homebrew/test_bot/test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def info_header(text)
8080

8181
sig {
8282
params(
83-
arguments: String,
83+
arguments: T.any(String, Pathname),
8484
named_args: T.nilable(T.any(String, T::Array[String])),
8585
env: T::Hash[String, String],
8686
verbose: T::Boolean,
@@ -91,7 +91,7 @@ def info_header(text)
9191
def test(*arguments, named_args: nil, env: {}, verbose: @verbose, ignore_failures: false,
9292
report_analytics: false)
9393
step = Step.new(
94-
arguments,
94+
arguments.map(&:to_s),
9595
named_args:,
9696
env:,
9797
verbose:,

Library/Homebrew/test_bot/test_formulae.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def install_formula_from_bottle!(formula_name, testing_formulae_dependents:, dry
292292

293293
install_args = []
294294
install_args += %w[--ignore-dependencies --skip-post-install] if testing_formulae_dependents
295-
test "brew", "install", *install_args, bottle_filename
295+
test "brew", "install", *install_args, bottle_filename.to_s
296296
install_step = steps.fetch(-1)
297297

298298
if !dry_run && !testing_formulae_dependents && install_step.passed?

0 commit comments

Comments
 (0)