@@ -226,6 +226,7 @@ class #{Formulary.class_s(name)} < Formula
226226 # upgrades with asking for user prompts
227227 it "prints formula and cask ask plans before upgrading" do
228228 cmd = klass . new ( [ "--ask" ] )
229+ download_queue = instance_double ( Homebrew ::DownloadQueue , fetch : nil , fetch_failed : false , shutdown : nil )
229230
230231 expect ( cmd ) . to receive ( :upgrade_outdated_formulae! )
231232 . with ( [ ] , dry_run : true , show_upgrade_summary : false )
@@ -241,12 +242,36 @@ class #{Formulary.class_s(name)} < Formula
241242 expect ( cmd ) . to receive ( :show_final_upgrade_summary ) . with ( dry_run : true ) . ordered
242243 expect ( Homebrew ::Install ) . to receive ( :ask ) . with ( action : "upgrade" )
243244 . ordered
245+ expect ( Homebrew ::DownloadQueue ) . to receive ( :new ) . ordered . and_return ( download_queue )
244246 expect ( cmd ) . to receive ( :upgrade_outdated_formulae! )
245- . with ( [ ] , use_prefetched : false , show_upgrade_summary : false )
247+ . with (
248+ [ ] ,
249+ prefetch_only : true ,
250+ download_queue :,
251+ prefetch_names : [ ] ,
252+ prefetch_upgrades : [ ] ,
253+ show_upgrade_summary : false ,
254+ show_downloads_heading : false ,
255+ )
256+ . ordered
257+ . and_return ( true )
258+ expect ( cmd ) . to receive ( :prefetch_outdated_casks! )
259+ . with (
260+ [ ] ,
261+ download_queue :,
262+ prefetch_names : [ ] ,
263+ prefetch_upgrades : [ ] ,
264+ show_downloads_heading : false ,
265+ )
266+ . ordered
267+ . and_return ( true )
268+ expect ( download_queue ) . to receive ( :fetch ) . ordered
269+ expect ( cmd ) . to receive ( :upgrade_outdated_formulae! )
270+ . with ( [ ] , use_prefetched : true , show_upgrade_summary : false )
246271 . ordered
247272 . and_return ( true )
248273 expect ( cmd ) . to receive ( :upgrade_outdated_casks! )
249- . with ( [ ] , skip_prefetch : false , show_upgrade_summary : false , download_queue : nil )
274+ . with ( [ ] , skip_prefetch : true , show_upgrade_summary : false , download_queue : nil )
250275 . ordered
251276 . and_return ( true )
252277 allow ( Homebrew ::Cleanup ) . to receive ( :periodic_clean! )
@@ -481,6 +506,55 @@ class #{Formulary.class_s(name)} < Formula
481506 EOS
482507 end
483508
509+ it "asks before fetching formulae and casks in the same download queue" do
510+ cmd = klass . new ( [ "--ask" ] )
511+ download_queue = instance_double ( Homebrew ::DownloadQueue , fetch : nil , fetch_failed : false , shutdown : nil )
512+ cask = instance_double (
513+ Cask ::Cask ,
514+ artifacts : [ ] ,
515+ full_name : "codex" ,
516+ installed_version : "0.117.0" ,
517+ version : "0.118.0" ,
518+ )
519+ installer = instance_double ( Cask ::Installer , enqueue_downloads : nil , source_download_requires_pre_fetch? : false )
520+
521+ allow ( cmd ) . to receive ( :upgrade_outdated_formulae! ) do |_ , dry_run : false , prefetch_only : false ,
522+ use_prefetched : false , prefetch_names : nil ,
523+ prefetch_upgrades : nil , **|
524+ if dry_run
525+ cmd . send ( :final_upgrade_summary ) . version_changes << "deno 2.7.10 -> 2.7.11"
526+ elsif prefetch_only
527+ prefetch_names &.replace ( [ "deno" ] )
528+ prefetch_upgrades &.replace ( [ "deno 2.7.10 -> 2.7.11" ] )
529+ else
530+ expect ( use_prefetched ) . to be ( true )
531+ end
532+
533+ true
534+ end
535+ allow ( Cask ::Upgrade ) . to receive ( :outdated_casks ) . and_return ( [ cask ] )
536+ allow ( Cask ::Installer ) . to receive ( :new ) . and_return ( installer )
537+ allow ( Cask ::Upgrade ) . to receive ( :upgrade_casks! ) do |*_ , **kwargs |
538+ if kwargs [ :dry_run ]
539+ kwargs [ :summary_upgrades ] << "codex 0.117.0 -> 0.118.0"
540+ else
541+ expect ( kwargs [ :skip_prefetch ] ) . to be ( true )
542+ end
543+
544+ true
545+ end
546+ allow ( Homebrew ::Cleanup ) . to receive ( :periodic_clean! )
547+ allow ( Homebrew ::Reinstall ) . to receive ( :reinstall_pkgconf_if_needed! )
548+ allow ( Homebrew . messages ) . to receive ( :display_messages )
549+
550+ expect ( Homebrew ::Install ) . to receive ( :ask ) . with ( action : "upgrade" ) . ordered
551+ expect ( Homebrew ::DownloadQueue ) . to receive ( :new ) . ordered . and_return ( download_queue )
552+ expect ( Homebrew ::Install ) . to receive ( :enqueue_cask_installers ) . ordered
553+ expect ( download_queue ) . to receive ( :fetch ) . ordered
554+
555+ cmd . run
556+ end
557+
484558 it "prefetches language cask files before fetching combined downloads" do
485559 cmd = klass . new ( [ ] )
486560 download_queue = instance_double ( Homebrew ::DownloadQueue , fetch_failed : false , shutdown : nil )
0 commit comments