From 4242e7ed50deda581a78504e994c504f958ba696 Mon Sep 17 00:00:00 2001 From: Chaturanga Manchanayake Date: Mon, 19 Oct 2026 11:39:30 +0530 Subject: [PATCH] Test bringing the window forward for a new file while it is still preparing Review follow-up: the earlier assertion reopened the same path, which takes the existing-tab shortcut. This one hands the running app a new file with preparation held, checks Minimized(false) and Focus are sent before release, and checks the new file is the selected tab once it is prepared. Co-Authored-By: Claude Opus 5.5 (1M context) --- crates/ui-egui/src/open_worker_tests.rs | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/crates/ui-egui/src/open_worker_tests.rs b/crates/ui-egui/src/open_worker_tests.rs index ebdd45054b..4fb705c6d8 100644 --- a/crates/ui-egui/src/open_worker_tests.rs +++ b/crates/ui-egui/src/open_worker_tests.rs @@ -670,3 +670,33 @@ fn startup_files_wait_for_absolute_link_consent_and_preparation() { assert_eq!(app.active, Some(1), "the user's approved navigation keeps focus"); let _ = std::fs::remove_file(path); } + +#[test] +#[allow(clippy::expect_used, clippy::panic, clippy::unwrap_used)] +fn a_new_file_from_the_os_brings_the_window_forward_before_it_is_prepared() { + let (mut harness, _client) = harness(); + let (gate, started, release, finished) = open_worker::prepare_gate(); + harness.state_mut().open_prepare_gate = Some(gate); + let path = std::env::temp_dir().join(format!("pdfcraft-os-open-worker-{}.pdf", std::process::id())); + std::fs::write(&path, fixture(2)).expect("write the handed-over PDF"); + let mut queue = vec![crate::OsEvent::Open(vec![path.to_string_lossy().into_owned()])]; + harness.state_mut().os_events = Some(Box::new(move || std::mem::take(&mut queue))); + harness.step(); + started.recv_timeout(Duration::from_secs(5)).expect("the handed-over PDF reached preparation"); + let commands: Vec<_> = harness.output().viewport_output.values().flat_map(|v| v.commands.clone()).collect(); + let visible = harness.state().views.len(); + // Always release before asserting: a failure must not strand the worker at the barrier. + release.send(()).expect("release the handed-over PDF"); + finished.recv_timeout(Duration::from_secs(5)).expect("the handed-over PDF prepared"); + assert!(commands.contains(&egui::ViewportCommand::Minimized(false)), "{commands:?}"); + assert!(commands.contains(&egui::ViewportCommand::Focus), "{commands:?}"); + assert_eq!(visible, 1, "the window comes forward while the file is still preparing"); + harness.step(); + let app = harness.state(); + assert_eq!(app.views.len(), 2); + let active = app.active.expect("a selected document"); + let doc = app.session.get(app.views[active].id).expect("the handed-over document"); + assert_eq!(doc.path.as_deref(), Some(path.to_string_lossy().as_ref()), "the new file is the selected tab"); + assert_eq!(doc.info.pages.len(), 2); + let _ = std::fs::remove_file(path); +}