diff --git a/crates/ui-egui/src/platform/pickers.rs b/crates/ui-egui/src/platform/pickers.rs index bd3aa568dc..b6d2435b1a 100644 --- a/crates/ui-egui/src/platform/pickers.rs +++ b/crates/ui-egui/src/platform/pickers.rs @@ -497,21 +497,20 @@ mod tests { #[test] fn reduce_file_size_asks_where_to_save_before_it_compresses() { let (mut app, dir) = reducing("first"); + // Complete deterministically: a tiny job may finish before run_optimize returns. + app.run_inline = true; 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"); + assert!(!out.exists(), "no copy is written before the answer"); + // The first answer is already queued; any second question would use this wrong path. + let unasked = dir.join("not asked.pdf"); + app.pick_override = Some(vec![unasked.to_string_lossy().into_owned()]); app.process_picked(); - let run = app.optimize_run.as_ref().expect("the answer starts it"); - assert_eq!(run.destination.as_deref(), out.to_str()); - // 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(); - while app.optimize_run.is_some() && start.elapsed() < std::time::Duration::from_secs(30) { - app.poll_optimize(); - std::thread::sleep(std::time::Duration::from_millis(5)); - } + assert!(app.optimize_run.is_none(), "the answer runs the inline job to completion"); + assert!(!unasked.exists(), "the queued destination is retained"); 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();