From d77082dfd0f1243c6d7d015aee2468133f3dcfb5 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Tue, 10 Nov 2026 23:57:52 +0000 Subject: [PATCH] address review: Batch checks the authorization gate for each save point --- crates/engine/src/cmd/file_cmds/batch_run.rs | 4 ++++ crates/engine/src/cmd/file_cmds/tests.rs | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/crates/engine/src/cmd/file_cmds/batch_run.rs b/crates/engine/src/cmd/file_cmds/batch_run.rs index b65b67b607..c92151d8f1 100644 --- a/crates/engine/src/cmd/file_cmds/batch_run.rs +++ b/crates/engine/src/cmd/file_cmds/batch_run.rs @@ -309,6 +309,10 @@ pub(super) fn batch(s: &mut Session, p: &Value) -> Result { let mut saved: Option> = None; for (id, params) in &steps { if batch_save_point(id) { + // The scratch session never executes a save point, so the gate would not see it. + if let Some(gate) = scratch.authorize { + gate(id, params)?; + } let st = scratch.active_mut().ok_or(EngineError::NoDocument)?; saved = Some(st.doc.clone()); // Batch performs the action's Save / Save As (to its destination), so the diff --git a/crates/engine/src/cmd/file_cmds/tests.rs b/crates/engine/src/cmd/file_cmds/tests.rs index ab861f2eb8..1b0f576f8f 100644 --- a/crates/engine/src/cmd/file_cmds/tests.rs +++ b/crates/engine/src/cmd/file_cmds/tests.rs @@ -1262,6 +1262,24 @@ fn image_processor_scratch_sessions_answer_to_the_authorization_gate() { assert_eq!(r["errors"].as_array().unwrap().len(), 1, "{r}"); } +#[test] +fn batch_save_points_answer_to_the_authorization_gate() { + fn deny_save(id: &str, _: &Value) -> Result<()> { + if id == "file.save" { Err(EngineError::Other(format!("automation command `{id}` is disabled"))) } else { Ok(()) } + } + let dir = tmp("batch-save-gate"); + let input = join(&dir, "in"); + std::fs::create_dir_all(&input).unwrap(); + png(&input, "a.png", 8, 8, "#ff0000"); + let mut s = Session::new(); + s.authorize = Some(deny_save); + let out = join(&dir, "out"); + let r = s.execute("file.automate.batch", json!({"steps": [["file.save", {}]], "input": input, "output": out, "format": "png"})).unwrap(); + assert!(r["files"].as_array().unwrap().is_empty(), "{r}"); + assert_eq!(r["errors"].as_array().unwrap().len(), 1, "{r}"); + assert!(!std::path::Path::new(&join(&out, "a.png")).exists()); +} + #[test] fn load_files_into_stack_and_image_processor_and_batch() { let dir = tmp("batch");