WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit f9873ce

Browse files
committed
test_bot: Bump some files to Sorbet typed: strict
- There's one left (as of 2025-11-09), `test_bot/test.rb` which shows >70 errors when making `strict`, so I'm leaving that one for future us!
1 parent 6664aa5 commit f9873ce

File tree

15 files changed

+339
-112
lines changed

15 files changed

+339
-112
lines changed

Library/Homebrew/test_bot.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# typed: true # rubocop:todo Sorbet/StrictSigil
1+
# typed: strict
22
# frozen_string_literal: true
33

44
require "test_bot/step"
@@ -19,18 +19,21 @@ module Homebrew
1919
module TestBot
2020
module_function
2121

22-
GIT = "/usr/bin/git"
22+
GIT = T.let("/usr/bin/git", String)
2323

24-
HOMEBREW_TAP_REGEX = %r{^([\w-]+)/homebrew-([\w-]+)$}
24+
HOMEBREW_TAP_REGEX = T.let(%r{^([\w-]+)/homebrew-([\w-]+)$}, Regexp)
2525

26+
sig { params(args: Cmd::TestBotCmd::Args).returns(T::Boolean) }
2627
def cleanup?(args)
2728
args.cleanup? || GitHub::Actions.env_set?
2829
end
2930

31+
sig { params(args: Cmd::TestBotCmd::Args).returns(T::Boolean) }
3032
def local?(args)
3133
args.local? || GitHub::Actions.env_set?
3234
end
3335

36+
sig { params(tap: T.nilable(String)).returns(T.nilable(Tap)) }
3437
def resolve_test_tap(tap = nil)
3538
return Tap.fetch(tap) if tap
3639

@@ -52,6 +55,7 @@ def resolve_test_tap(tap = nil)
5255
end
5356
end
5457

58+
sig { params(args: Cmd::TestBotCmd::Args).void }
5559
def run!(args)
5660
$stdout.sync = true
5761
$stderr.sync = true

Library/Homebrew/test_bot/bottles_fetch.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
# typed: true # rubocop:todo Sorbet/StrictSigil
1+
# typed: strict
22
# frozen_string_literal: true
33

44
module Homebrew
55
module TestBot
66
class BottlesFetch < TestFormulae
7+
sig { returns(T::Array[String]) }
78
attr_accessor :testing_formulae
89

10+
sig { params(args: Homebrew::CLI::Args).void }
911
def run!(args:)
1012
info_header "Testing formulae:"
1113
puts testing_formulae
@@ -19,6 +21,7 @@ def run!(args:)
1921

2022
private
2123

24+
sig { params(formula_name: String, args: Homebrew::CLI::Args).void }
2225
def fetch_bottles!(formula_name, args:)
2326
test_header(:BottlesFetch, method: "fetch_bottles!(#{formula_name})")
2427

Library/Homebrew/test_bot/cleanup_after.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# typed: true # rubocop:todo Sorbet/StrictSigil
1+
# typed: strict
22
# frozen_string_literal: true
33

44
module Homebrew
55
module TestBot
66
class CleanupAfter < TestCleanup
7+
sig { params(args: Homebrew::Cmd::TestBotCmd::Args).void }
78
def run!(args:)
89
if ENV["HOMEBREW_GITHUB_ACTIONS"].present? && ENV["GITHUB_ACTIONS_HOMEBREW_SELF_HOSTED"].blank? &&
910
# don't need to do post-build cleanup unless testing test-bot itself.
@@ -27,6 +28,7 @@ def run!(args:)
2728

2829
private
2930

31+
sig { void }
3032
def pkill_if_needed
3133
pgrep = ["pgrep", "-f", HOMEBREW_CELLAR.to_s]
3234

Library/Homebrew/test_bot/cleanup_before.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
# typed: true # rubocop:todo Sorbet/StrictSigil
1+
# typed: strict
22
# frozen_string_literal: true
33

44
module Homebrew
55
module TestBot
66
class CleanupBefore < TestCleanup
7+
sig { params(args: Homebrew::Cmd::TestBotCmd::Args).void }
78
def run!(args:)
89
test_header(:CleanupBefore)
910

10-
if tap.to_s != CoreTap.instance.name && CoreTap.instance.installed?
11-
reset_if_needed(CoreTap.instance.path.to_s)
12-
end
11+
reset_if_needed(CoreTap.instance.path) if tap.to_s != CoreTap.instance.name && CoreTap.instance.installed?
1312

1413
Pathname.glob("*.bottle*.*").each(&:unlink)
1514

Library/Homebrew/test_bot/formulae.rb

Lines changed: 64 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
1-
# typed: true # rubocop:todo Sorbet/StrictSigil
1+
# typed: strict
22
# frozen_string_literal: true
33

44
module Homebrew
55
module TestBot
66
class Formulae < TestFormulae
7-
attr_writer :testing_formulae, :added_formulae, :deleted_formulae
8-
7+
sig {
8+
params(
9+
tap: T.nilable(Tap),
10+
git: String,
11+
dry_run: T::Boolean,
12+
fail_fast: T::Boolean,
13+
verbose: T::Boolean,
14+
output_paths: T::Hash[Symbol, Pathname],
15+
).void
16+
}
917
def initialize(tap:, git:, dry_run:, fail_fast:, verbose:, output_paths:)
1018
super(tap:, git:, dry_run:, fail_fast:, verbose:)
1119

12-
@built_formulae = []
13-
@bottle_checksums = {}
14-
@bottle_output_path = output_paths[:bottle]
15-
@linkage_output_path = output_paths[:linkage]
16-
@skipped_or_failed_formulae_output_path = output_paths[:skipped_or_failed_formulae]
20+
@built_formulae = T.let([], T::Array[String])
21+
@bottle_checksums = T.let({}, T::Hash[Pathname, String])
22+
@bottle_output_path = T.let(T.must(output_paths[:bottle]), Pathname)
23+
@linkage_output_path = T.let(T.must(output_paths[:linkage]), Pathname)
24+
@skipped_or_failed_formulae_output_path = T.let(
25+
T.must(output_paths[:skipped_or_failed_formulae]),
26+
Pathname,
27+
)
28+
29+
@testing_formulae = T.let([], T::Array[String])
30+
@added_formulae = T.let([], T::Array[String])
31+
@deleted_formulae = T.let([], T::Array[String])
32+
33+
@tested_formulae_count = T.let(0, Integer)
34+
@testing_formulae_count = T.let(0, Integer)
1735
end
1836

37+
sig { params(args: Cmd::TestBotCmd::Args).void }
1938
def run!(args:)
2039
test_header(:Formulae)
2140

@@ -44,7 +63,6 @@ def run!(args:)
4463
# #run! modifies `@testing_formulae`, so we need to track this separately.
4564
@testing_formulae_count = @testing_formulae.count
4665
perform_bash_cleanup = @testing_formulae.include?("bash")
47-
@tested_formulae_count = 0
4866

4967
sorted_formulae.each do |f|
5068
verify_local_bottles
@@ -87,6 +105,7 @@ def run!(args:)
87105

88106
private
89107

108+
sig { params(deps: T::Array[Dependency]).void }
90109
def tap_needed_taps(deps)
91110
deps.each { |d| d.to_formula.recursive_dependencies }
92111
rescue TapFormulaUnavailableError => e
@@ -97,13 +116,15 @@ def tap_needed_taps(deps)
97116
retry
98117
end
99118

119+
sig { void }
100120
def install_ca_certificates_if_needed
101121
return if DevelopmentTools.ca_file_handles_most_https_certificates?
102122

103123
test "brew", "install", "--formulae", "ca-certificates",
104124
env: { "HOMEBREW_DEVELOPER" => nil }
105125
end
106126

127+
sig { params(formula: Formula, formula_name: String, args: Cmd::TestBotCmd::Args).void }
107128
def setup_formulae_deps_instances(formula, formula_name, args:)
108129
conflicts = formula.conflicts
109130
formula_recursive_dependencies = formula.recursive_dependencies.map(&:to_formula)
@@ -157,8 +178,8 @@ def setup_formulae_deps_instances(formula, formula_name, args:)
157178
end
158179

159180
dependencies -= installed
160-
@unchanged_dependencies = dependencies - @testing_formulae
161-
unless @unchanged_dependencies.empty?
181+
@unchanged_dependencies = T.let(dependencies - @testing_formulae, T.nilable(T::Array[Dependency]))
182+
if @unchanged_dependencies.present?
162183
test "brew", "fetch", "--formulae", "--retry",
163184
*@unchanged_dependencies
164185
end
@@ -188,17 +209,19 @@ def setup_formulae_deps_instances(formula, formula_name, args:)
188209
Utils.safe_popen_read("brew", "deps", "--formula", "--include-test", formula_name)
189210
.split("\n")
190211
build_dependencies = dependencies - runtime_or_test_dependencies
191-
@unchanged_build_dependencies = build_dependencies - @testing_formulae
212+
@unchanged_build_dependencies = T.let(build_dependencies - @testing_formulae, T.nilable(T::Array[Dependency]))
192213
end
193214

215+
sig { params(formula: Formula).void }
194216
def cleanup_bottle_etc_var(formula)
195217
# Restore etc/var files from bottle so dependents can use them.
196218
formula.install_etc_var
197219
end
198220

221+
sig { returns(T::Boolean) }
199222
def verify_local_bottles
200223
# Portable Ruby bottles are handled differently.
201-
return if testing_portable_ruby?
224+
return false if testing_portable_ruby?
202225

203226
# Setting `HOMEBREW_DISABLE_LOAD_FORMULA` probably doesn't do anything here but let's set it just to be safe.
204227
with_env(HOMEBREW_DISABLE_LOAD_FORMULA: "1") do
@@ -245,9 +268,10 @@ def verify_local_bottles
245268
end
246269
end
247270

271+
sig { params(formula: Formula, new_formula: T::Boolean, args: Cmd::TestBotCmd::Args).void }
248272
def bottle_reinstall_formula(formula, new_formula, args:)
249273
unless build_bottle?(formula, args:)
250-
@bottle_filename = nil
274+
@bottle_filename = T.let(nil, T.nilable(Pathname))
251275
return
252276
end
253277

@@ -282,16 +306,20 @@ def bottle_reinstall_formula(formula, new_formula, args:)
282306
return
283307
end
284308

285-
@bottle_filename = Pathname.new(
286-
bottle_step.output
287-
.gsub(%r{.*(\./\S+#{HOMEBREW_BOTTLES_EXTNAME_REGEX}).*}om, '\1'),
309+
@bottle_filename = T.let(
310+
Pathname.new(
311+
bottle_step.output.gsub(%r{.*(\./\S+#{HOMEBREW_BOTTLES_EXTNAME_REGEX}).*}om, '\1'),
312+
),
313+
T.nilable(Pathname),
288314
)
289-
@bottle_json_filename = Pathname.new(
290-
@bottle_filename.to_s.gsub(/\.(\d+\.)?tar\.gz$/, ".json"),
315+
316+
@bottle_json_filename = T.let(
317+
Pathname.new(@bottle_filename.to_s.gsub(/\.(\d+\.)?tar\.gz$/, ".json")),
318+
T.nilable(Pathname),
291319
)
292320

293-
@bottle_checksums[@bottle_filename.realpath] = @bottle_filename.sha256
294-
@bottle_checksums[@bottle_json_filename.realpath] = @bottle_json_filename.sha256
321+
@bottle_checksums[T.must(@bottle_filename).realpath] = T.must(@bottle_filename).sha256
322+
@bottle_checksums[T.must(@bottle_json_filename).realpath] = T.must(@bottle_json_filename).sha256
295323

296324
@bottle_output_path.write(bottle_step.output, mode: "a")
297325

@@ -304,9 +332,9 @@ def bottle_reinstall_formula(formula, new_formula, args:)
304332

305333
@testing_formulae.delete(formula.name)
306334

307-
unless @unchanged_build_dependencies.empty?
335+
if @unchanged_build_dependencies.present?
308336
test "brew", "uninstall", "--formulae", "--force", "--ignore-dependencies", *@unchanged_build_dependencies
309-
@unchanged_dependencies -= @unchanged_build_dependencies
337+
@unchanged_dependencies -= @unchanged_build_dependencies if @unchanged_dependencies.present?
310338
end
311339

312340
verify_attestations = if formula.name == "gh"
@@ -320,6 +348,7 @@ def bottle_reinstall_formula(formula, new_formula, args:)
320348
env: { "HOMEBREW_VERIFY_ATTESTATIONS" => verify_attestations }
321349
end
322350

351+
sig { params(formula: Formula, args: Cmd::TestBotCmd::Args).returns(T::Boolean) }
323352
def build_bottle?(formula, args:)
324353
# Build and runtime dependencies must be bottled on the current OS,
325354
# but accept an older compatible bottle for test dependencies.
@@ -334,6 +363,7 @@ def build_bottle?(formula, args:)
334363
!args.build_from_source?
335364
end
336365

366+
sig { params(formula: Formula).void }
337367
def livecheck(formula)
338368
return unless formula.livecheck_defined?
339369
return if formula.livecheck.skip?
@@ -395,6 +425,7 @@ def livecheck(formula)
395425
end
396426
end
397427

428+
sig { params(formula_name: String, args: Cmd::TestBotCmd::Args).void }
398429
def formula!(formula_name, args:)
399430
cleanup_during!(@testing_formulae, args:)
400431

@@ -595,7 +626,9 @@ def formula!(formula_name, args:)
595626
if failed_linkage_or_test_messages.present?
596627
if @bottle_filename
597628
failed_dir = @bottle_filename.dirname/"failed"
598-
moved_artifacts = [@bottle_filename, @bottle_json_filename].map(&:realpath)
629+
moved_artifacts = [@bottle_filename, @bottle_json_filename].map do |path|
630+
T.must(path).realpath
631+
end
599632
failed_dir.install moved_artifacts
600633

601634
moved_artifacts.each do |old_location|
@@ -613,13 +646,14 @@ def formula!(formula_name, args:)
613646
end
614647
ensure
615648
@tested_formulae_count += 1
616-
cleanup_bottle_etc_var(formula) if cleanup?(args)
649+
cleanup_bottle_etc_var(T.must(formula)) if cleanup?(args)
617650

618651
if @unchanged_dependencies.present?
619652
test "brew", "uninstall", "--formulae", "--force", "--ignore-dependencies", *@unchanged_dependencies
620653
end
621654
end
622655

656+
sig { params(formula_name: String).void }
623657
def portable_formula!(formula_name)
624658
test_header(:Formulae, method: "portable_formula!(#{formula_name})")
625659

@@ -655,6 +689,7 @@ def portable_formula!(formula_name)
655689
test "brew", "bottle", "--skip-relocation", "--json", "--no-rebuild", formula_name
656690
end
657691

692+
sig { params(formula_name: String).void }
658693
def deleted_formula!(formula_name)
659694
test_header(:Formulae, method: "deleted_formula!(#{formula_name})")
660695

@@ -667,8 +702,11 @@ def deleted_formula!(formula_name)
667702
formula_name
668703
end
669704

705+
sig { returns(T::Boolean) }
670706
def testing_portable_ruby?
671-
tap&.core_tap? && @testing_formulae.include?("portable-ruby")
707+
return false unless tap&.core_tap?
708+
709+
@testing_formulae.include?("portable-ruby")
672710
end
673711
end
674712
end

0 commit comments

Comments
 (0)