From 3f20c6848bf718e089d722e6f1b30f45169ae57c Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 12:29:26 +0000 Subject: [PATCH] Test fast optimize completion after picker --- crates/ui-egui/src/platform/pickers.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/platform/pickers.rs b/crates/ui-egui/src/platform/pickers.rs index bd3aa568dc..35cb1285f6 100644 --- a/crates/ui-egui/src/platform/pickers.rs +++ b/crates/ui-egui/src/platform/pickers.rs @@ -494,17 +494,22 @@ mod tests { } /// Reduce File Size asks first, so a heavy file can finish by itself. - #[test] - fn reduce_file_size_asks_where_to_save_before_it_compresses() { - let (mut app, dir) = reducing("first"); + fn reduce_file_size_after_pick(inline: bool) { + let (mut app, dir) = reducing(if inline { "first-inline" } else { "first" }); + app.run_inline = inline; let out = dir.join("notes (reduced).pdf"); app.pick_override = Some(vec![out.to_string_lossy().into_owned()]); app.reduce_file_size(); assert!(app.optimize_run.is_none() && app.progress_notice.is_none(), "nothing runs until the answer is in"); assert!(app.pickers.pending(), "the question is out"); app.process_picked(); - let run = app.optimize_run.as_ref().expect("the answer starts it"); - assert_eq!(run.destination.as_deref(), out.to_str()); + // A tiny optimization may finish during the initial poll, before the test observes it. + // Check the destination in either state; the saved copy is verified below in both cases. + if let Some(run) = app.optimize_run.as_ref() { + assert_eq!(run.destination.as_deref(), out.to_str()); + } else { + assert!(out.is_file(), "a completed optimization saved the chosen destination"); + } // Nothing more is asked at the end: the copy is simply there. app.pick_override = Some(vec![dir.join("not asked.pdf").to_string_lossy().into_owned()]); let start = std::time::Instant::now(); @@ -512,6 +517,7 @@ mod tests { app.poll_optimize(); std::thread::sleep(std::time::Duration::from_millis(5)); } + assert!(app.optimize_run.is_none(), "optimization finishes"); assert!(!app.pickers.pending(), "it doesn't ask again"); let written = std::fs::read(&out).unwrap_or_default(); let mut again = pdfcraft_engine::Session::new(); @@ -521,6 +527,16 @@ mod tests { let _ = std::fs::remove_dir_all(&dir); } + #[test] + fn reduce_file_size_asks_where_to_save_before_it_compresses() { + reduce_file_size_after_pick(false); + } + + #[test] + fn reduce_file_size_can_finish_before_the_first_poll_returns() { + reduce_file_size_after_pick(true); + } + #[test] fn cancelling_reduce_file_size_compresses_nothing() { let (mut app, dir) = reducing("cancel");