From d0bc109882b99ae108ba481eb0d3289c160de64d Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Sun, 7 Sep 2025 11:23:48 -0700 Subject: [PATCH] Fix update-report specs --- Library/Homebrew/build.rb | 6 ++--- Library/Homebrew/cmd/update-report.rb | 25 +++++++++++++++---- Library/Homebrew/dev-cmd/tests.rb | 2 +- Library/Homebrew/extend/kernel.rb | 2 +- Library/Homebrew/standalone/sorbet.rb | 18 +++++++++++++ .../Homebrew/test/cmd/update-report_spec.rb | 10 ++++---- 6 files changed, 48 insertions(+), 15 deletions(-) diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb index 702517fd03..fee6ecd7ff 100644 --- a/Library/Homebrew/build.rb +++ b/Library/Homebrew/build.rb @@ -135,9 +135,9 @@ class Build end new_env = { - "TMPDIR" => HOMEBREW_TEMP, - "TEMP" => HOMEBREW_TEMP, - "TMP" => HOMEBREW_TEMP, + "TMPDIR" => HOMEBREW_TEMP.to_s, + "TEMP" => HOMEBREW_TEMP.to_s, + "TMP" => HOMEBREW_TEMP.to_s, } with_env(new_env) do diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index 9419a9eb2d..8d74025abf 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -427,6 +427,19 @@ require "extend/os/cmd/update-report" class Reporter include Utils::Output::Mixin + Report = T.type_alias do + { + A: T::Array[String], + AC: T::Array[String], + D: T::Array[String], + DC: T::Array[String], + M: T::Array[String], + MC: T::Array[String], + R: T::Array[[String, String]], + RC: T::Array[[String, String]], + } + end + class ReporterRevisionUnsetError < RuntimeError sig { params(var_name: String).void } def initialize(var_name) @@ -456,14 +469,14 @@ class Reporter raise ReporterRevisionUnsetError, current_revision_var if @current_revision.empty? end - @report = T.let(nil, T.nilable(T::Hash[Symbol, T::Array[String]])) + @report = T.let(nil, T.nilable(Report)) end - sig { params(auto_update: T::Boolean).returns(T::Hash[Symbol, T::Array[String]]) } + sig { params(auto_update: T::Boolean).returns(Report) } def report(auto_update: false) return @report if @report - @report = Hash.new { |h, k| h[k] = [] } + @report = T.unsafe(Hash.new { |h, k| h[k] = [] }) return @report unless updated? diff.each_line do |line| @@ -791,13 +804,15 @@ class ReporterHub sig { void } def initialize - @hash = T.let({}, T::Hash[Symbol, T::Array[String]]) + @hash = T.let({}, T::Hash[Symbol, T::Array[T.any(String, [String, String])]]) @reporters = T.let([], T::Array[Reporter]) end sig { params(key: Symbol).returns(T::Array[String]) } def select_formula_or_cask(key) - @hash.fetch(key, []) + raise "Unsupported key #{key}" unless [:A, :AC, :D, :DC, :M, :MC].include?(key) + + T.cast(@hash.fetch(key, []), T::Array[String]) end sig { params(reporter: Reporter, auto_update: T::Boolean).void } diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb index dc742876bf..3b1c1f097e 100644 --- a/Library/Homebrew/dev-cmd/tests.rb +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -119,7 +119,7 @@ module Homebrew # seeds being output when running parallel tests. seed = args.seed || rand(0xFFFF).to_i - bundle_args = ["-I", HOMEBREW_LIBRARY_PATH/"test"] + bundle_args = ["-I", (HOMEBREW_LIBRARY_PATH/"test").to_s] bundle_args += %W[ --seed #{seed} --color diff --git a/Library/Homebrew/extend/kernel.rb b/Library/Homebrew/extend/kernel.rb index c6057d276f..98c269b81f 100644 --- a/Library/Homebrew/extend/kernel.rb +++ b/Library/Homebrew/extend/kernel.rb @@ -34,7 +34,7 @@ module Kernel sig { type_parameters(:U).params(block: T.proc.returns(T.type_parameter(:U))).returns(T.type_parameter(:U)) } def with_homebrew_path(&block) - with_env(PATH: PATH.new(ORIGINAL_PATHS), &block) + with_env(PATH: PATH.new(ORIGINAL_PATHS).to_s, &block) end sig { diff --git a/Library/Homebrew/standalone/sorbet.rb b/Library/Homebrew/standalone/sorbet.rb index 406582618d..e810fee45c 100644 --- a/Library/Homebrew/standalone/sorbet.rb +++ b/Library/Homebrew/standalone/sorbet.rb @@ -47,3 +47,21 @@ else T::Configuration.call_validation_error_handler = ->(signature, opts) {} T::Configuration.inline_type_error_handler = ->(error, opts) {} end + +module T + module Types + class TypedArray < TypedEnumerable + # overrides Base + def valid?(obj) + recursively_valid?(obj) + end + end + + class TypedHash < TypedEnumerable + # overrides Base + def valid?(obj) + recursively_valid?(obj) + end + end + end +end diff --git a/Library/Homebrew/test/cmd/update-report_spec.rb b/Library/Homebrew/test/cmd/update-report_spec.rb index 50363220c1..e6daf6433d 100644 --- a/Library/Homebrew/test/cmd/update-report_spec.rb +++ b/Library/Homebrew/test/cmd/update-report_spec.rb @@ -83,7 +83,7 @@ RSpec.describe Homebrew::Cmd::UpdateReport do expect(hub.select_formula_or_cask(:A)).to be_empty expect(hub.select_formula_or_cask(:D)).to be_empty - expect(hub.select_formula_or_cask(:R)).to eq([["cv", "progress"]]) + expect(hub.instance_variable_get(:@hash).fetch(:R, [])).to eq([["cv", "progress"]]) end context "when updating a Tap other than the core Tap" do @@ -102,7 +102,7 @@ RSpec.describe Homebrew::Cmd::UpdateReport do expect(hub.select_formula_or_cask(:A)).to be_empty expect(hub.select_formula_or_cask(:D)).to be_empty - expect(hub.select_formula_or_cask(:R)).to be_empty + expect(hub.instance_variable_get(:@hash).fetch(:R, [])).to be_empty end specify "with renamed Formula and restructured Tap" do @@ -111,7 +111,7 @@ RSpec.describe Homebrew::Cmd::UpdateReport do expect(hub.select_formula_or_cask(:A)).to be_empty expect(hub.select_formula_or_cask(:D)).to be_empty - expect(hub.select_formula_or_cask(:R)).to eq([%w[foo/bar/xchat foo/bar/xchat2]]) + expect(hub.instance_variable_get(:@hash).fetch(:R, [])).to eq([%w[foo/bar/xchat foo/bar/xchat2]]) end specify "with simulated 'homebrew/php' restructuring" do @@ -119,7 +119,7 @@ RSpec.describe Homebrew::Cmd::UpdateReport do expect(hub.select_formula_or_cask(:A)).to be_empty expect(hub.select_formula_or_cask(:D)).to be_empty - expect(hub.select_formula_or_cask(:R)).to be_empty + expect(hub.instance_variable_get(:@hash).fetch(:R, [])).to be_empty end specify "with Formula changes" do @@ -127,7 +127,7 @@ RSpec.describe Homebrew::Cmd::UpdateReport do expect(hub.select_formula_or_cask(:A)).to eq(%w[foo/bar/lua]) expect(hub.select_formula_or_cask(:M)).to eq(%w[foo/bar/git]) - expect(hub.select_formula_or_cask(:D)).to be_empty + expect(hub.instance_variable_get(:@hash).fetch(:R, [])).to be_empty end end end