From 1457ea39ba313684dbfda4897322ff0c22a41952 Mon Sep 17 00:00:00 2001 From: yoriswind Date: Wed, 4 Nov 2026 11:15:56 -0800 Subject: [PATCH] Preserve CLI run continuation after direct Batch file errors --- apps/photocraft-cli/src/document.rs | 4 ++- apps/photocraft-cli/tests/it/cli.rs | 39 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/apps/photocraft-cli/src/document.rs b/apps/photocraft-cli/src/document.rs index 4c6678bfb1..9bf5f15fdb 100644 --- a/apps/photocraft-cli/src/document.rs +++ b/apps/photocraft-cli/src/document.rs @@ -100,7 +100,9 @@ pub(crate) fn run_cmds(a: &RunArgs, out: &mut dyn Write, err: &mut dyn Write) -> continue; } let r = h.command_run(&id, params).map_err(|source| CliError::Command { id: id.clone(), source })?; - if let Some(message) = photocraft_engine::actions_cmds::nested_failure(&id, &r) { + // A direct Batch reports per-file errors and continues, as in Scripts; failed + // action or script calls still stop the command list before export. + if let Some(message) = photocraft_engine::actions_cmds::nested_failure(&id, &r).filter(|_| id != "file.automate.batch") { return Err(CliError::NestedFailure { id, message }); } let new_warnings: Vec = diff --git a/apps/photocraft-cli/tests/it/cli.rs b/apps/photocraft-cli/tests/it/cli.rs index 386eafe62c..074672a8b1 100644 --- a/apps/photocraft-cli/tests/it/cli.rs +++ b/apps/photocraft-cli/tests/it/cli.rs @@ -363,6 +363,45 @@ fn run_stops_after_failed_action_without_exporting() { std::fs::remove_dir_all(d).unwrap(); } +/// A direct Batch keeps its partial result without preventing later commands or export. +#[test] +fn run_continues_after_batch_file_errors_and_keeps_partial_results() { + let d = tmp("run-partial-batch"); + let good = d.join("good.png"); + let bad = d.join("bad.png"); + let batch_out = d.join("batch"); + let caller_out = d.join("caller.pcraft"); + write_png(&good, 6, 4, 3); + std::fs::write(&bad, b"not a PNG").unwrap(); + let params = json!({"input":[good,bad],"output":batch_out,"format":"pcraft","steps":[ + ["layer.renameLayer",{"name":"Batch output"}] + ]}) + .to_string(); + let stdout = ok(bin() + .args(["run", "--new", r#"{"width":8,"height":8}"#]) + .args(["--cmd", "file.automate.batch", "--params", ¶ms]) + .args(["--cmd", "layer.new.layer", "--params", r#"{"name":"After batch"}"#]) + .args(["--cmd", "document.inspect", "--out"]) + .arg(&caller_out)) + .stdout; + let rows: Vec = stdout.lines().map(|line| serde_json::from_str(line).unwrap()).collect(); + assert_eq!(rows.len(), 3); + assert_eq!(rows[0]["command"], "file.automate.batch"); + let result = &rows[0]["result"]; + assert_eq!(result["files"], json!([batch_out.join("good.pcraft")])); + assert_eq!(result["errors"].as_array().unwrap().len(), 1); + assert_eq!(result["errors"][0]["file"], json!(bad)); + assert!(result["errors"][0]["error"].as_str().is_some_and(|message| !message.is_empty())); + assert!(batch_out.join("good.pcraft").is_file()); + assert!(!batch_out.join("bad.pcraft").exists()); + assert_eq!(rows[2]["command"], "document.inspect"); + assert!(rows[2]["result"]["layers"].as_array().unwrap().iter().any(|layer| layer["name"] == "After batch")); + assert!(caller_out.is_file()); + let saved: Value = serde_json::from_str(&ok(bin().arg("info").arg(&caller_out)).stdout).unwrap(); + assert!(saved["layers"].as_array().unwrap().iter().any(|layer| layer["name"] == "After batch")); + std::fs::remove_dir_all(d).unwrap(); +} + #[test] fn run_continues_after_successful_action_and_exports() { let d = tmp("run-successful-action");