From 1bee4f9bf4fae68ff7c7e142c56e4a0baa37295e Mon Sep 17 00:00:00 2001 From: yoriswind Date: Tue, 3 Nov 2026 21:19:51 -0800 Subject: [PATCH] Clarify paused playback policy compatibility --- crates/ui-egui/src/panels/actions.rs | 5 +-- crates/ui-egui/src/panels/actions/tests.rs | 42 ++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/panels/actions.rs b/crates/ui-egui/src/panels/actions.rs index d562fc46c12..b10c3e1c3ed 100644 --- a/crates/ui-egui/src/panels/actions.rs +++ b/crates/ui-egui/src/panels/actions.rs @@ -841,10 +841,11 @@ pub fn abandoned(app: &mut PhotocraftApp, fields: &serde_json::Map photocraft_engine::Result<()>; /// A function-pointer dispatch gate cannot carry two different policies into nested jobs. -/// A changed policy ends this continuation rather than choosing which policy to discard. +/// Changed gates and distinct simultaneous Session/service gates both end this continuation; +/// hosts that need both policies must supply one composed gate at both boundaries. fn continuation_gate(captured: Option, live: Option) -> Result, String> { if captured.zip(live).is_some_and(|(before, now)| !std::ptr::fn_addr_eq(before, now)) { - return Err("the authorization context changed while the action was paused".into()); + return Err("the authorization context changed or uses policies that cannot be combined for this paused action".into()); } Ok(live.or(captured)) } diff --git a/crates/ui-egui/src/panels/actions/tests.rs b/crates/ui-egui/src/panels/actions/tests.rs index 64cbdb46291..408df652916 100644 --- a/crates/ui-egui/src/panels/actions/tests.rs +++ b/crates/ui-egui/src/panels/actions/tests.rs @@ -2442,6 +2442,48 @@ fn unchanged_and_released_gates_allow_the_action_tail() { } } +#[test] +fn distinct_configured_gates_require_one_composed_policy_for_automated_resume() { + fn deny_file_open(id: &str, _: &Value) -> photocraft_engine::Result<()> { + if id == "file.open" { Err(photocraft_engine::EngineError::Other("file open denied".into())) } else { Ok(()) } + } + assert!(!std::ptr::fn_addr_eq(deny_wide_blur as Gate, deny_file_open as Gate)); + for automated in [false, true] { + let mut app = gated_blur_fixture(true, false); + app.session.actions.list[0].steps.push(("layer.renameLayer".into(), json!({"name":"Allowed tail"}))); + app.session.authorize = Some(deny_wide_blur); + app.services.automation_authorize = Some(deny_file_open); + // The service is configured before the real local pause, but becomes effective only + // for the automated OK. Both callbacks allow this edit and its remaining command. + for gate in [deny_wide_blur as Gate, deny_file_open as Gate] { + gate("filter.blur.gaussianBlur", &json!({"radius":1})).unwrap(); + gate("layer.renameLayer", &json!({"name":"Allowed tail"})).unwrap(); + } + let dialog = play(&mut app, &json!({"action":"Gated blur"})).unwrap()["paused"]["dialog"].as_u64().unwrap(); + let before = app.session.active().unwrap().doc.clone(); + let rows = app.session.active().unwrap().history.past_len(); + app.automation_input = automated; + let result = crate::dialogs::confirm(&mut app, dialog); + let state = app.session.active().unwrap(); + if automated { + assert!(result.is_err_and(|error| error.contains("policies that cannot be combined"))); + assert_eq!(state.doc.as_ref(), before.as_ref()); + assert_eq!(state.history.past_len(), rows); + assert!(app.session.job_on(before.id).is_none()); + } else { + result.unwrap(); + assert_eq!(state.doc.layer(state.active_layer.unwrap()).unwrap().name, "Allowed tail"); + assert_eq!(state.history.past_len(), rows + 1); + assert!(app.session.undo()); + assert_eq!(app.session.active().unwrap().doc.as_ref(), before.as_ref()); + } + assert!(std::ptr::fn_addr_eq(app.session.authorize.unwrap(), deny_wide_blur as Gate)); + assert!(std::ptr::fn_addr_eq(app.services.automation_authorize.unwrap(), deny_file_open as Gate)); + assert!(app.paused_playbacks.paused.is_empty()); + assert_eq!(app.session.actions.playing, 0); + } +} + #[test] fn a_changed_gate_after_the_last_spelling_step_keeps_completed_edits() { let (mut app, before, past) = paused_history_spelling(true, Some(deny_wide_blur));