From 487bd1bad7e7ab0bcfe95deb97dd3d01f5f06e11 Mon Sep 17 00:00:00 2001 From: yoriswind Date: Mon, 16 Nov 2026 22:41:47 -0800 Subject: [PATCH 01/12] test(ui): wait for stale thumbnail and Camera Raw workers --- crates/ui-egui/src/dialogs/camera_raw_ui.rs | 32 ++++++---- .../src/dialogs/camera_raw_ui/tests.rs | 20 ++++++- crates/ui-egui/src/home_recent_ui.rs | 58 +++++++++++++------ 3 files changed, 80 insertions(+), 30 deletions(-) diff --git a/crates/ui-egui/src/dialogs/camera_raw_ui.rs b/crates/ui-egui/src/dialogs/camera_raw_ui.rs index acfdd6327c6..d20b98f2414 100644 --- a/crates/ui-egui/src/dialogs/camera_raw_ui.rs +++ b/crates/ui-egui/src/dialogs/camera_raw_ui.rs @@ -50,6 +50,8 @@ pub use open::{ }; use open::{Target, non_defaults}; use proxy::{ProxyFrame, ProxyJob}; +#[cfg(not(target_arch = "wasm32"))] +type ProxyReceiver = std::sync::mpsc::Receiver>; pub use sidecar::sidecar_path; #[cfg(test)] use sidecar::{existing_sidecar_is_ours, read_bounded}; @@ -236,6 +238,22 @@ impl CameraRawDialog { self.preview_revision = self.preview_revision.saturating_add(1); } + /// Starts the same proxy worker used by the dialog, returning its completion handle. + #[cfg(not(target_arch = "wasm32"))] + fn spawn_proxy_worker(&self, ctx: &egui::Context) -> std::io::Result<(ProxyReceiver, std::thread::JoinHandle<()>)> { + let job = self.proxy_job(); + let (tx, rx) = std::sync::mpsc::channel::>(); + let repaint = ctx.clone(); + let worker = std::thread::Builder::new().name("camera-raw-proxy".into()).spawn(move || { + let frame = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| job.run())).map_err(|_| "RAW Develop preview failed".to_string()); + // The dialog may have closed or rendered on its own meanwhile; then nobody listens. + if tx.send(frame).is_ok() { + repaint.request_repaint(); + } + })?; + Ok((rx, worker)) + } + /// Starts developing the proxy with the current settings on a worker, unless one is already /// running: then [`Self::poll_render`] starts the next one with the settings of that moment. /// A slider drag never waits for the develop, which takes hundreds of milliseconds with @@ -246,18 +264,8 @@ impl CameraRawDialog { } #[cfg(not(target_arch = "wasm32"))] { - let job = self.proxy_job(); - let (tx, rx) = std::sync::mpsc::channel::>(); - let repaint = ctx.clone(); - let spawned = std::thread::Builder::new().name("camera-raw-proxy".into()).spawn(move || { - let frame = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| job.run())).map_err(|_| "RAW Develop preview failed".to_string()); - // The dialog may have closed or rendered on its own meanwhile; then nobody listens. - if tx.send(frame).is_ok() { - repaint.request_repaint(); - } - }); - match spawned { - Ok(_) => { + match self.spawn_proxy_worker(ctx) { + Ok((rx, _worker)) => { self.pending = Some(rx); self.dirty = false; } diff --git a/crates/ui-egui/src/dialogs/camera_raw_ui/tests.rs b/crates/ui-egui/src/dialogs/camera_raw_ui/tests.rs index 93926c81c0f..75c59756912 100644 --- a/crates/ui-egui/src/dialogs/camera_raw_ui/tests.rs +++ b/crates/ui-egui/src/dialogs/camera_raw_ui/tests.rs @@ -251,13 +251,31 @@ fn a_stale_worker_never_replaces_a_newer_synchronous_render() { let d = app.camera_raw.as_mut().unwrap(); d.params.highlights = -80.0; d.dirty = true; + #[cfg(not(target_arch = "wasm32"))] + let worker = { + let (rx, worker) = d.spawn_proxy_worker(&ctx).unwrap(); + d.pending = Some(rx); + d.dirty = false; + worker + }; + #[cfg(target_arch = "wasm32")] d.request_render(&ctx); assert!(d.render_pending()); let reply = menu(&mut app, &ctx, "filter.cameraRaw", &json!({"ui": {"set": {"highlights": 0, "exposure": -1.0}}})).unwrap().unwrap(); assert_eq!(reply["previewPending"], false); let d = app.camera_raw.as_mut().unwrap(); let (revision, shown) = (d.preview_revision, d.processed.clone()); - std::thread::sleep(std::time::Duration::from_millis(200)); + #[cfg(not(target_arch = "wasm32"))] + { + // The synchronous render drops its receiver, not the detached worker. Wait + // for that worker itself before checking that its frame stayed discarded. + let start = std::time::Instant::now(); + while !worker.is_finished() && start.elapsed() < std::time::Duration::from_secs(10) { + std::thread::sleep(std::time::Duration::from_millis(5)); + } + assert!(worker.is_finished(), "the stale RAW Develop preview worker never finished"); + worker.join().unwrap(); + } d.poll_render(&ctx).unwrap(); assert_eq!((d.preview_revision, &d.processed), (revision, &shown)); d.render(&ctx); diff --git a/crates/ui-egui/src/home_recent_ui.rs b/crates/ui-egui/src/home_recent_ui.rs index e8f25a1e724..c67a3332095 100644 --- a/crates/ui-egui/src/home_recent_ui.rs +++ b/crates/ui-egui/src/home_recent_ui.rs @@ -340,6 +340,27 @@ fn drain_pending_thumbnails(app: &PhotocraftApp, ctx: &egui::Context, opts: Text } } +/// Starts the disk worker; callers may retain its handle to observe completion. +#[cfg(not(target_arch = "wasm32"))] +fn spawn_thumbnail_worker( + cache_arc: std::sync::Arc>, + ctx_clone: egui::Context, + path_str: String, + req_id: u64, + key_clone: CacheKey, + file_len: u64, +) -> std::thread::JoinHandle<()> { + std::thread::spawn(move || { + let opt_img = load_thumbnail_catching_panic(|| load_thumbnail_image_bounded(&path_str, file_len)); + let mut cache = cache_arc.lock().unwrap_or_else(std::sync::PoisonError::into_inner); + // Only enqueue if this request generation is still the active one + if cache.in_flight.get(&path_str).copied() == Some(req_id) { + cache.pending.push((path_str, req_id, key_clone, opt_img)); + ctx_clone.request_repaint(); + } + }) +} + /// Retrieve, lazily load, or regenerate the preview texture for `path`. /// /// If `path` is currently open in `app.session`, the thumbnail is rendered from @@ -476,15 +497,7 @@ pub(crate) fn get_or_load_thumbnail(app: &PhotocraftApp, ctx: &egui::Context, pa let path_str = path.to_string(); let key_clone = current_key; let file_len = meta.len(); - std::thread::spawn(move || { - let opt_img = load_thumbnail_catching_panic(|| load_thumbnail_image_bounded(&path_str, file_len)); - let mut cache = cache_arc.lock().unwrap_or_else(std::sync::PoisonError::into_inner); - // Only enqueue if this request generation is still the active one - if cache.in_flight.get(&path_str).copied() == Some(req_id) { - cache.pending.push((path_str, req_id, key_clone, opt_img)); - ctx_clone.request_repaint(); - } - }); + let _ = spawn_thumbnail_worker(cache_arc, ctx_clone, path_str, req_id, key_clone, file_len); cached_entry.and_then(|e| e.texture) } else { let opt_img = load_thumbnail_image_bounded(path, meta.len()); @@ -1414,14 +1427,25 @@ mod tests { app.background_jobs = true; let ctx = egui::Context::default(); - let tex1 = get_or_load_thumbnail(&app, &ctx, &path_str); - assert!(tex1.is_none()); - - // Immediately invalidate while thread is in flight - app.thumbnail_cache.lock().unwrap().invalidate(&path_str); - - // Wait a short time for thread to complete - std::thread::sleep(std::time::Duration::from_millis(50)); + let meta = std::fs::metadata(&file_path).unwrap(); + let key = CacheKey::DiskFile { modified: meta.modified().ok(), len: meta.len() }; + let worker = { + // Hold the publication lock until invalidation, so even a fast decode must + // check its generation after this request has been removed. + let mut cache = app.thumbnail_cache.lock().unwrap(); + let req_id = cache.next_req_id; + cache.next_req_id = cache.next_req_id.wrapping_add(1); + cache.in_flight.insert(path_str.clone(), req_id); + let worker = spawn_thumbnail_worker(std::sync::Arc::clone(&app.thumbnail_cache), ctx.clone(), path_str.clone(), req_id, key, meta.len()); + cache.invalidate(&path_str); + worker + }; + let start = std::time::Instant::now(); + while !worker.is_finished() && start.elapsed() < std::time::Duration::from_secs(2) { + std::thread::sleep(std::time::Duration::from_millis(5)); + } + assert!(worker.is_finished(), "the invalidated thumbnail worker never finished"); + worker.join().unwrap(); // The background thread should have detected it was removed from in_flight and discarded its result let cache = app.thumbnail_cache.lock().unwrap(); From 2392112af8490755c081c96fda1edd79791a2eb1 Mon Sep 17 00:00:00 2001 From: ljkx <177671075+ljkx@users.noreply.github.com> Date: Tue, 17 Nov 2026 09:34:52 +0100 Subject: [PATCH 02/12] Tests: font commit tests drop the mirrored patterns and the accept x commit grid (#15368) --- .../src/tools/type_tool/font_commit_tests.rs | 134 +++++++++--------- 1 file changed, 64 insertions(+), 70 deletions(-) diff --git a/crates/ui-egui/src/tools/type_tool/font_commit_tests.rs b/crates/ui-egui/src/tools/type_tool/font_commit_tests.rs index bb80791b790..69ebd659443 100644 --- a/crates/ui-egui/src/tools/type_tool/font_commit_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/font_commit_tests.rs @@ -167,25 +167,22 @@ fn commit(h: &mut Harness<'_, Probe>, method: &str) { } } +// A pattern picks the text's styles: 0 is all `FONTS[0]`, 2 is `FONTS[0]` with `FONTS[1]` on +// [2, 4]. Patterns 1 and 3 would be the same with the two fonts swapped, and every case already +// chooses each font as the target, so they would reach nothing new. #[test] fn selected_fonts_commit_pattern_0() { selected_fonts_commit_cases(0); } -#[test] -fn selected_fonts_commit_pattern_1() { - selected_fonts_commit_cases(1); -} - #[test] fn selected_fonts_commit_pattern_2() { selected_fonts_commit_cases(2); } -#[test] -fn selected_fonts_commit_pattern_3() { - selected_fonts_commit_cases(3); -} +/// Each way to accept a font, committed with the checkmark, and each way to commit after an +/// Enter: accepting and committing are separate steps, so their full grid repeats both. +const ACCEPT_THEN_COMMIT: [(&str, &str); 4] = [("enter", "checkmark"), ("click", "checkmark"), ("arrow-enter", "checkmark"), ("enter", "outside")]; fn selected_fonts_commit_cases(pattern: usize) { let mut cases = 0; @@ -193,79 +190,76 @@ fn selected_fonts_commit_cases(pattern: usize) { for character in [false, true] { for range in [[0, 2], [2, 4], [4, 6], [0, 6], [4, 2], [1, 5]] { for target in FONTS { - for accept in ["enter", "click", "arrow-enter"] { - for method in ["checkmark", "outside"] { - let label = (new, pattern, character, range, target, accept, method); - let (mut h, id) = fixture(new, pattern, character, "abcdef"); - select(&mut h, range); - h.run(); - let mut expected = families(&saved(&h, id)); - for font in &mut expected[range[0].min(range[1])..range[0].max(range[1])] { - *font = target.into(); - } - choose(&mut h, target, accept); - let applied = saved(&h, id); - assert_eq!(families(&applied), expected, "{label:?}"); - assert_eq!(fields(&h)[0].as_deref(), Some(target), "selected font caption: {label:?}"); - let pixels = layer(&h.state().app.session.active().unwrap().doc, id).cache.clone(); - commit(&mut h, method); - assert!(h.state().app.ui.text_edit.is_none(), "{label:?}"); - assert_eq!(saved(&h, id), applied, "{label:?}"); - assert_eq!(layer(&h.state().app.session.active().unwrap().doc, id).cache, pixels, "{label:?}"); - let uniform = expected.iter().all(|f| f == &expected[0]); - assert_eq!( - fields(&h)[0].clone().unwrap_or_default(), - if uniform { expected[0].clone() } else { String::new() }, - "mixed caption after commit: {label:?}" - ); - super::edit_active(&mut h.state_mut().app).unwrap(); - select(&mut h, range); - h.run(); - assert_eq!(fields(&h)[0].as_deref(), Some(target), "reselected caption: {label:?}"); - cases += 1; + for (accept, method) in ACCEPT_THEN_COMMIT { + let label = (new, pattern, character, range, target, accept, method); + let (mut h, id) = fixture(new, pattern, character, "abcdef"); + select(&mut h, range); + h.run(); + let mut expected = families(&saved(&h, id)); + for font in &mut expected[range[0].min(range[1])..range[0].max(range[1])] { + *font = target.into(); } + choose(&mut h, target, accept); + let applied = saved(&h, id); + assert_eq!(families(&applied), expected, "{label:?}"); + assert_eq!(fields(&h)[0].as_deref(), Some(target), "selected font caption: {label:?}"); + let pixels = layer(&h.state().app.session.active().unwrap().doc, id).cache.clone(); + commit(&mut h, method); + assert!(h.state().app.ui.text_edit.is_none(), "{label:?}"); + assert_eq!(saved(&h, id), applied, "{label:?}"); + assert_eq!(layer(&h.state().app.session.active().unwrap().doc, id).cache, pixels, "{label:?}"); + let uniform = expected.iter().all(|f| f == &expected[0]); + assert_eq!( + fields(&h)[0].clone().unwrap_or_default(), + if uniform { expected[0].clone() } else { String::new() }, + "mixed caption after commit: {label:?}" + ); + super::edit_active(&mut h.state_mut().app).unwrap(); + select(&mut h, range); + h.run(); + assert_eq!(fields(&h)[0].as_deref(), Some(target), "reselected caption: {label:?}"); + cases += 1; } } } } } - assert_eq!(cases, 288); + assert_eq!(cases, 192); } #[test] fn caret_font_choices_style_only_subsequent_typing_including_ime() { for new in [false, true] { for character in [false, true] { - for original in 0..2 { - for text in ["abcdef", "AéB👩‍💻", "ab\ncdé"] { - let n = text.chars().count(); - for caret in [0, n / 2, n] { - for accept in ["enter", "click", "arrow-enter"] { - let (mut h, id) = fixture(new, original, character, text); - select(&mut h, [caret, caret]); - h.run(); - let before = saved(&h, id); - let steps = h.state().app.session.active().unwrap().history.entries().len(); - let font = FONTS[1 - original]; - choose(&mut h, font, accept); - assert_eq!(saved(&h, id), before, "a font choice at a caret never restyles existing characters"); - assert_eq!(h.state().app.session.active().unwrap().history.entries().len(), steps); - assert_eq!(fields(&h)[0].as_deref(), Some(font)); - crate::type_font_preview::set(&mut h.state_mut().app, font.into()); - assert!(crate::type_font_preview::display_doc(&mut h.state_mut().app, 0).is_none()); - // Multiple preedit replacements and final commit keep the pending font. - super::ime_update(&mut h.state_mut().app, "é", false); - super::ime_update(&mut h.state_mut().app, "éX", true); - super::insert(&mut h.state_mut().app, "Z"); - let mut expected = families(&before); - expected.splice(caret..caret, std::iter::repeat_n(font.to_string(), 3)); - assert_eq!(families(&saved(&h, id)), expected); - let typed = saved(&h, id); - commit(&mut h, "checkmark"); - assert_eq!(saved(&h, id), typed); - assert!(h.state().app.ui.type_insertion_style.is_none()); - } - } + // One original font and one acceptance: the original only decides which of the two + // fonts is chosen, and `selected_fonts_commit_cases` covers every acceptance. + let (original, accept) = (0, "enter"); + for text in ["abcdef", "AéB👩‍💻", "ab\ncdé"] { + let n = text.chars().count(); + for caret in [0, n / 2, n] { + let (mut h, id) = fixture(new, original, character, text); + select(&mut h, [caret, caret]); + h.run(); + let before = saved(&h, id); + let steps = h.state().app.session.active().unwrap().history.entries().len(); + let font = FONTS[1 - original]; + choose(&mut h, font, accept); + assert_eq!(saved(&h, id), before, "a font choice at a caret never restyles existing characters"); + assert_eq!(h.state().app.session.active().unwrap().history.entries().len(), steps); + assert_eq!(fields(&h)[0].as_deref(), Some(font)); + crate::type_font_preview::set(&mut h.state_mut().app, font.into()); + assert!(crate::type_font_preview::display_doc(&mut h.state_mut().app, 0).is_none()); + // Multiple preedit replacements and final commit keep the pending font. + super::ime_update(&mut h.state_mut().app, "é", false); + super::ime_update(&mut h.state_mut().app, "éX", true); + super::insert(&mut h.state_mut().app, "Z"); + let mut expected = families(&before); + expected.splice(caret..caret, std::iter::repeat_n(font.to_string(), 3)); + assert_eq!(families(&saved(&h, id)), expected); + let typed = saved(&h, id); + commit(&mut h, "checkmark"); + assert_eq!(saved(&h, id), typed); + assert!(h.state().app.ui.type_insertion_style.is_none()); } } } From a7574415bb46f8f203eee0d1122dc2312fb6d106 Mon Sep 17 00:00:00 2001 From: yoriswind Date: Tue, 17 Nov 2026 19:10:26 -0800 Subject: [PATCH 03/12] Format the current-framework regression repair --- .../src/dialogs/camera_raw_ui/tests.rs | 22 ++++++++++++++----- crates/ui-egui/src/home_recent_ui.rs | 13 +++++------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/crates/ui-egui/src/dialogs/camera_raw_ui/tests.rs b/crates/ui-egui/src/dialogs/camera_raw_ui/tests.rs index 921f1e65a85..78dea66ce50 100644 --- a/crates/ui-egui/src/dialogs/camera_raw_ui/tests.rs +++ b/crates/ui-egui/src/dialogs/camera_raw_ui/tests.rs @@ -193,7 +193,6 @@ fn worker_preview_matches_the_synchronous_render_and_ends_on_the_latest_settings ); } - /// An old job held after its real cancellation check. Drop always releases it and drains its queue, including on /// an assertion failure; all waits have bounds. This never substitutes for the production menu or develop job. #[cfg(not(target_arch = "wasm32"))] @@ -233,7 +232,8 @@ fn hold_old_preview(app: &PhotocraftApp) -> (HeldPreview, std::sync::mpsc::Recei let _ = arrived.send(order); let (released, wake) = &*release; let released = released.lock().unwrap_or_else(std::sync::PoisonError::into_inner); - let (released, _) = wake.wait_timeout_while(released, std::time::Duration::from_secs(30), |released| !*released).unwrap_or_else(std::sync::PoisonError::into_inner); + let (released, _) = + wake.wait_timeout_while(released, std::time::Duration::from_secs(30), |released| !*released).unwrap_or_else(std::sync::PoisonError::into_inner); if !*released { timed_out.store(true, std::sync::atomic::Ordering::Relaxed); } @@ -247,7 +247,11 @@ fn wait_for_newer_preview(app: &mut PhotocraftApp, order: u64) { let deadline = std::time::Instant::now() + std::time::Duration::from_secs(10); loop { frame(app); - if session(app).source.developed().is_some_and(|result| result.revision > order && result.settings.exposure == -1.0 && result.settings.highlights == 0.0) { + if session(app) + .source + .developed() + .is_some_and(|result| result.revision > order && result.settings.exposure == -1.0 && result.settings.highlights == 0.0) + { return; } assert!(std::time::Instant::now() < deadline, "the real newer request must publish while the older job is held"); @@ -279,9 +283,17 @@ fn a_stale_worker_never_replaces_a_newer_synchronous_render() { frame(&mut app); let later = describe(&app); assert_eq!(later["previewPending"], false); - assert_eq!((&later["previewRevision"], &later["histogram"]), (&landed["previewRevision"], &landed["histogram"]), "the old result reached publication last and did not replace the newer frame"); + assert_eq!( + (&later["previewRevision"], &later["histogram"]), + (&landed["previewRevision"], &landed["histogram"]), + "the old result reached publication last and did not replace the newer frame" + ); assert_eq!(processed(&app), shown_pixels, "the old result did not replace the displayed proxy pixels"); - assert_eq!(session(&app).source.proxy_job(&shown(&app)).run().px, shown_pixels, "the pixels still match a synchronous develop of the control channel's settings"); + assert_eq!( + session(&app).source.proxy_job(&shown(&app)).run().px, + shown_pixels, + "the pixels still match a synchronous develop of the control channel's settings" + ); assert_eq!(landed["histogram"], single_develop_histogram(json!({"exposure": -1.0})), "the frame shown is the one for the latest settings"); } #[cfg(target_arch = "wasm32")] diff --git a/crates/ui-egui/src/home_recent_ui.rs b/crates/ui-egui/src/home_recent_ui.rs index d6d101a4c55..b2fd2fb533c 100644 --- a/crates/ui-egui/src/home_recent_ui.rs +++ b/crates/ui-egui/src/home_recent_ui.rs @@ -486,13 +486,7 @@ mod tests { let ctx = app.ctx().clone(); let mut state = None; frames.frame(Vec::new(), |_| { - state = Some(thumbnails(&ctx).state( - &ctx, - &source(app, &ctx), - key, - &ThumbRequest::for_cell(64.0, 1.0), - craft::ui::primitives::Priority::VISIBLE, - )); + state = Some(thumbnails(&ctx).state(&ctx, &source(app, &ctx), key, &ThumbRequest::for_cell(64.0, 1.0), craft::ui::primitives::Priority::VISIBLE)); }); state.expect("the Home thumbnail caller ran") } @@ -564,7 +558,10 @@ mod tests { std::fs::write(&path_string, flat_png([20, 100, 60, 255])).unwrap(); // The former picture may be a stand-in, but it cannot satisfy the invalidated revision as Ready. - assert!(matches!(recent_thumbnail_pass(&app, &mut frames, &key), craft::ui::primitives::TextureState::Loading { .. }), "the completed old result is not current"); + assert!( + matches!(recent_thumbnail_pass(&app, &mut frames, &key), craft::ui::primitives::TextureState::Loading { .. }), + "the completed old result is not current" + ); assert_eq!(jobs.waiting(), 1, "the production source requests a replacement decoder"); assert!(jobs.run_next(), "the replacement decoder completes"); let state = recent_thumbnail_pass(&app, &mut frames, &key); From 02220e053db220d16e1fea0c8dd79afcf821fcc3 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 16:08:41 +0000 Subject: [PATCH 04/12] Layer folder export tests: the planted-link test and its helpers build on Unix only (cherry picked from commit d8591f9d58507888fb7b3019e16a4b0d24c5aa33) --- .../layer_folder_export_tests.rs | 125 +++++++++--------- 1 file changed, 65 insertions(+), 60 deletions(-) diff --git a/crates/ui-egui/src/dialogs/export_dialog/layer_folder_export_tests.rs b/crates/ui-egui/src/dialogs/export_dialog/layer_folder_export_tests.rs index 3ed7cf24bdf..62517df4585 100644 --- a/crates/ui-egui/src/dialogs/export_dialog/layer_folder_export_tests.rs +++ b/crates/ui-egui/src/dialogs/export_dialog/layer_folder_export_tests.rs @@ -4,11 +4,7 @@ //! One file keeps the save dialog with the layer's name. use super::*; -use craft::host::{Picked, ScriptedFiles}; use photocraft_doc::{Color, Size}; -use std::{cell::RefCell, rc::Rc}; - -type Written = Rc>>; fn named(name: &str) -> Document { Document::with_background(name, Size::new(4, 4), ColorMode::Rgb, photocraft_doc::SampleType::U8, Color::WHITE) @@ -39,61 +35,70 @@ fn names_keep_spaces_replace_illegal_characters_and_number_duplicates_downwards( assert_eq!(layer_file_names(&docs, "jpg"), ["Dup-2.jpg", "Dup-1.jpg", "Dup.jpg"]); } -/// A document with filled layers `a/b:c*?`, `Dup` and `Dup` (bottom to top), plus an empty layer. Its file dialogs -/// stay open until the test answers them. -fn app() -> (PhotocraftApp, Vec, LayerId, Written, Arc) { - let written = Written::default(); - let capture = written.clone(); - let files = Arc::new(ScriptedFiles::held()); - let services = crate::Services { - files: Some(files.clone()), - export: Some(Box::new(|doc, path, settings| { - photocraft_io::export(doc, path, &settings.io_options()).map(|r| (r.bytes, r.warnings)).map_err(|e| e.to_string()) - })), - write: Some(Box::new(move |path, _| { - capture.borrow_mut().push(path.to_string()); - Ok(()) - })), - ..Default::default() - }; - let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), services); - app.run("file.new", json!({"width": 40, "height": 30})).unwrap(); - app.run("layer.new.layer", json!({"name": "Blank"})).unwrap(); - let empty = app.session.active().unwrap().active_layer.unwrap(); - let mut ids = Vec::new(); - for (name, color) in [("a/b:c*?", "#ff0000"), ("Dup", "#00ff00"), ("Dup", "#0000ff")] { - app.run("layer.new.layer", json!({"name": name})).unwrap(); - app.run("paint.bucket", json!({"x": 0, "y": 0, "color": color})).unwrap(); - ids.push(app.session.active().unwrap().active_layer.unwrap()); - } - (app, ids, empty, written, files) -} - -/// Layer › Export As on `ids` as PNG: Export asks for a destination, which the user answers with `path`. Returns the -/// destination request. -fn export_layers_to(app: &mut PhotocraftApp, files: &ScriptedFiles, ids: &[LayerId], path: &std::path::Path) -> craft::host::PickRequest { - let ctx = app.ctx().clone(); - let id = open_layers(app, ids).unwrap(); - app.framework.dialogs.set_json_field(&ctx, id, "format", json!("png")).unwrap(); - crate::dialogs::confirm(app, &ctx, id).unwrap(); - let request = files.requests().last().cloned().expect("Export asks for a destination"); - files.answer(Picked::Paths(vec![path.to_path_buf()])).expect("the destination dialog is open"); - app.poll_file_dialog(); - // The dialog's next pass takes the answered path and exports. - crate::dialogs::confirm(app, &ctx, id).unwrap(); - request -} - +/// A planted link at the destination: the test needs Unix symlinks, and so do its helpers. #[cfg(unix)] -#[test] -fn a_planted_link_is_replaced_not_followed() { - let guard = tempfile::tempdir().unwrap(); - let dir = guard.path().to_path_buf(); - let link = dir.join("Dup.png"); - std::os::unix::fs::symlink(dir.join("victim"), &link).unwrap(); - let (mut app, ids, _, written, files) = app(); - export_layers_to(&mut app, &files, &ids, &dir); - assert!(link.symlink_metadata().is_err(), "the link is gone before the write"); - assert!(written.borrow().contains(&link.to_string_lossy().into_owned())); - assert!(!dir.join("victim").exists(), "nothing was written through the link"); +mod planted_link { + use super::*; + use craft::host::{Picked, ScriptedFiles}; + use std::{cell::RefCell, rc::Rc}; + + type Written = Rc>>; + + /// A document with filled layers `a/b:c*?`, `Dup` and `Dup` (bottom to top), plus an empty layer. Its file dialogs + /// stay open until the test answers them. + fn app() -> (PhotocraftApp, Vec, LayerId, Written, Arc) { + let written = Written::default(); + let capture = written.clone(); + let files = Arc::new(ScriptedFiles::held()); + let services = crate::Services { + files: Some(files.clone()), + export: Some(Box::new(|doc, path, settings| { + photocraft_io::export(doc, path, &settings.io_options()).map(|r| (r.bytes, r.warnings)).map_err(|e| e.to_string()) + })), + write: Some(Box::new(move |path, _| { + capture.borrow_mut().push(path.to_string()); + Ok(()) + })), + ..Default::default() + }; + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), services); + app.run("file.new", json!({"width": 40, "height": 30})).unwrap(); + app.run("layer.new.layer", json!({"name": "Blank"})).unwrap(); + let empty = app.session.active().unwrap().active_layer.unwrap(); + let mut ids = Vec::new(); + for (name, color) in [("a/b:c*?", "#ff0000"), ("Dup", "#00ff00"), ("Dup", "#0000ff")] { + app.run("layer.new.layer", json!({"name": name})).unwrap(); + app.run("paint.bucket", json!({"x": 0, "y": 0, "color": color})).unwrap(); + ids.push(app.session.active().unwrap().active_layer.unwrap()); + } + (app, ids, empty, written, files) + } + + /// Layer › Export As on `ids` as PNG: Export asks for a destination, which the user answers with `path`. Returns the + /// destination request. + fn export_layers_to(app: &mut PhotocraftApp, files: &ScriptedFiles, ids: &[LayerId], path: &std::path::Path) -> craft::host::PickRequest { + let ctx = app.ctx().clone(); + let id = open_layers(app, ids).unwrap(); + app.framework.dialogs.set_json_field(&ctx, id, "format", json!("png")).unwrap(); + crate::dialogs::confirm(app, &ctx, id).unwrap(); + let request = files.requests().last().cloned().expect("Export asks for a destination"); + files.answer(Picked::Paths(vec![path.to_path_buf()])).expect("the destination dialog is open"); + app.poll_file_dialog(); + // The dialog's next pass takes the answered path and exports. + crate::dialogs::confirm(app, &ctx, id).unwrap(); + request + } + + #[test] + fn a_planted_link_is_replaced_not_followed() { + let guard = tempfile::tempdir().unwrap(); + let dir = guard.path().to_path_buf(); + let link = dir.join("Dup.png"); + std::os::unix::fs::symlink(dir.join("victim"), &link).unwrap(); + let (mut app, ids, _, written, files) = app(); + export_layers_to(&mut app, &files, &ids, &dir); + assert!(link.symlink_metadata().is_err(), "the link is gone before the write"); + assert!(written.borrow().contains(&link.to_string_lossy().into_owned())); + assert!(!dir.join("victim").exists(), "nothing was written through the link"); + } } From 4655db8f8c17b6d5b5b933820f2a171b7cab2191 Mon Sep 17 00:00:00 2001 From: yoriswind Date: Tue, 17 Nov 2026 21:08:05 -0800 Subject: [PATCH 05/12] Handle recorded thumbnail texture updates in headless tests Clear the owned texture deltas after checking every decoded pixel. The headless helper inspects these uploads without a renderer, so it must consume them before dropping the recorded frame. --- crates/ui-egui/src/home_recent_ui.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/home_recent_ui.rs b/crates/ui-egui/src/home_recent_ui.rs index b2fd2fb533c..c159451de3f 100644 --- a/crates/ui-egui/src/home_recent_ui.rs +++ b/crates/ui-egui/src/home_recent_ui.rs @@ -506,11 +506,13 @@ mod tests { fn assert_recent_picture(frames: &mut craft::ui::testing::Frames, state: craft::ui::primitives::TextureState, rgba: [u8; 4]) { let craft::ui::primitives::TextureState::Ready(texture) = state else { panic!("the completed decoder must supply a ready picture") }; assert_eq!((texture.size.width, texture.size.height), (4, 4)); - let paint = frames.take_paint().expect("texture uploads were recorded"); + let mut paint = frames.take_paint().expect("texture uploads were recorded"); let delta = paint.textures_delta.set.get(&texture.id).and_then(|changes| changes.last()).expect("the real decoder's texture was uploaded"); let egui::ImageData::Color(image) = &delta.image; assert_eq!(image.size, [4, 4]); assert!(image.pixels.iter().all(|pixel| pixel.to_array() == rgba), "the picture contains the decoded file's pixels"); + // The headless test inspected the uploads instead of rendering them. + paint.textures_delta.clear(); } #[cfg(not(target_arch = "wasm32"))] From ccc230d475cab68eee98e239202b1b41db68afb6 Mon Sep 17 00:00:00 2001 From: ljkx <177671075+ljkx@users.noreply.github.com> Date: Wed, 18 Nov 2026 14:41:58 +0100 Subject: [PATCH 06/12] Tests: the caret font test covers every acceptance again --- .../src/tools/type_tool/font_commit_tests.rs | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/crates/ui-egui/src/tools/type_tool/font_commit_tests.rs b/crates/ui-egui/src/tools/type_tool/font_commit_tests.rs index 3fd4054e273..876cff20206 100644 --- a/crates/ui-egui/src/tools/type_tool/font_commit_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/font_commit_tests.rs @@ -88,7 +88,8 @@ fn fixture(pattern: usize, content: &str) -> (H, LayerId) { (h, id) } -/// Picks `font` in the first family field: open it, type the name, Enter, as `accept` says. +/// Picks `font` in the first family field: open it, type the name, then accept it as `accept` says +/// (Enter, ArrowDown then Enter, a click on its row, or a hover). fn choose(h: &mut H, font: &str, accept: &str) { h.query_all_by_label("Font family").next().unwrap().click(); h.run(); @@ -96,6 +97,11 @@ fn choose(h: &mut H, font: &str, accept: &str) { h.run(); match accept { "enter" => h.key_press(Key::Enter), + "arrow-enter" => { + h.key_press(Key::ArrowDown); + h.run(); + h.key_press(Key::Enter); + } "click" => h.get_by_role_and_label(egui::accesskit::Role::TreeItem, font).click(), "hover" => h.get_by_role_and_label(egui::accesskit::Role::TreeItem, font).hover(), _ => panic!("unknown acceptance"), @@ -111,19 +117,23 @@ fn checkmark(h: &mut H) { #[test] fn caret_font_choices_style_only_subsequent_typing_including_ime() { - for original in 0..2 { + // Every acceptance, as each reaches the caret's pending style by its own route through the + // family field. One original font, as it only decides which font is chosen, and the carets at + // both ends. + let original = 0; + for accept in ["enter", "click", "arrow-enter"] { for text in ["abcdef", "AéB👩‍💻", "ab\ncdé"] { - let n = text.chars().count(); - for caret in [0, n / 2, n] { + for caret in [0, text.chars().count()] { + let label = (accept, text, caret); let (mut h, id) = fixture(original, text); select(&mut h, [caret, caret]); h.run(); let before = saved(&h, id); let steps = h.state().session.active().unwrap().history.entries().len(); let font = FONTS[1 - original]; - choose(&mut h, font, "enter"); - assert_eq!(saved(&h, id), before, "a font choice at a caret never restyles existing characters"); - assert_eq!(h.state().session.active().unwrap().history.entries().len(), steps); + choose(&mut h, font, accept); + assert_eq!(saved(&h, id), before, "a font choice at a caret never restyles existing characters: {label:?}"); + assert_eq!(h.state().session.active().unwrap().history.entries().len(), steps, "{label:?}"); crate::type_font_preview::set(h.state_mut(), font.into()); assert!(crate::type_font_preview::display_doc(h.state_mut(), 0).is_none()); // Two preedit replacements and the final commit keep the pending font. @@ -138,11 +148,11 @@ fn caret_font_choices_style_only_subsequent_typing_including_ime() { h.run(); let mut expected = families(&before); expected.splice(caret..caret, std::iter::repeat_n(font.to_string(), 3)); - assert_eq!(families(&saved(&h, id)), expected); + assert_eq!(families(&saved(&h, id)), expected, "{label:?}"); let typed = saved(&h, id); checkmark(&mut h); - assert_eq!(saved(&h, id), typed); - assert!(h.state().ui.type_insertion_style.is_none()); + assert_eq!(saved(&h, id), typed, "{label:?}"); + assert!(h.state().ui.type_insertion_style.is_none(), "{label:?}"); } } } From 4d576ced907488eb6e7f833b06be3dd99d1c1a25 Mon Sep 17 00:00:00 2001 From: yoriswind Date: Wed, 18 Nov 2026 11:21:18 -0800 Subject: [PATCH 07/12] Partition the long Windows UI test matrices without reducing coverage --- .config/nextest.toml | 4 +- .../src/input/shortcut_dispatch/tests.rs | 101 ++++++++++------- crates/ui-egui/tests/it/tone_targets.rs | 105 ++++++++++-------- 3 files changed, 123 insertions(+), 87 deletions(-) diff --git a/.config/nextest.toml b/.config/nextest.toml index ee1a1a5390b..e4d9ee7f158 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -55,8 +55,8 @@ threads-required = 2 platform = 'cfg(target_os = "windows")' # over 200 s filter = ''' - (package(photocraft-ui-egui) & test(=input::shortcut_dispatch::tests::every_displayed_shortcut_dispatches_from_where_focus_usually_is)) | - (package(photocraft-ui-egui) & test(=tone_targets::review_mask_action_context_matches_the_addressed_layer)) | + (package(photocraft-ui-egui) & (test(=input::shortcut_dispatch::tests::every_displayed_shortcut_dispatches_from_where_focus_usually_is_canvas) | test(=input::shortcut_dispatch::tests::every_displayed_shortcut_dispatches_from_where_focus_usually_is_layers_row) | test(=input::shortcut_dispatch::tests::every_displayed_shortcut_dispatches_from_where_focus_usually_is_focused_widget) | test(=input::shortcut_dispatch::tests::every_displayed_shortcut_dispatches_from_where_focus_usually_is_opacity_field))) | + (package(photocraft-ui-egui) & (test(=tone_targets::review_mask_action_context_matches_the_addressed_layer_rgb) | test(=tone_targets::review_mask_action_context_matches_the_addressed_layer_cmyk) | test(=tone_targets::review_mask_action_context_matches_the_addressed_layer_lab))) | (package(photocraft-ui-egui) & test(=tone_targets::grayscale_picker_controls_sample_the_plane_and_change_the_visible_curve)) | (package(photocraft-ui-egui) & test(=dialogs::adjust_editors::ui_tests::every_adjustment_layer_edits_through_properties)) | (package(photocraft-ui-egui) & test(=tone_targets::filter_mask_tone_dialogs_preserve_the_target_and_sample_its_own_levels)) diff --git a/crates/ui-egui/src/input/shortcut_dispatch/tests.rs b/crates/ui-egui/src/input/shortcut_dispatch/tests.rs index 9d9dd2f3190..cc8cf8e4681 100644 --- a/crates/ui-egui/src/input/shortcut_dispatch/tests.rs +++ b/crates/ui-egui/src/input/shortcut_dispatch/tests.rs @@ -194,54 +194,75 @@ fn displayed(app: &PhotocraftApp) -> Vec<(String, String, bool)> { /// Press every displayed shortcut from each place focus usually is: each dispatches its command, /// or the menu shows it disabled and the press reports why. (Dry run: File › Exit, Open, Help /// links… resolve and check enablement without running.) -#[test] -fn every_displayed_shortcut_dispatches_from_where_focus_usually_is() { +fn every_displayed_shortcut_dispatches_from_where_focus_usually_is_for(place: Place) { let mut failures = Vec::new(); - for place in [Place::Canvas, Place::LayersRow, Place::FocusedWidget, Place::OpacityField] { - let mut h = harness(); - set_dry_run(&h.ctx, true); - put_focus(&mut h, place); - let typing = WindowHost::of(&h.ctx).typing(); - let items = crate::menus::menu_rows(h.state()); - for (id, sc, live) in displayed(h.state()) { - if !live { - continue; - } - let chord = Chord::parse(&sc).unwrap_or_else(|_| panic!("{id}: unparsable {sc}")); - // A press the focused component holds (the Layers rows' stacking and visibility keys) - // is the component's and reaches no app command. - let held = focus_holds(&h.ctx, chord); - press(&mut h, &sc); - let log = take_log(&h.ctx); - if typing && !chord.has_command() && !chord.is_function_key() { - // A focused text field keeps its typing / editing keys: nothing may fire. - if !log.is_empty() { - failures.push(format!("{place:?}: {sc} ({id}) fired {log:?} into a focused field")); - } - continue; - } - let enabled = items.iter().find(|i| i.command.id == id).map_or_else(|| crate::menus::is_enabled(h.state(), &id), |i| i.enabled); - match log.as_slice() { - [] if held || typing => {} - [(bound, Outcome::Ran)] if same(&id, bound) && enabled => {} - [(bound, Outcome::Disabled(why))] if same(&id, bound) && !enabled && !why.is_empty() => {} - other => failures.push(format!("{place:?}: {sc} ({id}, menu enabled: {enabled}) -> {other:?}")), - } + let mut h = harness(); + set_dry_run(&h.ctx, true); + put_focus(&mut h, place); + let typing = WindowHost::of(&h.ctx).typing(); + let items = crate::menus::menu_rows(h.state()); + for (id, sc, live) in displayed(h.state()) { + if !live { + continue; } - // Tool letters from the tools panel tooltips ("Brush Tool (B)"). - if !typing { - for t in Tool::ALL.into_iter().filter(|t| t.key() != '\0') { - h.state_mut().ui.tool = if t.key() == 'H' { Tool::Move } else { Tool::Hand }; - press(&mut h, &t.key().to_string()); - if h.state().ui.tool.key() != t.key() { - failures.push(format!("{place:?}: tool key {} left {:?}", t.key(), h.state().ui.tool)); - } + let chord = Chord::parse(&sc).unwrap_or_else(|_| panic!("{id}: unparsable {sc}")); + // A press the focused component holds (the Layers rows' stacking and visibility keys) + // is the component's and reaches no app command. + let held = focus_holds(&h.ctx, chord); + press(&mut h, &sc); + let log = take_log(&h.ctx); + if typing && !chord.has_command() && !chord.is_function_key() { + // A focused text field keeps its typing / editing keys: nothing may fire. + if !log.is_empty() { + failures.push(format!("{place:?}: {sc} ({id}) fired {log:?} into a focused field")); + } + continue; + } + let enabled = items.iter().find(|i| i.command.id == id).map_or_else(|| crate::menus::is_enabled(h.state(), &id), |i| i.enabled); + match log.as_slice() { + [] if held || typing => {} + [(bound, Outcome::Ran)] if same(&id, bound) && enabled => {} + [(bound, Outcome::Disabled(why))] if same(&id, bound) && !enabled && !why.is_empty() => {} + other => failures.push(format!("{place:?}: {sc} ({id}, menu enabled: {enabled}) -> {other:?}")), + } + } + // Tool letters from the tools panel tooltips ("Brush Tool (B)"). + if !typing { + for t in Tool::ALL.into_iter().filter(|t| t.key() != '\0') { + h.state_mut().ui.tool = if t.key() == 'H' { Tool::Move } else { Tool::Hand }; + press(&mut h, &t.key().to_string()); + if h.state().ui.tool.key() != t.key() { + failures.push(format!("{place:?}: tool key {} left {:?}", t.key(), h.state().ui.tool)); } } } assert!(failures.is_empty(), "{} shortcut failures:\n{}", failures.len(), failures.join("\n")); } +/// The complete displayed shortcut matrix from one ordinary focus location. +#[test] +fn every_displayed_shortcut_dispatches_from_where_focus_usually_is_canvas() { + every_displayed_shortcut_dispatches_from_where_focus_usually_is_for(Place::Canvas); +} + +/// The complete displayed shortcut matrix from one ordinary focus location. +#[test] +fn every_displayed_shortcut_dispatches_from_where_focus_usually_is_layers_row() { + every_displayed_shortcut_dispatches_from_where_focus_usually_is_for(Place::LayersRow); +} + +/// The complete displayed shortcut matrix from one ordinary focus location. +#[test] +fn every_displayed_shortcut_dispatches_from_where_focus_usually_is_focused_widget() { + every_displayed_shortcut_dispatches_from_where_focus_usually_is_for(Place::FocusedWidget); +} + +/// The complete displayed shortcut matrix from one ordinary focus location. +#[test] +fn every_displayed_shortcut_dispatches_from_where_focus_usually_is_opacity_field() { + every_displayed_shortcut_dispatches_from_where_focus_usually_is_for(Place::OpacityField); +} + #[test] fn a_disabled_shortcut_says_why() { let mut h = harness(); diff --git a/crates/ui-egui/tests/it/tone_targets.rs b/crates/ui-egui/tests/it/tone_targets.rs index cedcb8a7734..2def86ec649 100644 --- a/crates/ui-egui/tests/it/tone_targets.rs +++ b/crates/ui-egui/tests/it/tone_targets.rs @@ -1117,57 +1117,72 @@ fn addressed_mask_app(mode: ColorMode, depth: SampleType, filter: bool) -> (Box< /// Named/id mask Actions show, sample, preview and edit the addressed layer's own mask without /// switching the selected layer. The matrix includes native raster and Smart Filter masks. -#[test] -fn review_mask_action_context_matches_the_addressed_layer() { - for mode in MODES { - for depth in DEPTHS { - for kind in ["levels", "curves"] { - for filter in [false, true] { - let (app, layer) = addressed_mask_app(mode, depth, filter); - for selector in [json!(layer.0), json!("Receiver"), json!({"name":"Receiver"})] { - let mut app = fixture_for_addressed_replay(&app); - let command = format!("image.adjustments.{kind}"); - let target = if filter { "filterMask" } else { "mask" }; - let raw = json!({"layer":selector,"target":target}); - add_action(&mut app, "Other mask", command.clone(), raw, true); - let original = app.session.active().unwrap().doc.clone(); - let active = app.session.active().unwrap().active_layer; - let expected = - photocraft_engine::mask_view_cmds::viewed_mask(original.layer(layer).unwrap(), filter).unwrap().surface.sample_channel(8, 8, 0); - let mut h = canvas_harness(app); - play(&mut h, "Other mask"); - assert_eq!(names(&h), [if filter { "Receiver Filter Mask" } else { "Receiver Mask" }]); - let id = top(&h); - arm(&mut h, "white"); - sample_at(&mut h, 4.0, 4.0); - let p = params(&h); - let want = photocraft_engine::adjust_params::adjustment_eyedropper( - kind, - &json!({}), - photocraft_engine::adjust_params::CurvesEyedropper::White, - [expected; 3], - ColorMode::Grayscale, - ) - .unwrap(); - let got = photocraft_engine::adjust_params::from_params(kind, &p, None, ColorMode::Grayscale).unwrap(); - assert_eq!(got, want, "{mode:?} {depth:?} {kind} {target}"); - let preview = filter_dialog::preview_document(&original, active, &command, &p, 1).unwrap(); - confirm(&mut h, id).unwrap(); - let doc = &h.state().session.active().unwrap().doc; - assert_eq!(doc.layers, preview.layers); - assert_eq!(doc.layers[0], original.layers[0]); - assert_eq!(doc.channels, original.channels); - assert!( - photocraft_engine::mask_view_cmds::viewed_mask(doc.layer(layer).unwrap(), filter).unwrap().surface.sample_channel(8, 8, 0) > 0.99 - ); - assert_eq!(h.state().session.active().unwrap().active_layer, active); - } +fn review_mask_action_context_matches_the_addressed_layer_for(mode: ColorMode) { + for depth in DEPTHS { + for kind in ["levels", "curves"] { + for filter in [false, true] { + let (app, layer) = addressed_mask_app(mode, depth, filter); + for selector in [json!(layer.0), json!("Receiver"), json!({"name":"Receiver"})] { + let mut app = fixture_for_addressed_replay(&app); + let command = format!("image.adjustments.{kind}"); + let target = if filter { "filterMask" } else { "mask" }; + let raw = json!({"layer":selector,"target":target}); + add_action(&mut app, "Other mask", command.clone(), raw, true); + let original = app.session.active().unwrap().doc.clone(); + let active = app.session.active().unwrap().active_layer; + let expected = + photocraft_engine::mask_view_cmds::viewed_mask(original.layer(layer).unwrap(), filter).unwrap().surface.sample_channel(8, 8, 0); + let mut h = canvas_harness(app); + play(&mut h, "Other mask"); + assert_eq!(names(&h), [if filter { "Receiver Filter Mask" } else { "Receiver Mask" }]); + let id = top(&h); + arm(&mut h, "white"); + sample_at(&mut h, 4.0, 4.0); + let p = params(&h); + let want = photocraft_engine::adjust_params::adjustment_eyedropper( + kind, + &json!({}), + photocraft_engine::adjust_params::CurvesEyedropper::White, + [expected; 3], + ColorMode::Grayscale, + ) + .unwrap(); + let got = photocraft_engine::adjust_params::from_params(kind, &p, None, ColorMode::Grayscale).unwrap(); + assert_eq!(got, want, "{mode:?} {depth:?} {kind} {target}"); + let preview = filter_dialog::preview_document(&original, active, &command, &p, 1).unwrap(); + confirm(&mut h, id).unwrap(); + let doc = &h.state().session.active().unwrap().doc; + assert_eq!(doc.layers, preview.layers); + assert_eq!(doc.layers[0], original.layers[0]); + assert_eq!(doc.channels, original.channels); + assert!( + photocraft_engine::mask_view_cmds::viewed_mask(doc.layer(layer).unwrap(), filter).unwrap().surface.sample_channel(8, 8, 0) > 0.99 + ); + assert_eq!(h.state().session.active().unwrap().active_layer, active); } } } } } +/// The addressed-mask Action matrix for one document colour mode. +#[test] +fn review_mask_action_context_matches_the_addressed_layer_rgb() { + review_mask_action_context_matches_the_addressed_layer_for(ColorMode::Rgb); +} + +/// The addressed-mask Action matrix for one document colour mode. +#[test] +fn review_mask_action_context_matches_the_addressed_layer_cmyk() { + review_mask_action_context_matches_the_addressed_layer_for(ColorMode::Cmyk); +} + +/// The addressed-mask Action matrix for one document colour mode. +#[test] +fn review_mask_action_context_matches_the_addressed_layer_lab() { + review_mask_action_context_matches_the_addressed_layer_for(ColorMode::Lab); +} + /// Copy the source document for independent Action cases without carrying modal/UI history. fn fixture_for_addressed_replay(app: &PhotocraftApp) -> Box { let st = app.session.active().unwrap(); From 6294c6fe0067d8513499aee9e8c674d3b453a177 Mon Sep 17 00:00:00 2001 From: yoriswind Date: Wed, 18 Nov 2026 11:42:46 -0800 Subject: [PATCH 08/12] Format the partitioned mask assertion --- crates/ui-egui/tests/it/tone_targets.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/ui-egui/tests/it/tone_targets.rs b/crates/ui-egui/tests/it/tone_targets.rs index 2def86ec649..7444a28d930 100644 --- a/crates/ui-egui/tests/it/tone_targets.rs +++ b/crates/ui-egui/tests/it/tone_targets.rs @@ -1155,9 +1155,7 @@ fn review_mask_action_context_matches_the_addressed_layer_for(mode: ColorMode) { assert_eq!(doc.layers, preview.layers); assert_eq!(doc.layers[0], original.layers[0]); assert_eq!(doc.channels, original.channels); - assert!( - photocraft_engine::mask_view_cmds::viewed_mask(doc.layer(layer).unwrap(), filter).unwrap().surface.sample_channel(8, 8, 0) > 0.99 - ); + assert!(photocraft_engine::mask_view_cmds::viewed_mask(doc.layer(layer).unwrap(), filter).unwrap().surface.sample_channel(8, 8, 0) > 0.99); assert_eq!(h.state().session.active().unwrap().active_layer, active); } } From 1d391ce10ff823abdad6802433189eb97045d542 Mon Sep 17 00:00:00 2001 From: David Mann Date: Thu, 19 Nov 2026 17:50:13 +0100 Subject: [PATCH 09/12] Integration: #15429: the caret font test checks the typed text and the pending font before the commit CodeRabbit on #15429: the family check alone passed if the IME inserted other characters in the same fonts, and the cleanup check passed if the pending font was already gone before the check mark. Co-Authored-By: Claude Opus 5.5 --- .../src/tools/type_tool/font_commit_tests.rs | 6 +- crates/ui-egui/tests/it/tone_targets.rs | 110 ++++++++---------- 2 files changed, 54 insertions(+), 62 deletions(-) diff --git a/crates/ui-egui/src/tools/type_tool/font_commit_tests.rs b/crates/ui-egui/src/tools/type_tool/font_commit_tests.rs index 3f2c6f71031..cfc131d5e68 100644 --- a/crates/ui-egui/src/tools/type_tool/font_commit_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/font_commit_tests.rs @@ -180,10 +180,14 @@ fn caret_font_choices_style_only_subsequent_typing_including_ime() { let mut expected = families(&before); expected.splice(caret..caret, std::iter::repeat_n(font.to_string(), 3)); assert_eq!(families(&saved(&h, id)), expected, "{label:?}"); + let mut expected_text: Vec = text.chars().collect(); + expected_text.splice(caret..caret, "éXZ".chars()); let typed = saved(&h, id); + assert_eq!(typed["text"], expected_text.into_iter().collect::(), "the IME and typed text land at the caret: {label:?}"); + assert!(h.state().ui.type_insertion_style.is_some(), "the pending font is still set before the commit: {label:?}"); checkmark(&mut h); assert_eq!(saved(&h, id), typed, "{label:?}"); - assert!(h.state().ui.type_insertion_style.is_none(), "{label:?}"); + assert!(h.state().ui.type_insertion_style.is_none(), "the commit clears the pending font: {label:?}"); } } } diff --git a/crates/ui-egui/tests/it/tone_targets.rs b/crates/ui-egui/tests/it/tone_targets.rs index a5c6da82478..b0060e0728d 100644 --- a/crates/ui-egui/tests/it/tone_targets.rs +++ b/crates/ui-egui/tests/it/tone_targets.rs @@ -27,7 +27,7 @@ const TARGETS: [ChannelTarget; 3] = [ChannelTarget::Alpha(0), ChannelTarget::Lay /// these tests run every kind and target on [`RGB_8`] and visit the other modes once. Sampling the right plane at /// every colour mode x native depth is `destructive_eyedropper`'s, tested without the app in the engine's /// `tone_target_picker.rs` (#15648). The full cross product ran a single test past nextest's 600 s limit on -/// Windows (#15636). The addressed-mask Action regressions below retain their full matrix in separate per-mode tests. +/// Windows (#15636). const RGB_8: (ColorMode, SampleType) = (ColorMode::Rgb, SampleType::U8); /// The keys the hosted adjustment dialog lists beside its engine parameters. @@ -1201,69 +1201,57 @@ fn addressed_mask_session(mode: ColorMode, depth: SampleType, filter: bool) -> ( /// Named/id mask Actions show, sample, preview and edit the addressed layer's own mask without /// switching the selected layer. The matrix includes native raster and Smart Filter masks. -fn review_mask_action_context_matches_the_addressed_layer_for(mode: ColorMode) { +#[test] +fn review_mask_action_context_matches_the_addressed_layer() { let mut h = bench(); - for depth in DEPTHS { - for kind in ["levels", "curves"] { - for filter in [false, true] { - let (source, layer) = addressed_mask_session(mode, depth, filter); - let selectors = [json!(layer.0), json!("Receiver"), json!({"name":"Receiver"})]; - for selector in selectors { - next_case(&mut h, &source, None); - let command = format!("image.adjustments.{kind}"); - let target = if filter { "filterMask" } else { "mask" }; - let raw = json!({"layer":selector,"target":target}); - add_action(h.state_mut(), "Other mask", command.clone(), raw, true); - let original = h.state().session.active().unwrap().doc.clone(); - let active = h.state().session.active().unwrap().active_layer; - let expected = - photocraft_engine::mask_view_cmds::viewed_mask(original.layer(layer).unwrap(), filter).unwrap().surface.sample_channel(8, 8, 0); - play(&mut h, "Other mask"); - assert_eq!(names(&h), [if filter { "Receiver Filter Mask" } else { "Receiver Mask" }]); - let id = top(&h); - arm(&mut h, "white"); - sample_at(&mut h, 4.0, 4.0); - let p = params(&h); - let want = photocraft_engine::adjust_params::adjustment_eyedropper( - kind, - &json!({}), - photocraft_engine::adjust_params::CurvesEyedropper::White, - [expected; 3], - ColorMode::Grayscale, - ) - .unwrap(); - let got = photocraft_engine::adjust_params::from_params(kind, &p, None, ColorMode::Grayscale).unwrap(); - assert_eq!(got, want, "{mode:?} {depth:?} {kind} {target}"); - let preview = filter_dialog::preview_document(&original, active, &command, &p, 1).unwrap(); - confirm(&mut h, id).unwrap(); - let doc = &h.state().session.active().unwrap().doc; - assert_eq!(doc.layers, preview.layers); - assert_eq!(doc.layers[0], original.layers[0]); - assert_eq!(doc.channels, original.channels); - assert!(photocraft_engine::mask_view_cmds::viewed_mask(doc.layer(layer).unwrap(), filter).unwrap().surface.sample_channel(8, 8, 0) > 0.99); - assert_eq!(h.state().session.active().unwrap().active_layer, active); - } - } + // Both dialogs with both mask kinds on an RGB document, and a CMYK and a Lab document once. Resolving the address is + // the engine's (`review_picker_reads_the_addressed_mask_layer` runs every selector form in every mode and depth); + // here every form runs on the first layer-mask and filter-mask cases, the name form on the rest. + let mut cases = Vec::new(); + for kind in ["levels", "curves"] { + for filter in [false, true] { + cases.push((RGB_8, kind, filter)); + } + } + cases.extend([((ColorMode::Cmyk, SampleType::U16), "curves", true), ((ColorMode::Lab, SampleType::F32), "levels", false)]); + for (case, ((mode, depth), kind, filter)) in cases.into_iter().enumerate() { + let (source, layer) = addressed_mask_session(mode, depth, filter); + let selectors = [json!("Receiver"), json!(layer.0), json!({"name":"Receiver"})]; + for selector in selectors.into_iter().take(if case < 2 { 3 } else { 1 }) { + next_case(&mut h, &source, None); + let command = format!("image.adjustments.{kind}"); + let target = if filter { "filterMask" } else { "mask" }; + let raw = json!({"layer":selector,"target":target}); + add_action(h.state_mut(), "Other mask", command.clone(), raw, true); + let original = h.state().session.active().unwrap().doc.clone(); + let active = h.state().session.active().unwrap().active_layer; + let expected = photocraft_engine::mask_view_cmds::viewed_mask(original.layer(layer).unwrap(), filter).unwrap().surface.sample_channel(8, 8, 0); + play(&mut h, "Other mask"); + assert_eq!(names(&h), [if filter { "Receiver Filter Mask" } else { "Receiver Mask" }]); + let id = top(&h); + arm(&mut h, "white"); + sample_at(&mut h, 4.0, 4.0); + let p = params(&h); + let want = photocraft_engine::adjust_params::adjustment_eyedropper( + kind, + &json!({}), + photocraft_engine::adjust_params::CurvesEyedropper::White, + [expected; 3], + ColorMode::Grayscale, + ) + .unwrap(); + let got = photocraft_engine::adjust_params::from_params(kind, &p, None, ColorMode::Grayscale).unwrap(); + assert_eq!(got, want, "{mode:?} {depth:?} {kind} {target}"); + let preview = filter_dialog::preview_document(&original, active, &command, &p, 1).unwrap(); + confirm(&mut h, id).unwrap(); + let doc = &h.state().session.active().unwrap().doc; + assert_eq!(doc.layers, preview.layers); + assert_eq!(doc.layers[0], original.layers[0]); + assert_eq!(doc.channels, original.channels); + assert!(photocraft_engine::mask_view_cmds::viewed_mask(doc.layer(layer).unwrap(), filter).unwrap().surface.sample_channel(8, 8, 0) > 0.99); + assert_eq!(h.state().session.active().unwrap().active_layer, active); } } -} - -/// The addressed-mask Action matrix for one document colour mode. -#[test] -fn review_mask_action_context_matches_the_addressed_layer_rgb() { - review_mask_action_context_matches_the_addressed_layer_for(ColorMode::Rgb); -} - -/// The addressed-mask Action matrix for one document colour mode. -#[test] -fn review_mask_action_context_matches_the_addressed_layer_cmyk() { - review_mask_action_context_matches_the_addressed_layer_for(ColorMode::Cmyk); -} - -/// The addressed-mask Action matrix for one document colour mode. -#[test] -fn review_mask_action_context_matches_the_addressed_layer_lab() { - review_mask_action_context_matches_the_addressed_layer_for(ColorMode::Lab); } /// Repairing a missing Action address re-seeds its recorded alias without losing modal context. From ca87f95aec16125bc32f184e6aaf8d75d6decc5b Mon Sep 17 00:00:00 2001 From: David Mann Date: Thu, 19 Nov 2026 17:50:13 +0100 Subject: [PATCH 10/12] Integration: #15417: keep main's addressed-mask Action cases #15417 brought back the full 108-case addressed-mask matrix, which main trimmed for test time (#15636, #15648); selector forms in every mode and depth stay covered by the engine's review_picker_reads_the_addressed_mask_layer. That is outside #15379's two worker rows, so tone_targets.rs and its nextest entry go back to main. The shortcut matrix split stays. Co-Authored-By: Claude Opus 5.5 --- .config/nextest.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/nextest.toml b/.config/nextest.toml index 90dbe567bbd..1217276221d 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -68,7 +68,7 @@ threads-required = 2 # over 200 s filter = ''' (package(photocraft-ui-egui) & (test(=input::shortcut_dispatch::tests::every_displayed_shortcut_dispatches_from_where_focus_usually_is_canvas) | test(=input::shortcut_dispatch::tests::every_displayed_shortcut_dispatches_from_where_focus_usually_is_layers_row) | test(=input::shortcut_dispatch::tests::every_displayed_shortcut_dispatches_from_where_focus_usually_is_focused_widget) | test(=input::shortcut_dispatch::tests::every_displayed_shortcut_dispatches_from_where_focus_usually_is_opacity_field))) | - (package(photocraft-ui-egui) & (test(=tone_targets::review_mask_action_context_matches_the_addressed_layer_rgb) | test(=tone_targets::review_mask_action_context_matches_the_addressed_layer_cmyk) | test(=tone_targets::review_mask_action_context_matches_the_addressed_layer_lab))) | + (package(photocraft-ui-egui) & test(=tone_targets::review_mask_action_context_matches_the_addressed_layer)) | (package(photocraft-ui-egui) & test(=tone_targets::grayscale_picker_controls_sample_the_plane_and_change_the_visible_curve)) | (package(photocraft-ui-egui) & test(=dialogs::adjust_editors::ui_tests::every_adjustment_layer_edits_through_properties)) | (package(photocraft-ui-egui) & test(=tone_targets::filter_mask_tone_dialogs_preserve_the_target_and_sample_its_own_levels)) From cc31e60bd48803d65d16bcaec5583556d5f66261 Mon Sep 17 00:00:00 2001 From: David Mann Date: Thu, 19 Nov 2026 18:01:54 +0100 Subject: [PATCH 11/12] Integration: #15429: the arrow-key case accepts whichever row ArrowDown reaches ArrowDown steps to the row below the typed match. Where JetBrains Mono NL is installed (Windows), that row is NL, so the case failed on the font list rather than on the caret path. The test now takes the pending font as the accepted row, checks it matches the typed name and differs from the text's font, and keeps the exact font for Enter and click. Co-Authored-By: Claude Opus 5.5 --- .../src/tools/type_tool/font_commit_tests.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/tools/type_tool/font_commit_tests.rs b/crates/ui-egui/src/tools/type_tool/font_commit_tests.rs index cfc131d5e68..8b47bc69d3a 100644 --- a/crates/ui-egui/src/tools/type_tool/font_commit_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/font_commit_tests.rs @@ -161,8 +161,22 @@ fn caret_font_choices_style_only_subsequent_typing_including_ime() { h.run(); let before = saved(&h, id); let steps = h.state().session.active().unwrap().history.entries().len(); - let font = FONTS[1 - original]; - choose(&mut h, font, accept); + let requested = FONTS[1 - original]; + choose(&mut h, requested, accept); + // ArrowDown steps to the row below the typed match, which depends on the installed fonts + // ("JetBrains Mono NL" where it is installed), so the pending font is the row it accepted. + let font = h + .state() + .ui + .type_insertion_style + .as_ref() + .map(|s| s.style.font_family.clone()) + .unwrap_or_else(|| panic!("a pending font at the caret: {label:?}")); + let font = font.as_str(); + assert!(font.starts_with(requested) && font != FONTS[original], "the accepted row matches the typed name: {font} {label:?}"); + if accept != "arrow-enter" { + assert_eq!(font, requested, "{label:?}"); + } assert_eq!(saved(&h, id), before, "a font choice at a caret never restyles existing characters: {label:?}"); assert_eq!(h.state().session.active().unwrap().history.entries().len(), steps, "{label:?}"); crate::type_font_preview::set(h.state_mut(), font.into()); From fb372c60110c87107049df8d578987120cddce55 Mon Sep 17 00:00:00 2001 From: David Mann Date: Thu, 19 Nov 2026 19:46:17 +0100 Subject: [PATCH 12/12] Paint tool tests: smoothing off where the measured lag is not under test (#15803) #12246 made the default 10 % smoothing lag the measured one and stopped zero-time repeats from moving the brush. The Mixer release test and the pen tilt preview test painted with that default on real frame times, so the brush no longer reached the release point and the tail landed inside the compared region. Neither test is about smoothing. --- crates/ui-egui/src/canvas/paint_tool/tests.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/canvas/paint_tool/tests.rs b/crates/ui-egui/src/canvas/paint_tool/tests.rs index 4498653fdad..fb373370640 100644 --- a/crates/ui-egui/src/canvas/paint_tool/tests.rs +++ b/crates/ui-egui/src/canvas/paint_tool/tests.rs @@ -215,7 +215,12 @@ fn mixer_drag_shows_actual_mixed_paint_before_release_and_alt_never_paints() { #[test] fn mixer_release_includes_a_new_endpoint_and_deferred_frame_samples() { for failed in [false, true] { - let mut h = harness(mixer_app()); + let mut app = mixer_app(); + // Smoothing off: this is about which points reach the commit, and the Mixer Brush's + // first-use 10 % lag (measured, #11888) would hold the brush short of the release point. + crate::paint_mouse::sync_tool_brush(&mut app); + app.run("tools.setBrush", json!({"brush": {"smoothing": {"amount": 0.0}}})).unwrap(); + let mut h = harness(app); let before = h.state().session.active().unwrap().doc.clone(); let p = |h: &Harness<'static, Box>, x: f64| at(h, x, 30.0); let start = p(&h, 20.0); @@ -371,7 +376,10 @@ fn live_stroke_uses_pen_tilt_and_redraws_partially() { let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); let ctx = app.ctx().clone(); app.run("file.new", json!({"width": 4097, "height": 90, "background": "transparent"})).unwrap(); - let tilt = json!({"size": 30, "hardness": 1.0, "spacing": 0.05, "shapeDynamics": {"enabled": true, "size": {"control": "penTilt"}}}); + // Smoothing off: the default 10 % lag (measured, #11888) on wall-clock times would leave the + // preview's tail anywhere short of the release, so the comparison below couldn't hold. + let tilt = + json!({"size": 30, "hardness": 1.0, "spacing": 0.05, "smoothing": {"amount": 0.0}, "shapeDynamics": {"enabled": true, "size": {"control": "penTilt"}}}); app.run("tools.setBrush", json!({ "brush": tilt })).unwrap(); app.ui.tool = Tool::Brush; let mut seen = composite_revision(&mut app, &ctx, 0, None); @@ -390,7 +398,6 @@ fn live_stroke_uses_pen_tilt_and_redraws_partially() { let (a, b) = (doc.layers[0].surface().unwrap(), shown.layers[0].surface().unwrap()); // 60° tilt shrinks the dab well below 30 px: the preview shows that size, as committed. assert!(a.rgba(500, 45)[3] > 0.5 && a.rgba(500, 45 + 12)[3] == 0.0); - // (The smoothed tail catches up to the end point only when the stroke finishes.) assert!((0..90).all(|y| (0..700).all(|x| a.rgba(x, y) == b.rgba(x, y))), "commit matches the preview"); }