From 967034f43e68e5cb0e69a8d013f8a5d3a599cb48 Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Wed, 3 Dec 2025 11:41:29 -0500 Subject: [PATCH] attestation: remove `T.must` This updates `ensure_executable!` return to drop nil and uses the `with_env` return so that Sorbet can infer the type. Also search all guesses for `ensure_executable!` prior to installing formula. --- Library/Homebrew/attestation.rb | 6 ++---- Library/Homebrew/extend/kernel.rb | 8 ++++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/attestation.rb b/Library/Homebrew/attestation.rb index bb1f13039b068..e03290af8ab7d 100644 --- a/Library/Homebrew/attestation.rb +++ b/Library/Homebrew/attestation.rb @@ -81,11 +81,9 @@ def self.gh_executable # NOTE: We set HOMEBREW_NO_VERIFY_ATTESTATIONS when installing `gh` itself, # to prevent a cycle during bootstrapping. This can eventually be resolved # by vendoring a pure-Ruby Sigstore verifier client. - with_env(HOMEBREW_NO_VERIFY_ATTESTATIONS: "1") do - @gh_executable = ensure_executable!("gh", reason: "verifying attestations", latest: true) + @gh_executable = with_env(HOMEBREW_NO_VERIFY_ATTESTATIONS: "1") do + ensure_executable!("gh", reason: "verifying attestations", latest: true) end - - T.must(@gh_executable) end # Prioritize installing `gh` first if it's in the formula list diff --git a/Library/Homebrew/extend/kernel.rb b/Library/Homebrew/extend/kernel.rb index fe4d0f55dd635..b408958507ca5 100644 --- a/Library/Homebrew/extend/kernel.rb +++ b/Library/Homebrew/extend/kernel.rb @@ -185,8 +185,8 @@ def redirect_stdout(file, &_block) out.close end - # Ensure the given executable is exist otherwise install the brewed version - sig { params(name: String, formula_name: T.nilable(String), reason: String, latest: T::Boolean).returns(T.nilable(Pathname)) } + # Ensure the given executable exists otherwise install the brewed version + sig { params(name: String, formula_name: T.nilable(String), reason: String, latest: T::Boolean).returns(Pathname) } def ensure_executable!(name, formula_name = nil, reason: "", latest: false) formula_name ||= name @@ -197,8 +197,8 @@ def ensure_executable!(name, formula_name = nil, reason: "", latest: false) # path where available, since the former is stable during upgrades. HOMEBREW_PREFIX/"opt/#{formula_name}/bin/#{name}", HOMEBREW_PREFIX/"bin/#{name}", - ].compact.first - return executable if executable.exist? + ].compact.find(&:exist?) + return executable if executable require "formula" Formulary.factory_stub(formula_name).ensure_installed!(reason:, latest:).opt_bin/name