From 0f554d9acc813626818588af876a48e2aee6d1df Mon Sep 17 00:00:00 2001 From: Dan Date: Sat, 14 Nov 2026 18:39:43 +0000 Subject: [PATCH 01/10] Report when Image Processor cannot open any source files --- .../image_processor_empty_source_tests.rs | 111 ++++++++++++++++++ crates/engine/src/cmd/file_cmds/processing.rs | 39 +++++- crates/ui-egui/src/app/commands.rs | 30 +++++ 3 files changed, 176 insertions(+), 4 deletions(-) create mode 100644 crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs diff --git a/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs b/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs new file mode 100644 index 0000000000..4dc632af00 --- /dev/null +++ b/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs @@ -0,0 +1,111 @@ +use std::{fs, path::Path}; + +use serde_json::{Value, json}; + +use crate::{EngineError, Session}; + +const COMMAND: &str = "file.scripts.imageProcessor"; +const NO_SOURCE: &str = "There were no source files that could be opened by PhotoCraft."; + +fn settings(input: &Path, output: &Path, per_format: bool) -> Value { + let mut params = json!({"input": input, "output": output}); + if per_format { + params["jpeg"] = json!({}); + params["tiff"] = json!({}); + } + params +} + +fn write_image(path: &Path) { + fs::write(path, b"P6\n2 1\n255\n\xff\0\0\0\xff\0").unwrap(); +} + +#[test] +fn blank_empty_non_image_and_corrupt_sources_report_no_openable_files() { + let root = tempfile::tempdir().unwrap(); + let input = root.path().join("input"); + let output = root.path().join("output"); + fs::create_dir(&input).unwrap(); + let mut session = Session::new(); + + for per_format in [false, true] { + assert_eq!(session.execute(COMMAND, settings(Path::new(""), &output, per_format)), Err(EngineError::Other(NO_SOURCE.into()))); + } + + for file in [None, Some("notes.txt"), Some("broken.jpg")] { + if let Some(file) = file { + fs::write(input.join(file), b"not an image").unwrap(); + } + for per_format in [false, true] { + assert_eq!(session.execute(COMMAND, settings(&input, &output, per_format)), Err(EngineError::Other(NO_SOURCE.into()))); + } + assert!(!output.exists()); + } +} + +#[test] +fn image_processor_skips_non_images_and_can_find_images_in_subfolders() { + let root = tempfile::tempdir().unwrap(); + let input = root.path().join("input"); + let nested = input.join("nested"); + let output = root.path().join("output"); + fs::create_dir_all(&nested).unwrap(); + fs::write(input.join("notes.txt"), b"not an image").unwrap(); + fs::write(nested.join("manifest.txt"), b"not an image").unwrap(); + write_image(&nested.join("test.ppm")); + let mut session = Session::new(); + + for per_format in [false, true] { + let mut params = settings(&input, &output, per_format); + assert_eq!(session.execute(COMMAND, params.clone()), Err(EngineError::Other(NO_SOURCE.into()))); + params["includeSubfolders"] = json!(true); + let result = session.execute(COMMAND, params).unwrap(); + let mut expected = vec![output.join("nested/test.jpg")]; + if per_format { + expected.push(output.join("nested/test.tif")); + } + assert_eq!(result, json!({"files": expected, "errors": []})); + for path in expected { + let image = photocraft_io::import(&path.to_string_lossy(), &fs::read(&path).unwrap()).unwrap(); + assert_eq!((image.document.size.width, image.document.size.height), (2, 1)); + } + } +} + +#[test] +fn an_opened_image_can_still_report_a_processing_or_write_failure() { + let root = tempfile::tempdir().unwrap(); + let input = root.path().join("input"); + let output = root.path().join("output"); + fs::create_dir(&input).unwrap(); + write_image(&input.join("test.ppm")); + fs::write(&output, b"not a directory").unwrap(); + let mut session = Session::new(); + for per_format in [false, true] { + let result = session.execute(COMMAND, settings(&input, &output, per_format)).unwrap(); + assert_eq!(result["files"], json!([])); + let errors = result["errors"].as_array().unwrap(); + assert_eq!(errors.len(), if per_format { 2 } else { 1 }); + assert!(errors.iter().all(|error| error["file"] == json!(input.join("test.ppm")))); + } + assert_eq!(fs::read(&output).unwrap(), b"not a directory"); +} + +#[test] +fn missing_paths_and_missing_open_documents_keep_their_own_errors() { + let root = tempfile::tempdir().unwrap(); + let missing = root.path().join("missing"); + let output = root.path().join("output"); + let mut session = Session::new(); + for per_format in [false, true] { + let params = settings(&missing, &output, per_format); + let error = session.execute(COMMAND, params.clone()).unwrap_err().to_string(); + assert!(error.contains(&missing.to_string_lossy().to_string()), "{error}"); + assert_ne!(error, NO_SOURCE); + for source in ["current", "open"] { + let mut params = params.clone(); + params["source"] = json!(source); + assert_eq!(session.execute(COMMAND, params), Err(EngineError::NoDocument)); + } + } +} diff --git a/crates/engine/src/cmd/file_cmds/processing.rs b/crates/engine/src/cmd/file_cmds/processing.rs index 5e0d6b2ddb..e4492cf68a 100644 --- a/crates/engine/src/cmd/file_cmds/processing.rs +++ b/crates/engine/src/cmd/file_cmds/processing.rs @@ -1,3 +1,5 @@ +use std::cell::Cell; + use super::batch_run::{BatchInput, batch_inputs_tree, process_document_copies, process_tree}; use super::open::import_opened; use super::paths::{file_name, list_images, read_file, stem, untitled_name}; @@ -7,6 +9,9 @@ use super::{ str_param, }; +#[cfg(all(test, not(target_arch = "wasm32")))] +#[path = "image_processor_empty_source_tests.rs"] +mod image_processor_empty_source_tests; #[cfg(all(test, not(target_arch = "wasm32")))] #[path = "image_processor_formats_tests.rs"] mod image_processor_formats_tests; @@ -131,8 +136,8 @@ pub(super) fn image_processor(s: &mut Session, p: &Value) -> Result { Ok(false) }; let r = if source == "folder" { - let inputs = batch_inputs_tree(p, cmd, &output)?; - process_tree(s, &inputs, &output, format, save, "", &process) + let inputs = image_processor_folder_inputs(p, &output)?; + process_image_processor_folder(s, &inputs, &output, format, save, &process)? } else { let documents = if source == "current" { vec![s.active().ok_or(EngineError::NoDocument)?] } else { s.documents().iter().collect() }; if documents.is_empty() { @@ -145,6 +150,32 @@ pub(super) fn image_processor(s: &mut Session, p: &Value) -> Result { const IMAGE_PROCESSOR: &str = "file.scripts.imageProcessor"; const IMAGE_PROCESSOR_NO_FORMAT: &str = "You must save to at least one file type."; +const IMAGE_PROCESSOR_NO_SOURCE: &str = "There were no source files that could be opened by PhotoCraft."; + +fn image_processor_folder_inputs(p: &Value, output: &str) -> Result> { + if p.get("input").or_else(|| p.get("files")).and_then(Value::as_str) == Some("") { + return Err(EngineError::Other(IMAGE_PROCESSOR_NO_SOURCE.into())); + } + batch_inputs_tree(p, IMAGE_PROCESSOR, output) +} + +/// The runner calls `process` only after it opens an input. Export and processing failures +/// still belong in the per-file report, even when none of the opened inputs could be saved. +fn process_image_processor_folder( + s: &Session, + inputs: &[BatchInput], + output: &str, + format: &str, + save: SaveOpts, + process: &dyn Fn(&mut Session, &str) -> Result, +) -> Result { + let opened = Cell::new(false); + let result = process_tree(s, inputs, output, format, save, "", &|scratch, out| { + opened.set(true); + process(scratch, out) + }); + if opened.get() { Ok(result) } else { Err(EngineError::Other(IMAGE_PROCESSOR_NO_SOURCE.into())) } +} fn image_processor_param(message: impl Into) -> EngineError { EngineError::BadParams { cmd: IMAGE_PROCESSOR.into(), msg: message.into() } @@ -221,7 +252,7 @@ fn image_processor_formats(s: &Session, p: &Value, source: &str, output: &str) - return Err(image_processor_param(IMAGE_PROCESSOR_NO_FORMAT)); } let inputs = match source { - "folder" => ProcessorInputs::Folder(batch_inputs_tree(p, IMAGE_PROCESSOR, output)?), + "folder" => ProcessorInputs::Folder(image_processor_folder_inputs(p, output)?), "current" => ProcessorInputs::Documents(vec![s.active().ok_or(EngineError::NoDocument)?]), _ if s.documents().is_empty() => return Err(EngineError::NoDocument), _ => ProcessorInputs::Documents(s.documents().iter().collect()), @@ -246,7 +277,7 @@ fn image_processor_formats(s: &Session, p: &Value, source: &str, output: &str) - Ok(false) }; let mut result = match &inputs { - ProcessorInputs::Folder(inputs) => process_tree(s, inputs, output, format.extension, format.save, "", &process), + ProcessorInputs::Folder(inputs) => process_image_processor_folder(s, inputs, output, format.extension, format.save, &process)?, ProcessorInputs::Documents(documents) => process_document_copies(s, documents, output, format.extension, format.save, &process), }; if let Some(Value::Array(written)) = result.get_mut("files").map(Value::take) { diff --git a/crates/ui-egui/src/app/commands.rs b/crates/ui-egui/src/app/commands.rs index 1aa81115d4..333cfe2b0b 100644 --- a/crates/ui-egui/src/app/commands.rs +++ b/crates/ui-egui/src/app/commands.rs @@ -211,6 +211,9 @@ impl PhotocraftApp { } } Err(e) => { + if id == "file.scripts.imageProcessor" && e == "There were no source files that could be opened by PhotoCraft." { + crate::panels::options_bar::range_alert(&mut self.ui, e); + } self.ui.status = e.clone(); self.ui.status_error = true; } @@ -437,3 +440,30 @@ const ADDS_LAYER_MASK: [&str; 5] = [ "layer.layerMask.hideSelection", "layer.layerMask.fromTransparency", ]; + +#[cfg(all(test, not(target_arch = "wasm32")))] +mod image_processor_empty_source_tests { + use super::*; + + #[test] + fn confirming_image_processor_with_no_source_replaces_the_form_with_an_alert() { + let input = tempfile::tempdir().unwrap(); + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + let ctx = egui::Context::default(); + crate::menus::invoke(&mut app, &ctx, "file.scripts.imageProcessor", json!({})).unwrap(); + let form = app.ui.dialogs.last_mut().unwrap(); + let form_id = form.id; + form.fields.insert("input".into(), json!(input.path())); + let output = input.path().join("processed"); + form.fields.insert("output".into(), json!(output)); + + let expected = "There were no source files that could be opened by PhotoCraft."; + assert_eq!(crate::dialogs::confirm(&mut app, form_id), Err(expected.into())); + assert_eq!(app.ui.dialogs.len(), 1); + let alert = &app.ui.dialogs[0]; + assert_ne!(alert.id, form_id); + assert_eq!(alert.kind, state::DialogKind::Error); + assert_eq!(alert.fields.get("message"), Some(&json!(expected))); + assert!(!output.exists()); + } +} From 1d25e374ce05ec8c81df6e38b80f11bd0f777856 Mon Sep 17 00:00:00 2001 From: Dan Date: Sat, 14 Nov 2026 18:41:16 +0000 Subject: [PATCH 02/10] Cover Image Processor input validation and partial failures --- .../image_processor_empty_source_tests.rs | 41 +++++++++++++++++++ crates/engine/src/cmd/file_cmds/processing.rs | 8 +++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs b/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs index 4dc632af00..b95475dc41 100644 --- a/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs +++ b/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs @@ -109,3 +109,44 @@ fn missing_paths_and_missing_open_documents_keep_their_own_errors() { } } } + +#[test] +fn mixed_valid_and_corrupt_images_keep_the_corrupt_file_report() { + let root = tempfile::tempdir().unwrap(); + let input = root.path().join("input"); + let output = root.path().join("output"); + fs::create_dir(&input).unwrap(); + let corrupt = input.join("broken.jpg"); + fs::write(&corrupt, b"not an image").unwrap(); + write_image(&input.join("test.ppm")); + let mut session = Session::new(); + for per_format in [false, true] { + let result = session.execute(COMMAND, settings(&input, &output, per_format)).unwrap(); + let mut expected = vec![output.join("test.jpg")]; + if per_format { + expected.push(output.join("test.tif")); + } + assert_eq!(result["files"], json!(expected)); + let errors = result["errors"].as_array().unwrap(); + assert_eq!(errors.len(), if per_format { 2 } else { 1 }); + assert!(errors.iter().all(|error| error["file"] == json!(corrupt))); + } +} + +#[test] +fn empty_explicit_inputs_error_and_invalid_recursion_keeps_its_diagnostic() { + let root = tempfile::tempdir().unwrap(); + let output = root.path().join("output"); + let mut session = Session::new(); + for per_format in [false, true] { + let mut params = settings(Path::new(""), &output, per_format); + params["includeSubfolders"] = json!("true"); + let error = session.execute(COMMAND, params.clone()).unwrap_err(); + assert!(matches!(error, EngineError::BadParams { msg, .. } if msg.contains("includeSubfolders"))); + params.as_object_mut().unwrap().remove("input"); + params["includeSubfolders"] = json!(false); + params["files"] = json!([]); + assert_eq!(session.execute(COMMAND, params), Err(EngineError::Other(NO_SOURCE.into()))); + } + assert!(!output.exists()); +} diff --git a/crates/engine/src/cmd/file_cmds/processing.rs b/crates/engine/src/cmd/file_cmds/processing.rs index e4492cf68a..98c0bbec71 100644 --- a/crates/engine/src/cmd/file_cmds/processing.rs +++ b/crates/engine/src/cmd/file_cmds/processing.rs @@ -103,7 +103,8 @@ pub(super) fn parse_steps(v: &Value) -> Result> { /// Resize and export folder inputs or copies of the current/all open documents. /// An omitted `source` keeps the folder-input contract; document sources include unsaved /// edits without modifying the original documents. Invalid parameters and missing documents -/// return an error; processing failures and output-name collisions appear in per-file errors. +/// return an error, as does a folder source with no openable images. Processing failures and +/// output-name collisions appear in per-file errors. pub(super) fn image_processor(s: &mut Session, p: &Value) -> Result { let cmd = IMAGE_PROCESSOR; let source = match p.get("source") { @@ -154,7 +155,10 @@ const IMAGE_PROCESSOR_NO_SOURCE: &str = "There were no source files that could b fn image_processor_folder_inputs(p: &Value, output: &str) -> Result> { if p.get("input").or_else(|| p.get("files")).and_then(Value::as_str) == Some("") { - return Err(EngineError::Other(IMAGE_PROCESSOR_NO_SOURCE.into())); + // Treat the empty dialog field as an empty file list while retaining normal validation. + let mut params = p.clone(); + params["input"] = json!([]); + return batch_inputs_tree(¶ms, IMAGE_PROCESSOR, output); } batch_inputs_tree(p, IMAGE_PROCESSOR, output) } From d9a6ee824d8d9c1fd455ade17b46cbe9ea0aad3b Mon Sep 17 00:00:00 2001 From: Dan Date: Sat, 14 Nov 2026 18:51:01 +0000 Subject: [PATCH 03/10] Propagate fixture write errors to Image Processor tests --- .../file_cmds/image_processor_empty_source_tests.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs b/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs index b95475dc41..4af3916e27 100644 --- a/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs +++ b/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs @@ -16,8 +16,8 @@ fn settings(input: &Path, output: &Path, per_format: bool) -> Value { params } -fn write_image(path: &Path) { - fs::write(path, b"P6\n2 1\n255\n\xff\0\0\0\xff\0").unwrap(); +fn write_image(path: &Path) -> std::io::Result<()> { + fs::write(path, b"P6\n2 1\n255\n\xff\0\0\0\xff\0") } #[test] @@ -52,7 +52,7 @@ fn image_processor_skips_non_images_and_can_find_images_in_subfolders() { fs::create_dir_all(&nested).unwrap(); fs::write(input.join("notes.txt"), b"not an image").unwrap(); fs::write(nested.join("manifest.txt"), b"not an image").unwrap(); - write_image(&nested.join("test.ppm")); + write_image(&nested.join("test.ppm")).unwrap(); let mut session = Session::new(); for per_format in [false, true] { @@ -78,7 +78,7 @@ fn an_opened_image_can_still_report_a_processing_or_write_failure() { let input = root.path().join("input"); let output = root.path().join("output"); fs::create_dir(&input).unwrap(); - write_image(&input.join("test.ppm")); + write_image(&input.join("test.ppm")).unwrap(); fs::write(&output, b"not a directory").unwrap(); let mut session = Session::new(); for per_format in [false, true] { @@ -118,7 +118,7 @@ fn mixed_valid_and_corrupt_images_keep_the_corrupt_file_report() { fs::create_dir(&input).unwrap(); let corrupt = input.join("broken.jpg"); fs::write(&corrupt, b"not an image").unwrap(); - write_image(&input.join("test.ppm")); + write_image(&input.join("test.ppm")).unwrap(); let mut session = Session::new(); for per_format in [false, true] { let result = session.execute(COMMAND, settings(&input, &output, per_format)).unwrap(); From 4ed9fb9e3183b28757f88bce56a01895394cd68b Mon Sep 17 00:00:00 2001 From: Dan Date: Sat, 14 Nov 2026 20:05:36 +0000 Subject: [PATCH 04/10] Isolate output fixtures when testing both Image Processor fixes --- .../src/cmd/file_cmds/image_processor_empty_source_tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs b/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs index 4af3916e27..60078944c8 100644 --- a/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs +++ b/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs @@ -48,7 +48,6 @@ fn image_processor_skips_non_images_and_can_find_images_in_subfolders() { let root = tempfile::tempdir().unwrap(); let input = root.path().join("input"); let nested = input.join("nested"); - let output = root.path().join("output"); fs::create_dir_all(&nested).unwrap(); fs::write(input.join("notes.txt"), b"not an image").unwrap(); fs::write(nested.join("manifest.txt"), b"not an image").unwrap(); @@ -56,6 +55,7 @@ fn image_processor_skips_non_images_and_can_find_images_in_subfolders() { let mut session = Session::new(); for per_format in [false, true] { + let output = root.path().join(if per_format { "multi" } else { "single" }); let mut params = settings(&input, &output, per_format); assert_eq!(session.execute(COMMAND, params.clone()), Err(EngineError::Other(NO_SOURCE.into()))); params["includeSubfolders"] = json!(true); @@ -114,13 +114,13 @@ fn missing_paths_and_missing_open_documents_keep_their_own_errors() { fn mixed_valid_and_corrupt_images_keep_the_corrupt_file_report() { let root = tempfile::tempdir().unwrap(); let input = root.path().join("input"); - let output = root.path().join("output"); fs::create_dir(&input).unwrap(); let corrupt = input.join("broken.jpg"); fs::write(&corrupt, b"not an image").unwrap(); write_image(&input.join("test.ppm")).unwrap(); let mut session = Session::new(); for per_format in [false, true] { + let output = root.path().join(if per_format { "multi" } else { "single" }); let result = session.execute(COMMAND, settings(&input, &output, per_format)).unwrap(); let mut expected = vec![output.join("test.jpg")]; if per_format { From ee19ca874a3cb5b3322b798eac6fe4798b499733 Mon Sep 17 00:00:00 2001 From: Dan Date: Sat, 14 Nov 2026 21:53:44 +0000 Subject: [PATCH 05/10] Compare Image Processor test outputs as native paths --- .../file_cmds/image_processor_empty_source_tests.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs b/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs index 60078944c8..d529760b8f 100644 --- a/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs +++ b/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs @@ -1,4 +1,7 @@ -use std::{fs, path::Path}; +use std::{ + fs, + path::{Path, PathBuf}, +}; use serde_json::{Value, json}; @@ -64,7 +67,9 @@ fn image_processor_skips_non_images_and_can_find_images_in_subfolders() { if per_format { expected.push(output.join("nested/test.tif")); } - assert_eq!(result, json!({"files": expected, "errors": []})); + let files: Vec = serde_json::from_value(result["files"].clone()).unwrap(); + assert_eq!(files, expected); + assert_eq!(result["errors"], json!([])); for path in expected { let image = photocraft_io::import(&path.to_string_lossy(), &fs::read(&path).unwrap()).unwrap(); assert_eq!((image.document.size.width, image.document.size.height), (2, 1)); @@ -126,7 +131,8 @@ fn mixed_valid_and_corrupt_images_keep_the_corrupt_file_report() { if per_format { expected.push(output.join("test.tif")); } - assert_eq!(result["files"], json!(expected)); + let files: Vec = serde_json::from_value(result["files"].clone()).unwrap(); + assert_eq!(files, expected); let errors = result["errors"].as_array().unwrap(); assert_eq!(errors.len(), if per_format { 2 } else { 1 }); assert!(errors.iter().all(|error| error["file"] == json!(corrupt))); From 7496bcbc35e737b182c62987f7a7aeb6d4d2d5a7 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sun, 15 Nov 2026 16:41:17 +0100 Subject: [PATCH 06/10] Artboards to Files order test: expect the file names (#15170) #13641 renamed the exported files to with spaces as hyphens; the order test from #13670 still expected the old p_0000_Empty Board.png names and failed on main. Assert all three names in top-first order. (cherry picked from commit 42e9467bf9d746140a7ecd7a8b7b6382b1b5769b) --- crates/engine/src/cmd/artboard_cmds/pdf_page_order_tests.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/artboard_cmds/pdf_page_order_tests.rs b/crates/engine/src/cmd/artboard_cmds/pdf_page_order_tests.rs index 49356105a6..0541f8e456 100644 --- a/crates/engine/src/cmd/artboard_cmds/pdf_page_order_tests.rs +++ b/crates/engine/src/cmd/artboard_cmds/pdf_page_order_tests.rs @@ -54,5 +54,7 @@ fn artboards_to_files_keeps_its_top_first_order() { let r = s.execute("file.export.artboardsToFiles", json!({"dir": dir.to_string_lossy(), "prefix": "p"})).unwrap(); let _ = std::fs::remove_dir_all(&dir); let files: Vec<&str> = r["files"].as_array().unwrap().iter().filter_map(Value::as_str).collect(); - assert!(files[0].ends_with("p_0000_Empty Board.png") && files[2].ends_with("p_0002_Red Board.png"), "{files:?}"); + // Files are named , spaces as hyphens (#13633); top artboard first. + let names: Vec<&str> = files.iter().map(|f| f.rsplit(['/', '\\']).next().unwrap_or(f)).collect(); + assert_eq!(names, ["pEmpty-Board.png", "pBlue-Board.png", "pRed-Board.png"], "{files:?}"); } From c12dc347814e6b21ba37f5fdb8f7e8f470ec9aa2 Mon Sep 17 00:00:00 2001 From: Dan Date: Sun, 15 Nov 2026 16:22:47 +0000 Subject: [PATCH 07/10] Use an action row in the shortcut set switch test --- .../src/prefs/prefs_ui/shortcut_set_switch_tests.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/prefs/prefs_ui/shortcut_set_switch_tests.rs b/crates/ui-egui/src/prefs/prefs_ui/shortcut_set_switch_tests.rs index dafa8be560..7512acee99 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/shortcut_set_switch_tests.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/shortcut_set_switch_tests.rs @@ -165,7 +165,13 @@ fn an_unmodified_set_switches_at_once() { fn an_action_function_key_is_no_edit() { let (mut h, first) = dialog(); h.state_mut().ui.dialogs.retain(|d| d.id != first); - crate::actions::assign_shortcut(h.state_mut(), "Sepia", "F2").unwrap(); + let app = h.state_mut(); + app.run("actions.record", json!({"name": "Sepia"})).unwrap(); + app.run("actions.stop", json!({})).unwrap(); + let row = app.session.actions.list.iter().position(|action| action.name == "Sepia").unwrap(); + crate::actions::assign_shortcut(app, row, "F2").unwrap(); + let action_id = app.session.actions.list[row].action_id.as_deref().unwrap(); + let shortcut_id = photocraft_engine::actions_cmds::occurrence_key(action_id); let ctx = h.ctx.clone(); let id = crate::menus::invoke(h.state_mut(), &ctx, "edit.keyboardShortcuts", json!({})).unwrap()["dialog"].as_u64().unwrap(); h.run_steps(4); @@ -173,6 +179,7 @@ fn an_action_function_key_is_no_edit() { pick_set(&mut h, "PhotoCraft Defaults"); assert!(!asking(&h)); assert_eq!(field(&h, id, "activeSet"), json!("")); + assert_eq!(field(&h, id, "overrides")[shortcut_id], "F2"); } #[test] From db534a44d9e4afd9a8d7144c61114145ed0e69b2 Mon Sep 17 00:00:00 2001 From: Dan Date: Sun, 15 Nov 2026 22:46:39 +0000 Subject: [PATCH 08/10] Keep Image Processor results across source read failures --- .../image_processor_empty_source_tests.rs | 31 ++++++++++++++++++ crates/engine/src/cmd/file_cmds/processing.rs | 32 +++++++++++++------ 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs b/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs index d529760b8f..8bacfa1706 100644 --- a/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs +++ b/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs @@ -156,3 +156,34 @@ fn empty_explicit_inputs_error_and_invalid_recursion_keeps_its_diagnostic() { } assert!(!output.exists()); } + +#[test] +fn a_source_removed_between_formats_keeps_the_written_file_and_read_error() { + use super::{ProcessorInputs, image_processor_folder_inputs, processor_format, run_processor_formats}; + + let root = tempfile::tempdir().unwrap(); + let output = root.path().join("output"); + let input = root.path().join("test.ppm"); + let jpeg = output.join("test.jpg"); + fs::create_dir(&output).unwrap(); + write_image(&input).unwrap(); + let session = Session::new(); + let output = output.to_str().unwrap(); + let sources = image_processor_folder_inputs(&json!({"files": [input]}), output).unwrap(); + let inputs = ProcessorInputs::Folder(sources); + let formats = [ + processor_format(&session, "jpeg", "jpg", &json!({})).unwrap().unwrap(), + processor_format(&session, "tiff", "tif", &json!({})).unwrap().unwrap(), + ]; + let result = run_processor_formats(&session, &inputs, output, formats.into_iter().inspect(|format| { + if format.extension == "tif" { + assert!(jpeg.is_file()); + fs::remove_file(&input).unwrap(); + } + })).unwrap(); + assert_eq!(result["files"], json!([jpeg])); + let errors = result["errors"].as_array().unwrap(); + assert_eq!(errors.len(), 1); + assert_eq!(errors[0]["file"], json!(input)); + assert_eq!(errors[0]["format"], "tif"); +} diff --git a/crates/engine/src/cmd/file_cmds/processing.rs b/crates/engine/src/cmd/file_cmds/processing.rs index 98c0bbec71..76d56e4870 100644 --- a/crates/engine/src/cmd/file_cmds/processing.rs +++ b/crates/engine/src/cmd/file_cmds/processing.rs @@ -138,7 +138,10 @@ pub(super) fn image_processor(s: &mut Session, p: &Value) -> Result { }; let r = if source == "folder" { let inputs = image_processor_folder_inputs(p, &output)?; - process_image_processor_folder(s, &inputs, &output, format, save, &process)? + let opened = Cell::new(false); + let result = process_image_processor_folder(s, &inputs, &output, format, save, &opened, &process); + require_opened_source(&opened)?; + result } else { let documents = if source == "current" { vec![s.active().ok_or(EngineError::NoDocument)?] } else { s.documents().iter().collect() }; if documents.is_empty() { @@ -171,14 +174,17 @@ fn process_image_processor_folder( output: &str, format: &str, save: SaveOpts, + opened: &Cell, process: &dyn Fn(&mut Session, &str) -> Result, -) -> Result { - let opened = Cell::new(false); - let result = process_tree(s, inputs, output, format, save, "", &|scratch, out| { +) -> Value { + process_tree(s, inputs, output, format, save, "", &|scratch, out| { opened.set(true); process(scratch, out) - }); - if opened.get() { Ok(result) } else { Err(EngineError::Other(IMAGE_PROCESSOR_NO_SOURCE.into())) } + }) +} + +fn require_opened_source(opened: &Cell) -> Result<()> { + if opened.get() { Ok(()) } else { Err(EngineError::Other(IMAGE_PROCESSOR_NO_SOURCE.into())) } } fn image_processor_param(message: impl Into) -> EngineError { @@ -261,12 +267,17 @@ fn image_processor_formats(s: &Session, p: &Value, source: &str, output: &str) - _ if s.documents().is_empty() => return Err(EngineError::NoDocument), _ => ProcessorInputs::Documents(s.documents().iter().collect()), }; + run_processor_formats(s, &inputs, output, formats) +} + +fn run_processor_formats(s: &Session, inputs: &ProcessorInputs<'_>, output: &str, formats: impl IntoIterator) -> Result { let mut files = Vec::new(); let mut errors = Vec::new(); + let opened = Cell::new(false); for format in formats { // The existing runners prepare fresh scratch documents for each output. let process = |scratch: &mut Session, out: &str| { - if let ProcessorInputs::Folder(inputs) = &inputs + if let ProcessorInputs::Folder(inputs) = inputs && super::paths::is_file(out) && inputs.iter().any(|input| super::paths::same_file(&input.path, out)) { @@ -280,8 +291,8 @@ fn image_processor_formats(s: &Session, p: &Value, source: &str, output: &str) - } Ok(false) }; - let mut result = match &inputs { - ProcessorInputs::Folder(inputs) => process_image_processor_folder(s, inputs, output, format.extension, format.save, &process)?, + let mut result = match inputs { + ProcessorInputs::Folder(inputs) => process_image_processor_folder(s, inputs, output, format.extension, format.save, &opened, &process), ProcessorInputs::Documents(documents) => process_document_copies(s, documents, output, format.extension, format.save, &process), }; if let Some(Value::Array(written)) = result.get_mut("files").map(Value::take) { @@ -297,6 +308,9 @@ fn image_processor_formats(s: &Session, p: &Value, source: &str, output: &str) - })); } } + if matches!(inputs, ProcessorInputs::Folder(_)) { + require_opened_source(&opened)?; + } Ok(json!({"files": files, "errors": errors})) } From b662e550ea2caabc8a50ed46e65e51cfcb500673 Mon Sep 17 00:00:00 2001 From: Dan Date: Sun, 15 Nov 2026 23:03:50 +0000 Subject: [PATCH 09/10] Match workspace Rust formatting --- .../image_processor_empty_source_tests.rs | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs b/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs index 8bacfa1706..e3f5ce9c20 100644 --- a/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs +++ b/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs @@ -171,16 +171,20 @@ fn a_source_removed_between_formats_keeps_the_written_file_and_read_error() { let output = output.to_str().unwrap(); let sources = image_processor_folder_inputs(&json!({"files": [input]}), output).unwrap(); let inputs = ProcessorInputs::Folder(sources); - let formats = [ - processor_format(&session, "jpeg", "jpg", &json!({})).unwrap().unwrap(), - processor_format(&session, "tiff", "tif", &json!({})).unwrap().unwrap(), - ]; - let result = run_processor_formats(&session, &inputs, output, formats.into_iter().inspect(|format| { - if format.extension == "tif" { - assert!(jpeg.is_file()); - fs::remove_file(&input).unwrap(); - } - })).unwrap(); + let formats = + [processor_format(&session, "jpeg", "jpg", &json!({})).unwrap().unwrap(), processor_format(&session, "tiff", "tif", &json!({})).unwrap().unwrap()]; + let result = run_processor_formats( + &session, + &inputs, + output, + formats.into_iter().inspect(|format| { + if format.extension == "tif" { + assert!(jpeg.is_file()); + fs::remove_file(&input).unwrap(); + } + }), + ) + .unwrap(); assert_eq!(result["files"], json!([jpeg])); let errors = result["errors"].as_array().unwrap(); assert_eq!(errors.len(), 1); From 7da733e6020542d55ed2e0ff0a79359f9317a8fb Mon Sep 17 00:00:00 2001 From: Dan Date: Sun, 22 Nov 2026 18:37:58 +0000 Subject: [PATCH 10/10] Compare Image Processor output by path on Windows --- .../src/cmd/file_cmds/image_processor_empty_source_tests.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs b/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs index e3f5ce9c20..8333b48996 100644 --- a/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs +++ b/crates/engine/src/cmd/file_cmds/image_processor_empty_source_tests.rs @@ -185,7 +185,9 @@ fn a_source_removed_between_formats_keeps_the_written_file_and_read_error() { }), ) .unwrap(); - assert_eq!(result["files"], json!([jpeg])); + let files = result["files"].as_array().unwrap(); + assert_eq!(files.len(), 1); + assert_eq!(Path::new(files[0].as_str().unwrap()), jpeg); let errors = result["errors"].as_array().unwrap(); assert_eq!(errors.len(), 1); assert_eq!(errors[0]["file"], json!(input));