From c865234eb56577aa2b21f9e052c8dad2a1e40acb Mon Sep 17 00:00:00 2001 From: David Mann Date: Wed, 18 Nov 2026 21:04:03 +0100 Subject: [PATCH 1/2] WIP: tone_targets whole-app runs only for the UI glue (#15648) Co-Authored-By: Claude Opus 5.5 From 6ec2b76b786439449c8d0cf0d151ab1de9c19dad Mon Sep 17 00:00:00 2001 From: David Mann Date: Wed, 18 Nov 2026 21:12:45 +0100 Subject: [PATCH 2/2] Tests: tone_targets builds the whole app only for the UI glue (#15648) The three whole-app Levels/Curves tests ran the colour mode x bit depth matrix that the engine's tone_target_picker tests already cover without the app. They now run every dialog and target on an RGB document and the grayscale, CMYK and Lab documents once each, where adjust_dialog::pick branches; every selector form still runs for a layer mask and a filter mask. A new engine test covers the Smart Filter mask picker in every mode, depth and mask state, the one gray target the engine did not test yet. Whole-app runs: 60 -> 25 (228 on main before #15637). Co-Authored-By: Claude Opus 5.5 --- crates/engine/tests/it/tone_target_picker.rs | 53 ++++ crates/ui-egui/tests/it/tone_targets.rs | 245 ++++++++++--------- 2 files changed, 185 insertions(+), 113 deletions(-) diff --git a/crates/engine/tests/it/tone_target_picker.rs b/crates/engine/tests/it/tone_target_picker.rs index 6e291729a4b..16b4ee9cec4 100644 --- a/crates/engine/tests/it/tone_target_picker.rs +++ b/crates/engine/tests/it/tone_target_picker.rs @@ -381,3 +381,56 @@ fn review_picker_reads_the_addressed_mask_layer() { } } } + +/// A Smart Filter mask is a gray target like a layer mask: the picker reads the stored mask, or the implicit Reveal +/// All before anything is stored, without materializing it, and the commit edits only the filter mask, in every +/// colour mode and native depth. (The UI's tone dialogs test only that their pick reaches this target, #15648.) +#[test] +fn filter_mask_picker_samples_and_edits_only_the_filter_mask() { + for mode in [ColorMode::Rgb, ColorMode::Grayscale, ColorMode::Cmyk, ColorMode::Lab] { + for depth in [SampleType::U8, SampleType::U16, SampleType::F32] { + for stored in [false, true] { + for kind in ["levels", "curves"] { + let case = format!("{mode:?} {depth:?} stored={stored} {kind}"); + let mut s = session(mode, depth); + // A Smart Filter needs the composite selected, not one colour channel, and no Quick Mask (the filter + // would edit the Quick Mask instead). + s.edit("No Quick Mask", |doc, _| { + doc.quick_mask = None; + Ok(()) + }) + .unwrap(); + s.active_mut().unwrap().channel_view.target = ChannelTarget::Composite; + s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap(); + s.execute("filter.blur.gaussianBlur", json!({"radius": 1})).unwrap(); + if stored { + s.execute("edit.fill", json!({"target": "filterMask", "contents": "color", "color": "#404040"})).unwrap(); + } + let id = s.active().unwrap().active_layer.unwrap(); + let before = s.active().unwrap().doc.clone(); + let p = json!({"target": "filterMask", "eyedropper": {"point": "white", "at": [8, 8]}}); + let picked = adjust_params::destructive_eyedropper(&s, kind, &p).unwrap().unwrap(); + assert!(std::sync::Arc::ptr_eq(&before, &s.active().unwrap().doc), "sampling is read-only: {case}"); + let white = if stored { 64.0 } else { 255.0 }; + let sampled = if kind == "levels" { + adjust_params::to_params(&picked)["inWhite"].as_f64().unwrap() + } else { + adjust_params::to_params(&picked)["points"].as_array().unwrap().last().unwrap()[0].as_f64().unwrap() + }; + assert!((sampled - white).abs() < 1.0, "{case}: sampled {sampled}, want {white}"); + s.execute(&format!("image.adjustments.{kind}"), p).unwrap(); + let doc = &s.active().unwrap().doc; + let (LayerContent::Smart(old), LayerContent::Smart(new)) = (&before.layer(id).unwrap().content, &doc.layer(id).unwrap().content) else { + panic!("{case}: not a smart object") + }; + assert!(new.filter_mask.as_ref().unwrap().surface.sample_channel(8, 8, 0) > 0.99, "{case}"); + assert_eq!(new.smart_filters, old.smart_filters, "{case}: the adjustment edits the mask, adds no filter"); + assert_eq!(new.source, old.source, "{case}"); + assert_eq!(doc.layer(id).unwrap().mask, before.layer(id).unwrap().mask, "{case}: the layer mask"); + assert_eq!(doc.channels, before.channels, "{case}"); + assert_eq!(doc.quick_mask, before.quick_mask, "{case}"); + } + } + } + } +} diff --git a/crates/ui-egui/tests/it/tone_targets.rs b/crates/ui-egui/tests/it/tone_targets.rs index d1c02abb38b..c5e6e69dfef 100644 --- a/crates/ui-egui/tests/it/tone_targets.rs +++ b/crates/ui-egui/tests/it/tone_targets.rs @@ -20,14 +20,15 @@ const MODES: [ColorMode; 3] = [ColorMode::Rgb, ColorMode::Cmyk, ColorMode::Lab]; const GRAY_TARGET_MODES: [ColorMode; 4] = [ColorMode::Rgb, ColorMode::Cmyk, ColorMode::Lab, ColorMode::Grayscale]; const DEPTHS: [SampleType; 3] = [SampleType::U8, SampleType::U16, SampleType::F32]; const TARGETS: [ChannelTarget; 3] = [ChannelTarget::Alpha(0), ChannelTarget::LayerMask, ChannelTarget::Composite]; -/// Every mode and every depth once, for the whole-app tests. The planes they edit are single-channel -/// gray whatever the document mode (the mode only changes the colour layer, which each case asserts -/// stays untouched), and the depth does not interact with the mode, so the full cross product reaches -/// no new code and ran a single test past nextest's 600 s limit on Windows (#15636). -const MODE_DEPTHS: [(ColorMode, SampleType); 3] = [(ColorMode::Rgb, SampleType::U8), (ColorMode::Cmyk, SampleType::U16), (ColorMode::Lab, SampleType::F32)]; -/// [`MODE_DEPTHS`] plus a grayscale document, for the tests that also cover gray documents. -const GRAY_MODE_DEPTHS: [(ColorMode, SampleType); 4] = - [(ColorMode::Rgb, SampleType::U8), (ColorMode::Cmyk, SampleType::U16), (ColorMode::Lab, SampleType::F32), (ColorMode::Grayscale, SampleType::U16)]; +/// The whole-app picker tests check what the UI adds to the engine's gray picker: the canvas press reaches the +/// armed dialog (`canvas/tools/dialog.rs` -> `canvas_input::pick_tone`), and `adjust_dialog::pick` puts the +/// dialog's target into the parameters and writes the result back into the dialog. That code branches on the +/// dialog kind, the target and on RGB / gray / other documents (`picker.supported`), never on the bit depth, so +/// 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). One whole-app case builds a fresh app and renders about 20 frames, so the +/// full cross product ran a single test past nextest's 600 s limit on Windows (#15636). +const RGB_8: (ColorMode, SampleType) = (ColorMode::Rgb, SampleType::U8); /// The keys the hosted adjustment dialog lists beside its engine parameters. const DIALOG_STATE: [&str; 4] = ["preview", "picker", "channel", "clipping"]; @@ -415,41 +416,47 @@ fn levels_auto_uses_the_selected_colour_channels_histogram() { } } -/// Black/white picker controls sample the gray plane and update the visible neutral curve. +/// Black/white picker controls sample the gray plane and update the visible neutral curve: every dialog and target +/// on an RGB document, then a grayscale, a CMYK and a Lab document once each (see [`RGB_8`]). #[test] fn grayscale_picker_controls_sample_the_plane_and_change_the_visible_curve() { + let mut cases = Vec::new(); for kind in ["curves", "levels"] { - for (mode, depth) in GRAY_MODE_DEPTHS { - for target in TARGETS { - let mut h = open_on_canvas(fixture(mode, depth, target), kind); - assert!(h.get_by_label("Set Neutral Gray Point").accesskit_node().is_disabled()); - assert!(!h.get_by_label("Set White Point").accesskit_node().is_disabled()); - h.get_by_label("Set White Point").click(); - h.run_steps(2); - assert!(picker_armed(&h)); - let before = params(&h); - let original = h.state().session.active().unwrap().doc.clone(); - sample_at(&mut h, 4.0, 4.0); - let after = params(&h); - let key = if kind == "curves" { "points" } else { "inWhite" }; - assert_ne!(before[key], after[key], "{kind} {mode:?} {depth:?} {target:?}"); - let sampled_level = if kind == "curves" { - after["points"].as_array().unwrap().last().unwrap()[0].as_f64().unwrap() - } else { - after["inWhite"].as_f64().unwrap() - }; - assert!((sampled_level - 63.75).abs() < 0.3, "sample the plane's 25% gray, not the colour layer: {after}"); - for key in ["red", "green", "blue"] { - assert_eq!(before[key], after[key], "hidden {key} must not change"); - } - assert!(std::sync::Arc::ptr_eq(&original, &h.state().session.active().unwrap().doc)); - let id = top(&h); - confirm(&mut h, id).unwrap(); - assert!(value(h.state(), target) > 0.99, "{kind} {mode:?} {depth:?} {target:?}"); - assert_eq!(h.state().session.active().unwrap().doc.layers[0].content, original.layers[0].content); - } + for target in TARGETS { + cases.push((kind, RGB_8.0, RGB_8.1, target)); } } + cases.extend([ + ("curves", ColorMode::Grayscale, SampleType::U16, ChannelTarget::LayerMask), + ("levels", ColorMode::Grayscale, SampleType::F32, ChannelTarget::Composite), + ("levels", ColorMode::Cmyk, SampleType::U16, ChannelTarget::Alpha(0)), + ("curves", ColorMode::Lab, SampleType::F32, ChannelTarget::Alpha(0)), + ]); + for (kind, mode, depth, target) in cases { + let mut h = open_on_canvas(fixture(mode, depth, target), kind); + assert!(h.get_by_label("Set Neutral Gray Point").accesskit_node().is_disabled()); + assert!(!h.get_by_label("Set White Point").accesskit_node().is_disabled()); + h.get_by_label("Set White Point").click(); + h.run_steps(2); + assert!(picker_armed(&h)); + let before = params(&h); + let original = h.state().session.active().unwrap().doc.clone(); + sample_at(&mut h, 4.0, 4.0); + let after = params(&h); + let key = if kind == "curves" { "points" } else { "inWhite" }; + assert_ne!(before[key], after[key], "{kind} {mode:?} {depth:?} {target:?}"); + let sampled_level = + if kind == "curves" { after["points"].as_array().unwrap().last().unwrap()[0].as_f64().unwrap() } else { after["inWhite"].as_f64().unwrap() }; + assert!((sampled_level - 63.75).abs() < 0.3, "sample the plane's 25% gray, not the colour layer: {after}"); + for key in ["red", "green", "blue"] { + assert_eq!(before[key], after[key], "hidden {key} must not change"); + } + assert!(std::sync::Arc::ptr_eq(&original, &h.state().session.active().unwrap().doc)); + let id = top(&h); + confirm(&mut h, id).unwrap(); + assert!(value(h.state(), target) > 0.99, "{kind} {mode:?} {depth:?} {target:?}"); + assert_eq!(h.state().session.active().unwrap().doc.layers[0].content, original.layers[0].content); + } } /// Replay a recorded tone step with its dialog enabled while a different channel is selected; `on_canvas` runs the @@ -898,42 +905,50 @@ fn filter_mask_fixture(mode: ColorMode, depth: SampleType, stored: bool) -> Box< app } -/// New upstream filter masks use the same scalar controls, picker and preserved targeting in every document space. +/// New upstream filter masks use the same scalar controls, picker and preserved targeting: both dialogs with a stored +/// and an implicit mask on an RGB document, and a grayscale document once. Every mode and depth is the engine's +/// `filter_mask_picker_samples_and_edits_only_the_filter_mask` (see [`RGB_8`]). #[test] fn filter_mask_tone_dialogs_preserve_the_target_and_sample_its_own_levels() { - for (mode, depth) in GRAY_MODE_DEPTHS { - for kind in ["levels", "curves"] { - for stored in [false, true] { - let app = filter_mask_fixture(mode, depth, stored); - let st = app.session.active().unwrap(); - let layer = st.active_layer.unwrap(); - let expected_name = format!("{} Filter Mask", st.doc.layer(layer).unwrap().name); - let before = st.doc.clone(); - let mut h = open_on_canvas(app, kind); - assert_eq!(names(&h), [expected_name], "{mode:?} {depth:?} {kind}"); - assert_eq!(params(&h)["target"], "filterMask"); - let id = top(&h); - arm(&mut h, "white"); - sample_at(&mut h, 4.0, 4.0); - assert!(picker_armed(&h), "the picker stays armed on {mode:?} {depth:?} stored={stored}"); - assert!(std::sync::Arc::ptr_eq(&before, &h.state().session.active().unwrap().doc), "sampling is read-only"); - assert_eq!(params(&h)["target"], "filterMask"); - if kind == "levels" { - let expected = if stored { 64.0 } else { 255.0 }; - assert!((params(&h)["inWhite"].as_f64().unwrap() - expected).abs() < 1.0); - } - confirm(&mut h, id).unwrap(); - let after = &h.state().session.active().unwrap().doc; - let LayerContent::Smart(old) = &before.layer(layer).unwrap().content else { panic!("smart fixture") }; - let LayerContent::Smart(new) = &after.layer(layer).unwrap().content else { panic!("smart result") }; - assert_eq!(new.smart_filters, old.smart_filters, "the adjustment edits the mask rather than adding a filter"); - assert_eq!(new.source, old.source); - assert_eq!(after.channels, before.channels); - assert_eq!(after.layer(layer).unwrap().mask, before.layer(layer).unwrap().mask); - assert!(new.filter_mask.as_ref().unwrap().surface.sample_channel(8, 8, 0) > 0.99); - } + let mut cases = Vec::new(); + for kind in ["levels", "curves"] { + for stored in [false, true] { + cases.push((RGB_8, kind, stored)); } } + cases.push(((ColorMode::Grayscale, SampleType::U16), "levels", true)); + for ((mode, depth), kind, stored) in cases { + let app = filter_mask_fixture(mode, depth, stored); + let st = app.session.active().unwrap(); + let layer = st.active_layer.unwrap(); + let expected_name = format!("{} Filter Mask", st.doc.layer(layer).unwrap().name); + let before = st.doc.clone(); + let mut h = open_on_canvas(app, kind); + assert_eq!(names(&h), [expected_name], "{mode:?} {depth:?} {kind}"); + assert_eq!(params(&h)["target"], "filterMask"); + let id = top(&h); + arm(&mut h, "white"); + sample_at(&mut h, 4.0, 4.0); + assert!(picker_armed(&h), "the picker stays armed on {mode:?} {depth:?} stored={stored}"); + assert!(std::sync::Arc::ptr_eq(&before, &h.state().session.active().unwrap().doc), "sampling is read-only"); + assert_eq!(params(&h)["target"], "filterMask"); + let white = if stored { 64.0 } else { 255.0 }; + let sampled = if kind == "levels" { + params(&h)["inWhite"].as_f64().unwrap() + } else { + params(&h)["points"].as_array().unwrap().last().unwrap()[0].as_f64().unwrap() + }; + assert!((sampled - white).abs() < 1.0, "{mode:?} {depth:?} {kind} stored={stored}: sampled {sampled}, want {white}"); + confirm(&mut h, id).unwrap(); + let after = &h.state().session.active().unwrap().doc; + let LayerContent::Smart(old) = &before.layer(layer).unwrap().content else { panic!("smart fixture") }; + let LayerContent::Smart(new) = &after.layer(layer).unwrap().content else { panic!("smart result") }; + assert_eq!(new.smart_filters, old.smart_filters, "the adjustment edits the mask rather than adding a filter"); + assert_eq!(new.source, old.source); + assert_eq!(after.channels, before.channels); + assert_eq!(after.layer(layer).unwrap().mask, before.layer(layer).unwrap().mask); + assert!(new.filter_mask.as_ref().unwrap().surface.sample_channel(8, 8, 0) > 0.99); + } } /// A recorded alpha address takes precedence over the currently selected filter mask. @@ -1123,49 +1138,53 @@ fn addressed_mask_app(mode: ColorMode, depth: SampleType, filter: bool) -> (Box< /// switching the selected layer. The matrix includes native raster and Smart Filter masks. #[test] fn review_mask_action_context_matches_the_addressed_layer() { - for (pair, (mode, depth)) in MODE_DEPTHS.into_iter().enumerate() { - for kind in ["levels", "curves"] { - for filter in [false, true] { - let (app, layer) = addressed_mask_app(mode, depth, filter); - // Resolving the address does not depend on the mode or depth: every selector form on the first pair. - let selectors = [json!(layer.0), json!("Receiver"), json!({"name":"Receiver"})]; - for selector in selectors.into_iter().take(if pair == 0 { 3 } else { 1 }) { - 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); - } - } + // 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 (app, layer) = addressed_mask_app(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 }) { + 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); } } }