diff --git a/Library/Homebrew/bundle/installer.rb b/Library/Homebrew/bundle/installer.rb index 7e9100c510d13..cc6bb37fb8fa3 100644 --- a/Library/Homebrew/bundle/installer.rb +++ b/Library/Homebrew/bundle/installer.rb @@ -15,6 +15,13 @@ class InstallableEntry < T::Struct const :cls, T.class_of(Homebrew::Bundle::PackageType) end + sig { void } + def self.reset! + Homebrew::Bundle.reset! + Homebrew::Bundle::Cask.reset! + Homebrew::Bundle::Tap.reset! + end + sig { params( entries: T::Array[Dsl::Entry], diff --git a/Library/Homebrew/test/bundle/installer_spec.rb b/Library/Homebrew/test/bundle/installer_spec.rb index c0916884a9782..2c9799a1e0f08 100644 --- a/Library/Homebrew/test/bundle/installer_spec.rb +++ b/Library/Homebrew/test/bundle/installer_spec.rb @@ -13,6 +13,7 @@ let(:cask_entry) { Homebrew::Bundle::Dsl::Entry.new(:cask, "google-chrome", cask_options) } before do + described_class.reset! allow(Homebrew::Bundle::Skipper).to receive(:skip?).and_return(false) allow(Homebrew::Bundle::Brew).to receive_messages(formula_upgradable?: false, install!: true) allow(Homebrew::Bundle::Brew).to receive_messages(formula_installed_and_up_to_date?: false, @@ -22,6 +23,18 @@ allow(Homebrew::Bundle::Tap).to receive_messages(preinstall!: true, install!: true, installed_taps: []) end + it "resets cached package state before installing" do + expect(Homebrew::Bundle::Cask).to receive(:casks).twice.and_return( + [double(to_s: "stale")], + [double(to_s: "google-chrome")], + ) + + expect(Homebrew::Bundle::Cask.cask_names).to eq(["stale"]) + + described_class.reset! + described_class.install!([cask_entry], verbose: false, force: false, quiet: true) + end + it "prefetches installable formulae and casks before installing" do allow(Homebrew::Bundle::Tap).to receive(:installed_taps).and_return(["homebrew/cask"]) allow(Homebrew::Bundle::Brew).to receive(:formula_installed_and_up_to_date?) @@ -85,8 +98,13 @@ end it "installs independent formulae in parallel with jobs > 1" do + allow(Homebrew::Bundle::Brew).to receive(:formula_bottled?).and_return(true) allow(Homebrew::Bundle::Brew).to receive(:formulae_by_full_name).with("alpha").and_return({ dependencies: [] }) allow(Homebrew::Bundle::Brew).to receive(:formulae_by_full_name).with("beta").and_return({ dependencies: [] }) + allow(Homebrew::Bundle::Brew).to receive(:recursive_dep_names).with("alpha", + include_build: false).and_return(Set.new) + allow(Homebrew::Bundle::Brew).to receive(:recursive_dep_names).with("beta", + include_build: false).and_return(Set.new) expect(Homebrew::Bundle::Brew).to receive(:install!) .with("alpha", preinstall: true, no_upgrade: false, verbose: false, force: false) .and_return(true) @@ -110,9 +128,14 @@ true end + allow(Homebrew::Bundle::Brew).to receive(:formula_bottled?).and_return(true) allow(Homebrew::Bundle::Brew).to receive(:formulae_by_full_name).with("alpha") .and_return({ dependencies: ["beta"] }) allow(Homebrew::Bundle::Brew).to receive(:formulae_by_full_name).with("beta").and_return({ dependencies: [] }) + allow(Homebrew::Bundle::Brew).to receive(:recursive_dep_names).with("alpha", + include_build: false).and_return(Set.new) + allow(Homebrew::Bundle::Brew).to receive(:recursive_dep_names).with("beta", + include_build: false).and_return(Set.new) success, failure = Homebrew::Bundle::ParallelInstaller.new( [alpha_entry, beta_entry],