From e6a58842f36794eafa1b3fa953e580a361cf733b Mon Sep 17 00:00:00 2001 From: aiongg Date: Wed, 18 Nov 2026 20:28:54 +0000 Subject: [PATCH 1/7] ui: build the toolbar's slots once per preferences revision The toolbar, its measure and the dock's grid each resolved the stored layout (tool_layout, layout_sections, Tool::from_name per name) several times a frame. The slots depend only on the preferences' toolbar layout, so the app keeps them with the PrefsStore revision they were built at. --- crates/engine/src/prefs.rs | 4 ++-- crates/ui-egui/src/app.rs | 1 + crates/ui-egui/src/lib.rs | 2 ++ crates/ui-egui/src/panels/tool_commands.rs | 22 ++++++++++++++++++++++ crates/ui-egui/src/panels/toolbar.rs | 8 ++++---- crates/ui-egui/src/state/tool.rs | 3 ++- 6 files changed, 33 insertions(+), 7 deletions(-) diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rs index 1412f1406a..86ce38741b 100644 --- a/crates/engine/src/prefs.rs +++ b/crates/engine/src/prefs.rs @@ -1413,8 +1413,8 @@ impl ToolbarCustomization { /// works with or without "Tool". `None` for a name that isn't a tool. pub fn tool_name(name: &str) -> Option { let canonical = |key: &str| -> String { key.chars().take(1).flat_map(char::to_uppercase).chain(key.chars().skip(1)).collect() }; - // Stored layouts hold canonical names: find those without allocating (the toolbar - // resolves its layout every frame). + // Stored layouts hold canonical names: find those without allocating (every layout + // resolves each of its names here). if let Some(key) = crate::shell_commands::TOOLS.iter().filter_map(|(id, _, _)| id.strip_prefix("tools.select.")).find(|k| k.eq_ignore_ascii_case(name)) { return Some(canonical(key)); diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 50e17e2a46..f65417fd5c 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -69,6 +69,7 @@ impl PhotocraftApp { remove_pending_target: None, remove_trail: None, menu_model: None, + toolbar_slots: Default::default(), move_preview: None, move_hover: None, move_distance: None, diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 63c87c0551..ab76978eed 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -351,6 +351,8 @@ pub struct PhotocraftApp { /// The menu bar's rows and the English text of its titles, rebuilt when their inputs change /// (`menus::MenuModel`). pub(crate) menu_model: Option, + /// The toolbar's slots for the stored layout (`tool_commands::ToolbarSlots`). + pub(crate) toolbar_slots: panels::tool_commands::ToolbarSlots, /// Move tool drag shown live (`move_ui`). pub(crate) move_preview: Option, /// Move tool › Show Highlight on Rollover: the last hover answer (`move_hover`). diff --git a/crates/ui-egui/src/panels/tool_commands.rs b/crates/ui-egui/src/panels/tool_commands.rs index 68e63869f2..453e98fa4b 100644 --- a/crates/ui-egui/src/panels/tool_commands.rs +++ b/crates/ui-egui/src/panels/tool_commands.rs @@ -338,6 +338,28 @@ pub(crate) fn slots(toolbar: &ToolbarCustomization) -> Vec> { slots } +/// The rail's [`slots`] for the stored layout, built once per preferences revision ([`PrefsStore::rev`]): the toolbar, its +/// measure and the dock's grid read them several times a frame, and the layout changes only with the preferences. +/// +/// [`PrefsStore::rev`]: photocraft_engine::prefs::PrefsStore::rev +#[derive(Default)] +pub(crate) struct ToolbarSlots(std::cell::RefCell]>)>>); + +impl ToolbarSlots { + /// The slots of `prefs`' toolbar layout. + pub(crate) fn get(&self, prefs: &photocraft_engine::prefs::PrefsStore) -> std::sync::Arc<[ToolSlot]> { + let mut held = self.0.borrow_mut(); + match &*held { + Some((rev, slots)) if *rev == prefs.rev() => slots.clone(), + _ => { + let built: std::sync::Arc<[ToolSlot]> = slots(&prefs.get().toolbar).into(); + *held = Some((prefs.rev(), built.clone())); + built + } + } + } +} + /// `slots` as the group layout `edit.toolbar {"toolbar": ..}` stores: one list of `Tool` names per slot. pub(crate) fn saved_groups(slots: &[ToolSlot]) -> serde_json::Value { slots.iter().map(|slot| slot.tools.iter().map(|tool| format!("{:?}", tool.id)).collect::>()).collect() diff --git a/crates/ui-egui/src/panels/toolbar.rs b/crates/ui-egui/src/panels/toolbar.rs index acb14c1d00..b239bcf3d0 100644 --- a/crates/ui-egui/src/panels/toolbar.rs +++ b/crates/ui-egui/src/panels/toolbar.rs @@ -140,7 +140,7 @@ fn last_used(slots: &[ToolSlot], group_tools: &[Tool]) -> LastUsed { /// The cells of the toolbar's grid: its visible slots and the Edit Toolbar button. The dock column's width in steps goes /// up to this many content columns. pub(crate) fn cells(app: &PhotocraftApp) -> usize { - visible_slots(&tool_commands::slots(&app.session.prefs().toolbar), &[]).len() + 1 + visible_slots(&app.toolbar_slots.get(&app.session.prefs), &[]).len() + 1 } /// The Edit in Quick Mask Mode command, which the rail's footer shows as a rail button. @@ -181,7 +181,7 @@ fn footer(app: &mut PhotocraftApp, ui: &mut egui::Ui, rail: RailFooter) { /// The height of the toolbar's rail laid out `width` wide: as many tool columns as `width` holds, with the footer. pub(crate) fn measure(app: &mut PhotocraftApp, ui: &egui::Ui, width: f32) -> f32 { - let slots = tool_commands::slots(&app.session.prefs().toolbar); + let slots = app.toolbar_slots.get(&app.session.prefs); let remembered = last_used(&slots, &app.ui.group_tools); let current = app.ui.tool; let (opens, editing) = (crate::panel_docking::toolbar_opens(app), app.ui.toolbar_drawer); @@ -196,7 +196,7 @@ pub(crate) fn measure(app: &mut PhotocraftApp, ui: &egui::Ui, width: f32) -> f32 /// remembered tools are read again at the start of each pass, so a second pass applies only its own input. pub fn toolbar(app: &mut PhotocraftApp, ui: &mut egui::Ui) { let ctx = ui.ctx().clone(); - let slots = tool_commands::slots(&app.session.prefs().toolbar); + let slots = app.toolbar_slots.get(&app.session.prefs); let remembered = last_used(&slots, &app.ui.group_tools); let current = app.ui.tool; let (opens, editing) = (crate::panel_docking::toolbar_opens(app), app.ui.toolbar_drawer); @@ -217,7 +217,7 @@ pub fn toolbar(app: &mut PhotocraftApp, ui: &mut egui::Ui) { _ => {} } if let Some(next) = &out.last_used { - for slot in &slots { + for slot in slots.iter() { if let Some(tool) = next.get(slot.id) && remembered.get(slot.id) != Some(tool) { diff --git a/crates/ui-egui/src/state/tool.rs b/crates/ui-egui/src/state/tool.rs index ec6be52664..f68a0ece96 100644 --- a/crates/ui-egui/src/state/tool.rs +++ b/crates/ui-egui/src/state/tool.rs @@ -320,7 +320,8 @@ impl Tool { /// The tool `s` names: its variant name, that name without "marquee", or its label, in any case and with spaces, /// `_` and `-` ignored. The first tool of [`Tool::ALL`] a spelling names wins. pub fn from_name(s: &str) -> Option { - // The toolbar resolves its whole layout through here every frame: one table instead of formatting every tool's names per lookup. + // Panels resolve tool names per row as they draw, and the command gate per tool command: one table instead of + // formatting every tool's names per lookup. static NAMES: std::sync::OnceLock> = std::sync::OnceLock::new(); let names = NAMES.get_or_init(|| { let mut names = std::collections::HashMap::new(); From 5a0ba0940884b0d5ecffbd188f6f8172f2a10744 Mon Sep 17 00:00:00 2001 From: aiongg Date: Wed, 18 Nov 2026 20:30:10 +0000 Subject: [PATCH 2/7] ui: is_live tests the hash tables and prefixes before the row scans The command gate asks is_live for every command a pass resolves. The engine catalogue, the shell's commands and the prefix tests answer for most live ids; the linear scans (bridged rows, view and workspace commands, which builds a CommandRef) now run last. Same answers. --- crates/ui-egui/src/menus/items.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/menus/items.rs b/crates/ui-egui/src/menus/items.rs index fa6bb6f12a..6ed2a6741a 100644 --- a/crates/ui-egui/src/menus/items.rs +++ b/crates/ui-egui/src/menus/items.rs @@ -13,22 +13,24 @@ use super::state::{checked, is_enabled, reveal_label, translated_menu_label}; use super::{DOCUMENT_ITEM, PhotocraftApp, TOP_MENUS, UI_COMMANDS}; /// Is `id` implemented by the engine or the shell (a live menu item)? Shared by the menus and -/// the parity report ([`crate::parity`]). +/// the parity report ([`crate::parity`]). The command gate asks this for every command a pass +/// resolves, framework commands included, so the hash lookups and prefix tests come first and +/// the scans of the bridged rows and the workspace commands last. pub fn is_live(id: &str) -> bool { static UI_IDS: std::sync::OnceLock> = std::sync::OnceLock::new(); photocraft_engine::commands::find(id).is_some() - || crate::tool_shortcuts::tool(id).is_some() || UI_IDS.get_or_init(|| UI_COMMANDS.iter().map(|c| c.0).collect()).contains(id) + || id.starts_with(super::DOCUMENT_ITEM) + || id == "view.proofSetup.custom" + || crate::tool_shortcuts::tool(id).is_some() || panel_alias(id).is_some() || crate::panel_docking::toggle_panel(id).is_some() || workspace_id(id).is_some() || proof_preset(id).is_some() - || id == "view.proofSetup.custom" - || crate::view_cmds::handles(id) || crate::analysis::handles(id) + || crate::view_cmds::handles(id) || crate::shortcut_dispatch::is_bridged(id) || crate::workspace_ui::handles(id) - || id.starts_with(super::DOCUMENT_ITEM) } /// Commands outside the catalogue that belong right after a catalogue item: `(id, after)`. From 837e19257c65bcffe7a916fc7bffc5de54f8bf9c Mon Sep 17 00:00:00 2001 From: aiongg Date: Wed, 18 Nov 2026 20:32:04 +0000 Subject: [PATCH 3/7] tests: the adjustment editors test runs one app per document every_adjustment_layer_edits_through_properties started the whole app for each of 16 kinds on each of 6 documents. It now starts one app per document and runs Undo back to the document before adding the next kind's layer, so every kind still meets the new document with its two tones. Cases and assertions are kept. --- .../src/dialogs/adjust_editors/ui_tests.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs b/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs index bc3155e39d..faa944fadb 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs @@ -134,11 +134,24 @@ fn sliders(h: &Harness<'_, Box>) -> Vec { /// Issue #12: every adjustment kind, on a new document at 8/16/32 bits and in RGB, Grayscale, /// CMYK and Lab, opens its Properties editor and takes an edit through real input without /// panicking; slider kinds commit exactly one history step per gesture and end the preview with it. +/// One app per document: Undo takes back each kind's layer and edit before the next kind's layer +/// is added, so every kind meets the new document with its two tones. #[test] fn every_adjustment_layer_edits_through_properties() { for (mode, depth) in [("rgb", 8), ("rgb", 16), ("rgb", 32), ("gray", 8), ("cmyk", 8), ("lab", 16)] { - for kind in ALL_KINDS { - let mut h = app_harness(kind, mode, depth); + let mut h = app_harness(ALL_KINDS[0], mode, depth); + // The document's history before its adjustment layer. + let base = history_len(&h) - 1; + for (i, kind) in ALL_KINDS.into_iter().enumerate() { + if i > 0 { + while history_len(&h) > base { + let steps = history_len(&h); + h.state_mut().run("edit.undo", json!({})).unwrap_or_else(|e| panic!("{kind} {mode}: undo: {e}")); + assert!(history_len(&h) < steps, "{kind} {mode}: undo to the new document"); + } + h.state_mut().run(&format!("layer.newAdjustmentLayer.{kind}"), json!({})).unwrap(); + h.run_steps(8); + } let (_, before) = layer(&h); let steps = history_len(&h); let slider = sliders(&h).first().copied(); From c1ab90aa35eb3eac34792c8bf993308352edcfea Mon Sep 17 00:00:00 2001 From: aiongg Date: Wed, 18 Nov 2026 20:33:05 +0000 Subject: [PATCH 4/7] tests: the exhaustive shortcut test sends each press as one frame's input Harness::event steps one frame per queued event, so a tap (modifiers, press, release, modifiers) plus its three steps ran six whole-app frames per shortcut. The dispatch test now queues the four events into one frame's input and runs the two frames the runtime and the app need to take the key and run its command. Every shortcut, place and assertion stays. --- .../src/input/shortcut_dispatch/tests.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/input/shortcut_dispatch/tests.rs b/crates/ui-egui/src/input/shortcut_dispatch/tests.rs index 9d9dd2f319..6561866c34 100644 --- a/crates/ui-egui/src/input/shortcut_dispatch/tests.rs +++ b/crates/ui-egui/src/input/shortcut_dispatch/tests.rs @@ -84,6 +84,19 @@ fn press(h: &mut Harness<'_, Box>, sc: &str) { tap(h, sc.logical_key, sc.modifiers); } +/// Queue one press/release in one input frame, then let the runtime collect and the app dispatch it. +fn press_in_one_frame(h: &mut Harness<'_, Box>, sc: &str) { + let sc = parse(sc).unwrap_or_else(|| panic!("unparsable shortcut {sc}")); + let m = platform(sc.modifiers); + h.input_mut().events.extend([ + egui::Event::ModifiersChanged(m), + egui::Event::Key { key: sc.logical_key, physical_key: None, pressed: true, repeat: false, modifiers: m }, + egui::Event::Key { key: sc.logical_key, physical_key: None, pressed: false, repeat: false, modifiers: m }, + egui::Event::ModifiersChanged(Modifiers::NONE), + ]); + h.run_steps(2); +} + fn click(h: &mut Harness<'_, Box>, at: Pos2) { h.hover_at(at); h.run_steps(1); @@ -211,7 +224,7 @@ fn every_displayed_shortcut_dispatches_from_where_focus_usually_is() { // 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); + press_in_one_frame(&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. @@ -232,7 +245,7 @@ fn every_displayed_shortcut_dispatches_from_where_focus_usually_is() { 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()); + press_in_one_frame(&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)); } From d83654889eb9c8535defe90c0e951402d4b43bee Mon Sep 17 00:00:00 2001 From: aiongg Date: Wed, 18 Nov 2026 20:34:40 +0000 Subject: [PATCH 5/7] tests: the slow tone_targets tests run their cases on one app The grayscale picker, filter mask and addressed mask tests started an app for every case. Each now keeps one canvas harness and opens each case's fixture document in it as a new document, after closing the last case's and clearing what a case leaves: the actions, the Layers panel's mask targets and the tone dialogs' last-used settings. Cases and assertions are kept. --- crates/ui-egui/tests/it/tone_targets.rs | 143 ++++++++++++++++-------- 1 file changed, 97 insertions(+), 46 deletions(-) diff --git a/crates/ui-egui/tests/it/tone_targets.rs b/crates/ui-egui/tests/it/tone_targets.rs index b1db0eaab7..7e56445c20 100644 --- a/crates/ui-egui/tests/it/tone_targets.rs +++ b/crates/ui-egui/tests/it/tone_targets.rs @@ -8,7 +8,7 @@ use egui_kittest::{ kittest::{NodeT, Queryable}, }; use photocraft_color::{ColorMode, PixelFormat, SampleType}; -use photocraft_doc::{AlphaChannel, Document, Layer, LayerContent, LayerMask}; +use photocraft_doc::{AlphaChannel, DocId, Document, Layer, LayerContent, LayerMask}; use photocraft_engine::{Session, actions_cmds::Action, channel_cmds::ChannelTarget}; use photocraft_geom::Size; use photocraft_raster::Surface; @@ -34,6 +34,18 @@ const DIALOG_STATE: [&str; 4] = ["preview", "picker", "channel", "clipping"]; /// Build a native-depth document with distinct colour pixels, a named alpha, a layer mask and optional Quick Mask. fn fixture(mode: ColorMode, depth: SampleType, target: ChannelTarget) -> Box { + app_of(fixture_session(mode, depth, target)) +} + +/// The app over a fixture's session, its jobs run in place. +fn app_of(session: Session) -> Box { + let mut app = PhotocraftApp::new(session, Default::default()); + app.background_jobs = false; + app +} + +/// [`fixture`]'s session. +fn fixture_session(mode: ColorMode, depth: SampleType, target: ChannelTarget) -> Session { let mut doc = Document::new("Tone targets", Size::new(32, 32), mode, depth); let mut pixels = Surface::new(PixelFormat::new(mode, depth, true)); pixels.fill_rect( @@ -59,9 +71,7 @@ fn fixture(mode: ColorMode, depth: SampleType, target: ChannelTarget) -> Box) -> Harness<'static, Box>) { + let reply = control(h, "ui.set", json!({"zoom": 12, "center": [38, 16]})); + assert_eq!(reply["ok"], true, "the view zooms: {reply}"); +} + +/// One [`canvas_harness`] for all the cases of a test: [`next_case`] puts each case's document in it. +fn bench() -> Harness<'static, Box> { + canvas_harness(fixture(ColorMode::Rgb, SampleType::U8, ChannelTarget::Composite)) +} + +/// The next case of a test on the bench `h`: the active document of `from` (a fixture's session) opens as a new +/// document in place of what `h` shows, with its active layer and channel target, and `filter_mask` is the Layers +/// panel's filter mask target. What an earlier case left goes first: the open documents, the actions, the Layers +/// panel's mask targets and the tone dialogs' last-used settings. +fn next_case(h: &mut Harness<'static, Box>, from: &Session, filter_mask: Option) { + for kind in ["levels", "curves"] { + set_saved_value(&h.ctx, &adjust_dialog::last_key(kind), None::); + } + let app = h.state_mut(); + assert_eq!(app.dialog_count(), 0, "the last case closed its dialog"); + while app.session.close(0).is_some() {} + let st = from.active().unwrap(); + let mut doc = (*st.doc).clone(); + // A document of its own, as in a case's own app: nothing the app keeps per document carries over. + doc.id = DocId::fresh(); + app.session.add_document(doc, None); + app.session.select_layer(st.active_layer.unwrap()).unwrap(); + app.session.active_mut().unwrap().channel_view = st.channel_view.clone(); + app.session.actions = from.actions.clone(); + app.ui.mask_target = false; + app.ui.vector_mask_target = false; + app.ui.filter_mask_target = filter_mask; + app.sync_views(); + h.run_steps(3); + show_left_of_dialog(h); +} + /// Open a neutral tone dialog on `h` and settle its layout before interacting with controls. fn open_in(mut h: Harness<'static, Box>, kind: &str) -> Harness<'static, Box> { + open_here(&mut h, kind); + h +} + +/// [`open_in`] on a harness kept for more cases. +fn open_here(h: &mut Harness<'static, Box>, kind: &str) { adjust_dialog::open(h.state_mut(), &format!("image.adjustments.{kind}")).unwrap(); h.run_steps(4); - h } /// Open a neutral tone dialog and settle its layout before interacting with controls. @@ -420,10 +471,12 @@ fn levels_auto_uses_the_selected_colour_channels_histogram() { /// Black/white picker controls sample the gray plane and update the visible neutral curve. #[test] fn grayscale_picker_controls_sample_the_plane_and_change_the_visible_curve() { + let mut h = bench(); 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); + next_case(&mut h, &fixture_session(mode, depth, target), None); + open_here(&mut h, 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(); @@ -888,30 +941,39 @@ fn last_tone_settings_on_grayscale_pixels_drop_hidden_colour_records() { /// Build a filtered smart object with a selected filter mask, optionally still the implicit reveal-all mask. fn filter_mask_fixture(mode: ColorMode, depth: SampleType, stored: bool) -> Box { - let mut app = fixture(mode, depth, ChannelTarget::Color(0)); - app.session.active_mut().unwrap().channel_view.target = ChannelTarget::Composite; - app.run("layer.smartObjects.convertToSmartObject", json!({})).unwrap(); - app.run("filter.blur.gaussianBlur", json!({"radius":1})).unwrap(); - let id = app.session.active().unwrap().active_layer.unwrap(); - if stored { - app.run("edit.fill", json!({"target":"filterMask","contents":"color","color":"#404040"})).unwrap(); - } + let (session, id) = filter_mask_session(mode, depth, stored); + let mut app = app_of(session); app.ui.filter_mask_target = Some(id.0); app } +/// [`filter_mask_fixture`]'s session and the smart object, whose filter mask the Layers panel targets. +fn filter_mask_session(mode: ColorMode, depth: SampleType, stored: bool) -> (Session, photocraft_doc::LayerId) { + let mut session = fixture_session(mode, depth, ChannelTarget::Color(0)); + session.active_mut().unwrap().channel_view.target = ChannelTarget::Composite; + session.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap(); + session.execute("filter.blur.gaussianBlur", json!({"radius":1})).unwrap(); + let id = session.active().unwrap().active_layer.unwrap(); + if stored { + session.execute("edit.fill", json!({"target":"filterMask","contents":"color","color":"#404040"})).unwrap(); + } + (session, id) +} + /// New upstream filter masks use the same scalar controls, picker and preserved targeting in every document space. #[test] fn filter_mask_tone_dialogs_preserve_the_target_and_sample_its_own_levels() { + let mut h = bench(); 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 (session, id) = filter_mask_session(mode, depth, stored); + next_case(&mut h, &session, Some(id.0)); + let st = h.state().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); + open_here(&mut h, kind); assert_eq!(names(&h), [expected_name], "{mode:?} {depth:?} {kind}"); assert_eq!(params(&h)["target"], "filterMask"); let id = top(&h); @@ -1096,15 +1158,16 @@ fn review_precise_action_settings_survive_last_used_recall() { } } -/// Build distinct active and addressed masks, retaining the active layer and panel target. -fn addressed_mask_app(mode: ColorMode, depth: SampleType, filter: bool) -> (Box, photocraft_doc::LayerId) { - let mut app = if filter { filter_mask_fixture(mode, depth, true) } else { fixture(mode, depth, ChannelTarget::Alpha(0)) }; - let mut other = app.session.active().unwrap().doc.layers[0].clone(); +/// Build distinct active and addressed masks, retaining the active layer. The session holds the document, the id is +/// the addressed layer's. +fn addressed_mask_session(mode: ColorMode, depth: SampleType, filter: bool) -> (Session, photocraft_doc::LayerId) { + let mut session = if filter { filter_mask_session(mode, depth, true).0 } else { fixture_session(mode, depth, ChannelTarget::Alpha(0)) }; + let mut other = session.active().unwrap().doc.layers[0].clone(); other.id = Layer::new("id", other.content.clone()).id; other.name = "Receiver".into(); let mut mask = LayerMask::reveal_all(); mask.surface = Surface::new(PixelFormat::new(ColorMode::Grayscale, depth, false)); - mask.surface.fill_rect(app.session.active().unwrap().doc.bounds(), &[0.75]); + mask.surface.fill_rect(session.active().unwrap().doc.bounds(), &[0.75]); if filter { let LayerContent::Smart(sm) = &mut other.content else { panic!("smart") }; sm.filter_mask = Some(mask); @@ -1112,36 +1175,36 @@ fn addressed_mask_app(mode: ColorMode, depth: SampleType, filter: bool) -> (Box< other.mask = Some(mask); } let id = other.id; - app.session + session .edit("Other mask", |doc, _| { doc.layers.push(other); Ok(()) }) .unwrap(); - (app, id) + (session, id) } /// 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() { + let mut h = bench(); 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); + let (source, layer) = addressed_mask_session(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); + 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(&mut app, "Other mask", command.clone(), raw, true); - let original = app.session.active().unwrap().doc.clone(); - let active = app.session.active().unwrap().active_layer; + 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); - 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); @@ -1172,18 +1235,6 @@ fn review_mask_action_context_matches_the_addressed_layer() { } } -/// 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(); - let mut s = Session::new(); - s.add_document((*st.doc).clone(), None); - s.select_layer(st.active_layer.unwrap()).unwrap(); - s.active_mut().unwrap().channel_view = st.channel_view.clone(); - let mut result = PhotocraftApp::new(s, Default::default()); - result.background_jobs = false; - result -} - /// Repairing a missing Action address re-seeds its recorded alias without losing modal context. #[test] fn review_repaired_action_target_seeds_recorded_controls() { From aa9648185a0387675917848e6dcd16c653fd5259 Mon Sep 17 00:00:00 2001 From: aiongg Date: Wed, 18 Nov 2026 20:36:32 +0000 Subject: [PATCH 6/7] tests: the caret font test runs its 18 cases on one app caret_font_choices_style_only_subsequent_typing_including_ime started the whole app for each font, text and caret. It now keeps one app with the fixture's document: Undo takes each case's text layer back before the next case makes its own, so every case starts from the same document. The fixture builds the same app and layer through the two steps the test shares. Cases and assertions are kept. --- .../src/tools/type_tool/font_commit_tests.rs | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 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 cddbe532c2..dcc72c211d 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 @@ -66,17 +66,29 @@ fn surrender_focus(h: &mut H) { /// A text layer `content` in an edit session in `FONTS[pattern % 2]`; patterns 2 and 3 style characters 2..4 in the other font. /// The full app frame, so the options bar and the Character panel both show their family fields. fn fixture(pattern: usize, content: &str) -> (H, LayerId) { - let content = content.to_owned(); - let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).with_max_steps(64).build_eframe(move |cc| { + let mut h = document(); + let id = text_layer(&mut h, pattern, content); + (h, id) +} + +/// [`fixture`]'s app with its document and the Type tool, before the text layer. +fn document() -> H { + Harness::builder().with_size(vec2(1600.0, 1000.0)).with_max_steps(64).build_eframe(move |cc| { PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); let mut app = PhotocraftApp::with_context(cc.egui_ctx.clone(), photocraft_engine::Session::new(), Services::default()); app.session.edit_prefs(|p| p.type_.font_preview = photocraft_engine::prefs::FontPreview::Off); app.run("file.new", json!({"width": 240, "height": 160})).unwrap(); app.sync_views(); app.ui.tool = crate::state::Tool::Type; - app.run("type.create", json!({"text": content, "font": FONTS[pattern % 2], "size": 18})).unwrap(); app - }); + }) +} + +/// [`fixture`]'s text layer, made on `h` and edited. +fn text_layer(h: &mut H, pattern: usize, content: &str) -> LayerId { + h.state_mut().run("type.create", json!({"text": content, "font": FONTS[pattern % 2], "size": 18})).unwrap(); + // Settle as the harness does after its first frame. + let _ = h.run_ok(); let id = h.state().session.active().unwrap().active_layer.unwrap(); let ctx = h.ctx.clone(); super::edit_active(h.state_mut(), &ctx).unwrap(); @@ -85,7 +97,22 @@ fn fixture(pattern: usize, content: &str) -> (H, LayerId) { h.state_mut().run("type.setStyle", json!({"layer": id.0, "range": [2, 4], "font": FONTS[1 - pattern % 2], "coalesce": key})).unwrap(); } h.run_steps(3); - (h, id) + id +} + +/// The past states of the document's history. +fn past_len(h: &H) -> usize { + h.state().session.active().unwrap().history.past_len() +} + +/// Undo back to `steps` past states: the document before the last case's text layer. +fn undo_to(h: &mut H, steps: usize) { + while past_len(h) > steps { + let before = past_len(h); + h.state_mut().run("edit.undo", json!({})).unwrap_or_else(|e| panic!("undo: {e}")); + assert!(past_len(h) < before, "Undo takes back the last case"); + } + let _ = h.run_ok(); } /// Picks `font` in the first family field: open it, type the name, Enter, as `accept` says. @@ -111,11 +138,15 @@ fn checkmark(h: &mut H) { #[test] fn caret_font_choices_style_only_subsequent_typing_including_ime() { + // One app: each case's text layer goes with Undo before the next case makes its own. + let mut h = document(); + let base = past_len(&h); 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] { - let (mut h, id) = fixture(original, text); + undo_to(&mut h, base); + let id = text_layer(&mut h, original, text); select(&mut h, [caret, caret]); h.run(); let before = saved(&h, id); From bd3712d114382570d6ade7b8ca3c81d6ab3ae367 Mon Sep 17 00:00:00 2001 From: aiongg Date: Wed, 18 Nov 2026 21:20:35 +0000 Subject: [PATCH 7/7] Lint: each shared test fixture loads once per test binary, and xtask names its step list type --- crates/automation/tests/it/main.rs | 4 ++++ crates/automation/tests/it/smart_filter_authorization.rs | 3 +-- crates/automation/tests/it/smart_filter_stack_cache.rs | 3 +-- crates/automation/tests/support/smart_filter_fixture.rs | 4 ++-- crates/engine/tests/it/atn_shape_blur.rs | 3 +-- crates/engine/tests/it/csh_import.rs | 3 +-- crates/engine/tests/it/main.rs | 4 ++++ xtask/src/main.rs | 8 +++++--- 8 files changed, 19 insertions(+), 13 deletions(-) diff --git a/crates/automation/tests/it/main.rs b/crates/automation/tests/it/main.rs index f83222b58d..c7d055e14d 100644 --- a/crates/automation/tests/it/main.rs +++ b/crates/automation/tests/it/main.rs @@ -25,3 +25,7 @@ mod save_snapshot; mod scratch_save; mod smart_filter_authorization; mod smart_filter_stack_cache; + +// Shared by smart_filter_authorization and smart_filter_stack_cache. +#[path = "../support/smart_filter_fixture.rs"] +mod smart_filter_fixture; diff --git a/crates/automation/tests/it/smart_filter_authorization.rs b/crates/automation/tests/it/smart_filter_authorization.rs index ed25ed7658..2ad83f4bba 100644 --- a/crates/automation/tests/it/smart_filter_authorization.rs +++ b/crates/automation/tests/it/smart_filter_authorization.rs @@ -2,8 +2,7 @@ use std::path::Path; use std::sync::Arc; -#[path = "../support/smart_filter_fixture.rs"] -mod fixture; +use crate::smart_filter_fixture as fixture; use fixture::{Fixture, assert_denied, cube, path_params}; use photocraft_automation::{Headless, workspace::authorize_desktop_engine_step}; diff --git a/crates/automation/tests/it/smart_filter_stack_cache.rs b/crates/automation/tests/it/smart_filter_stack_cache.rs index f9ab205c2c..a89a8450bc 100644 --- a/crates/automation/tests/it/smart_filter_stack_cache.rs +++ b/crates/automation/tests/it/smart_filter_stack_cache.rs @@ -4,8 +4,7 @@ use photocraft_automation::workspace::authorize_desktop_engine_step; use photocraft_engine::{Session, smart_cmds}; use serde_json::json; -#[path = "../support/smart_filter_fixture.rs"] -mod fixture; +use crate::smart_filter_fixture as fixture; use fixture::{Fixture, assert_denied}; diff --git a/crates/automation/tests/support/smart_filter_fixture.rs b/crates/automation/tests/support/smart_filter_fixture.rs index 26d5cab27b..a78ee43216 100644 --- a/crates/automation/tests/support/smart_filter_fixture.rs +++ b/crates/automation/tests/support/smart_filter_fixture.rs @@ -1,6 +1,6 @@ //! The smart filter authorization tests' fixture: a workspace with a striped image to place and -//! maps and LUTs outside it (`#[path]`-included by `it/smart_filter_authorization.rs` and -//! `smart_filter_stack_cache.rs`). +//! maps and LUTs outside it (`#[path]`-included once by `it/main.rs`, used by +//! `smart_filter_authorization` and `smart_filter_stack_cache`). use std::path::{Path, PathBuf}; use std::sync::atomic::{AtomicU64, Ordering}; diff --git a/crates/engine/tests/it/atn_shape_blur.rs b/crates/engine/tests/it/atn_shape_blur.rs index 529243cb2f..d9b25ea0cc 100644 --- a/crates/engine/tests/it/atn_shape_blur.rs +++ b/crates/engine/tests/it/atn_shape_blur.rs @@ -5,8 +5,7 @@ use photocraft_engine::actions_cmds::{ActionList, ActionsFile}; use photocraft_engine::{Session, atn_cmds}; use serde_json::json; -#[path = "../common/csh_fixture.rs"] -mod csh_fixture; +use crate::csh_fixture; const SHAPE_ID: &str = "original-fixture-square"; diff --git a/crates/engine/tests/it/csh_import.rs b/crates/engine/tests/it/csh_import.rs index e3e31fa539..7bcf40ea21 100644 --- a/crates/engine/tests/it/csh_import.rs +++ b/crates/engine/tests/it/csh_import.rs @@ -4,8 +4,7 @@ use photocraft_engine::Session; use serde_json::json; -#[path = "../common/csh_fixture.rs"] -mod fixture; +use crate::csh_fixture as fixture; use fixture::{polygon_csh, triangle_csh}; #[test] diff --git a/crates/engine/tests/it/main.rs b/crates/engine/tests/it/main.rs index 3bcc48ca68..32c55b9ff4 100644 --- a/crates/engine/tests/it/main.rs +++ b/crates/engine/tests/it/main.rs @@ -133,3 +133,7 @@ mod vector_paste_options; mod wand_transparent_copy; mod working_rgb_profile; mod xmp_charref; + +// Shared by atn_shape_blur and csh_import. +#[path = "../common/csh_fixture.rs"] +mod csh_fixture; diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 9a7953dcbf..72abfd43dd 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -290,6 +290,8 @@ struct CiOptions { } type StepFn = fn(&CiOptions) -> Result<(), String>; +/// The steps a `cargo xtask ci` call runs, in order, by name. +type CiPlan = Vec<(&'static str, StepFn)>; /// The CI gate's steps, in the order `cargo xtask ci` runs them. const CI_STEPS: [(&str, Part, StepFn); 12] = [ @@ -462,7 +464,7 @@ fn ci_exclude() -> Vec { /// The steps `cargo xtask ci ` runs, and how: no argument runs every step; a part (`lint`, /// `build`, `tests`) runs the steps of one gate job; a step's name runs that step. -fn ci_from_args(args: &[&str], exclude: Vec) -> Result<(Vec<(&'static str, StepFn)>, CiOptions), String> { +fn ci_from_args(args: &[&str], exclude: Vec) -> Result<(CiPlan, CiOptions), String> { let mut options = CiOptions { build_only: false, partition: None, selection: Selection::All, exclude }; let mut what = None; for &arg in args { @@ -506,8 +508,8 @@ fn tests_partition(selection: Selection, env: Option) -> Option /// The steps of `parts`, in CI_STEPS order. When the tests are only built, the test steps become /// that one build. -fn ci_plan(parts: &[Part], build_only: bool) -> Vec<(&'static str, StepFn)> { - let mut plan: Vec<(&'static str, StepFn)> = Vec::new(); +fn ci_plan(parts: &[Part], build_only: bool) -> CiPlan { + let mut plan: CiPlan = Vec::new(); for &(name, part, f) in &CI_STEPS { if !parts.contains(&part) { continue;