From e639b77e5dcd4196a176b1927a26820e4c7494cf Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 19:30:29 -0800 Subject: [PATCH] Tests: update prompt tests wait for the offer's answer craft-update now reads the installed files for an offered release on a thread of its own, and the prompt opens at a later tick. The tests that open the prompt through an offer wait for that thread's repaint request and tick once, and the startup prompt test uses an isolated updater. --- crates/ui-egui/src/updates_ui.rs | 44 +++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/updates_ui.rs b/crates/ui-egui/src/updates_ui.rs index 41f5e68372..3dce3e2310 100644 --- a/crates/ui-egui/src/updates_ui.rs +++ b/crates/ui-egui/src/updates_ui.rs @@ -239,13 +239,45 @@ mod tests { #[cfg(not(target_arch = "wasm32"))] pub(super) fn offer(app: &mut VectorcraftApp) { app.updates_rt.updater = isolated_updater(env!("CARGO_PKG_VERSION"), "prompt"); - app.updates_rt.updater.offer(craft_update::Release { + offer_and_wait(&mut app.updates_rt.updater, release_99()); + } + + /// The release the tests offer. + #[cfg(not(target_arch = "wasm32"))] + fn release_99() -> craft_update::Release { + craft_update::Release { tag: "v99.0.0".into(), version: craft_update::parse_version("99.0.0"), name: "VectorCraft 99.0.0".into(), html_url: "https://github.com/storytold/vectorcraft/releases/tag/v99.0.0".into(), ..Default::default() + } + } + + /// Offers `release` and returns once its prompt is open. The updater reads the installed + /// files for an offer on a thread of its own, which asks the context the updater keeps for a + /// repaint after it answers; the next tick opens the prompt. The updater must not have kept + /// another context, which its thread would ask instead. A copy the launcher manages ignores + /// the offer and fails the test. + #[cfg(not(target_arch = "wasm32"))] + fn offer_and_wait(updater: &mut Updater, release: craft_update::Release) { + let ctx = egui::Context::default(); + let (answered, wait) = std::sync::mpsc::channel(); + ctx.set_request_repaint_callback(move |info| { + if info.delay.is_zero() { + let _ = answered.send(()); + } }); + // Keeps `ctx` for the offer's thread. + updater.tick(&ctx); + updater.offer(release); + // `offer` reads the launcher's choice; a managed copy starts no inspection. + assert!(updater.managed().is_none(), "the launcher manages this copy, so it ignored the offer"); + if !updater.prompt_open() { + wait.recv().unwrap(); + updater.tick(&ctx); + } + assert!(updater.prompt_open(), "the offer opened its prompt"); } /// An app with one saved document holding a selected rectangle. @@ -336,14 +368,8 @@ mod tests { fn startup_prompt_shows_and_closes() { let mut app = VectorcraftApp::new(Session::new(), Default::default()); let ctx = egui::Context::default(); - let release = craft_update::Release { - tag: "v99.0.0".into(), - version: craft_update::parse_version("99.0.0"), - name: "VectorCraft 99.0.0".into(), - html_url: "https://github.com/storytold/vectorcraft/releases/tag/v99.0.0".into(), - ..Default::default() - }; - app.updates_rt.updater.offer(release); + app.updates_rt.updater = isolated_updater(env!("CARGO_PKG_VERSION"), "startup"); + offer_and_wait(&mut app.updates_rt.updater, release_99()); let mut output = ctx.run_ui(egui::RawInput::default(), |ui| { show(&mut app, ui.ctx());