diff --git a/crates/engine/src/actions_cmds.rs b/crates/engine/src/actions_cmds.rs index 414234db24..55c7264de5 100644 --- a/crates/engine/src/actions_cmds.rs +++ b/crates/engine/src/actions_cmds.rs @@ -68,7 +68,11 @@ pub fn replayable(id: &str) -> bool { // Again journals its concrete transform too; recording the wrapper would replay it twice. id == "actions.play" || (!id.starts_with("actions.") + // Browse executes its steps through Session::execute, so those concrete + // commands are already journaled. Recording the wrapper as well replays + // every script edit twice (#3057). && id != "edit.transform.again" + && id != "file.scripts.browse" && (shell_view_command(id) || shell_save_command(id) || crate::commands::find(id).is_some_and(|c| c.journal))) } diff --git a/crates/engine/src/automate_cmds/tests.rs b/crates/engine/src/automate_cmds/tests.rs index 73fb157c30..9259bdc8ee 100644 --- a/crates/engine/src/automate_cmds/tests.rs +++ b/crates/engine/src/automate_cmds/tests.rs @@ -54,6 +54,38 @@ fn browse_runs_a_script_file() { assert_eq!(r["results"].as_array().unwrap().len(), 1); } +#[test] +fn recording_browse_script_captures_each_effect_once() { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 12, "height": 8})).unwrap(); + s.execute("actions.record", json!({"name": "Rotate script"})).unwrap(); + let run = s.execute("file.scripts.browse", json!({"steps": [["image.imageRotation.90cw", {}]]})).unwrap(); + assert_eq!(run["ok"], true); + assert_eq!((s.active().unwrap().doc.size.width, s.active().unwrap().doc.size.height), (8, 12)); + let done = s.execute("actions.stop", json!({})).unwrap(); + assert_eq!(done["steps"], 1, "Browse must not be recorded a second time"); + let recorded = s.execute("actions.get", json!({"action": "Rotate script"})).unwrap(); + assert_eq!(recorded["steps"], json!([["image.imageRotation.90cw", {}]])); + + s.execute("image.imageRotation.90ccw", json!({})).unwrap(); + assert_eq!((s.active().unwrap().doc.size.width, s.active().unwrap().doc.size.height), (12, 8)); + let replay = s.execute("actions.play", json!({"action": "Rotate script"})).unwrap(); + assert_eq!(replay["ran"], 1); + assert_eq!((s.active().unwrap().doc.size.width, s.active().unwrap().doc.size.height), (8, 12)); +} + +#[test] +fn standalone_browse_script_still_runs_and_journals_concrete_commands() { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 12, "height": 8})).unwrap(); + let start = s.journal.len(); + let result = s.execute("file.scripts.browse", json!({"steps": [["image.imageRotation.90cw", {}]]})).unwrap(); + assert_eq!(result["ok"], true); + assert_eq!(s.journal.len(), start + 2, "the child and Browse retain their diagnostic journal entries"); + assert_eq!(s.journal[start].0, "image.imageRotation.90cw"); + assert_eq!((s.active().unwrap().doc.size.width, s.active().unwrap().doc.size.height), (8, 12)); +} + #[test] fn script_events_fire_on_new_and_close() { let mut s = Session::new();