LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
test: factor long UI and MCP scenarios into helpers
Dylan M. Taylor6e54232557c0
diff --git a/crates/mcp/tests/it/e2e.rs b/crates/mcp/tests/it/e2e.rsindex 03d77c7e2..2a8db44c7 100644--- a/crates/mcp/tests/it/e2e.rs+++ b/crates/mcp/tests/it/e2e.rs@@ -246,33 +246,13 @@ impl Backend for HoldAfterFirst {}}-/// Real stdio framing and real atomic exports: progress, ping during a batch, cancellation-/// between complete photos, unrelated output preservation, and a usable session afterwards.-/// Both exports wait after their first photo ([`HoldAfterFirst`]) until the ping is answered or-/// the cancel is read, so neither can finish first on a fast machine.-#[test]-fn export_progress_and_cancel() {- let dir = std::env::temp_dir().join(format!("lc-mcp-progress-{}", std::process::id()));- let _ = std::fs::remove_dir_all(&dir);- std::fs::create_dir_all(&dir).unwrap();- let (input, mut send) = std::io::pipe().unwrap();- let (output, write) = std::io::pipe().unwrap();- let hold = Arc::new(AtomicBool::new(true));- let backend = HoldAfterFirst { inner: file_backed_photos(&dir), hold: hold.clone() };- let server = std::thread::spawn(move || Server::new(Box::new(backend)).serve(BufReader::new(input), write).unwrap());- let (tx, rx) = std::sync::mpsc::channel();- let reader = std::thread::spawn(move || {- for line in BufReader::new(output).lines() {- let value: Value = serde_json::from_str(&line.unwrap()).unwrap();- if tx.send(value).is_err() {- break;- }- }- });- let next = || rx.recv_timeout(Duration::from_secs(30)).expect("MCP reply/progress");- writeln!(send, "{}", call(1, "query_photos", json!({"limit":8}))).unwrap();- let query = next();- let photos = query["result"]["structuredContent"]["photos"].as_array().unwrap();+type Rx = std::sync::mpsc::Receiver<Value>;++fn next_msg(rx: &Rx) -> Value {+ rx.recv_timeout(Duration::from_secs(30)).expect("MCP reply/progress")+}++fn assert_query_photos(photos: &[Value]) {assert_eq!(photos.len(), 8);// Real files, real metadata: eight distinct 1200×800 PNGs probed from disk, not synthesized.let names: std::collections::HashSet<&str> = photos.iter().map(|p| p["fileName"].as_str().unwrap()).collect();@@ -281,13 +261,15 @@ fn export_progress_and_cancel() {assert_eq!((p["width"].as_u64(), p["height"].as_u64()), (Some(1200), Some(800)), "{p}");assert_eq!(p["format"], "PNG", "{p}");}- let ids: Vec<_> = photos.iter().map(|p| p["id"].clone()).collect();+}++fn run_complete_export(send: &mut impl Write, rx: &Rx, hold: &AtomicBool, ids: &[Value], dir: &std::path::Path) {let mut request = call(2, "export", json!({"ids":ids,"dir":dir.join("complete"),"longEdge":1200,"format":"png"}));request["params"]["_meta"] = json!({"progressToken":"photos","io.modelcontextprotocol/protocolVersion":"2026-07-28"});writeln!(send, "{request}").unwrap();let (mut last, mut notes, mut asked, mut answered) = (-1.0, 0, false, false);loop {- let value = next();+ let value = next_msg(rx);if value["method"] == "notifications/progress" {assert_eq!(value["params"]["progressToken"], "photos");let progress = value["params"]["progress"].as_f64().unwrap();@@ -312,17 +294,16 @@ fn export_progress_and_cancel() {}assert!(notes >= 2 && answered, "{notes} progress messages; ping answered {answered}");assert_eq!(last, 8.0);- let out = dir.join("cancelled");- std::fs::create_dir_all(&out).unwrap();- let decoy = out.join("photo999.png");- std::fs::write(&decoy, b"unrelated existing output").unwrap();+}++fn run_cancelled_export(send: &mut impl Write, rx: &Rx, hold: &AtomicBool, ids: &[Value], out: &std::path::Path) {// this export waits after its first photo until the cancel below is readhold.store(true, Ordering::SeqCst);let mut request = call(4, "command_run", json!({"id":"app.export","params":{"ids":ids,"dir":out,"longEdge":1200,"format":"png"}}));request["params"]["_meta"] = json!({"progressToken":44});writeln!(send, "{request}").unwrap();loop {- let value = next();+ let value = next_msg(rx);assert_ne!(value["id"], 4, "must be cancellable before completion: {value}");assert_eq!(value["params"]["progressToken"], 44, "{value}");if value["params"]["progress"].as_f64().unwrap() > 0.0 {@@ -332,7 +313,7 @@ fn export_progress_and_cancel() {writeln!(send, "{}", json!({"jsonrpc":"2.0","method":"notifications/cancelled","params":{"requestId":4}})).unwrap();writeln!(send, "{}", call(5, "doc_inspect", json!({}))).unwrap();loop {- let value = next();+ let value = next_msg(rx);if value["method"] == "notifications/progress" {continue;}@@ -340,13 +321,19 @@ fn export_progress_and_cancel() {assert_eq!(value["result"]["isError"], false);break;}- assert_eq!(std::fs::read(&decoy).unwrap(), b"unrelated existing output");- let photos: Vec<_> = std::fs::read_dir(&out).unwrap().map(|e| e.unwrap().path()).filter(|p| *p != decoy).collect();+}++fn assert_cancelled_output(out: &std::path::Path, decoy: &std::path::Path) {+ assert_eq!(std::fs::read(decoy).unwrap(), b"unrelated existing output");+ let photos: Vec<_> = std::fs::read_dir(out).unwrap().map(|e| e.unwrap().path()).filter(|p| p != decoy).collect();assert_eq!(photos.len(), 1, "only the photo completed before the cancel remains: {photos:?}");for path in &photos {let d = lightcraft_codecs::decode(&std::fs::read(path).unwrap(), Default::default()).expect("complete image, no partial/temp file");assert_eq!((d.width, d.height), (1200, 800), "{}", path.display());}+}++fn assert_complete_output(dir: &std::path::Path) {// The finished export's eight outputs are real 1200×800 PNGs, one per distinct original.let complete: Vec<_> = std::fs::read_dir(dir.join("complete")).unwrap().map(|e| e.unwrap().path()).collect();assert_eq!(complete.len(), 8, "earlier export retained: {complete:?}");@@ -359,6 +346,44 @@ fn export_progress_and_cancel() {exported.insert(bytes);}assert_eq!(exported.len(), 8, "eight distinct outputs, not copies of one export");+}++/// Real stdio framing and real atomic exports: progress, ping during a batch, cancellation+/// between complete photos, unrelated output preservation, and a usable session afterwards.+/// Both exports wait after their first photo ([`HoldAfterFirst`]) until the ping is answered or+/// the cancel is read, so neither can finish first on a fast machine.+#[test]+fn export_progress_and_cancel() {+ let dir = std::env::temp_dir().join(format!("lc-mcp-progress-{}", std::process::id()));+ let _ = std::fs::remove_dir_all(&dir);+ std::fs::create_dir_all(&dir).unwrap();+ let (input, mut send) = std::io::pipe().unwrap();+ let (output, write) = std::io::pipe().unwrap();+ let hold = Arc::new(AtomicBool::new(true));+ let backend = HoldAfterFirst { inner: file_backed_photos(&dir), hold: hold.clone() };+ let server = std::thread::spawn(move || Server::new(Box::new(backend)).serve(BufReader::new(input), write).unwrap());+ let (tx, rx) = std::sync::mpsc::channel();+ let reader = std::thread::spawn(move || {+ for line in BufReader::new(output).lines() {+ let value: Value = serde_json::from_str(&line.unwrap()).unwrap();+ if tx.send(value).is_err() {+ break;+ }+ }+ });+ writeln!(send, "{}", call(1, "query_photos", json!({"limit":8}))).unwrap();+ let query = next_msg(&rx);+ let photos = query["result"]["structuredContent"]["photos"].as_array().unwrap();+ assert_query_photos(photos);+ let ids: Vec<_> = photos.iter().map(|p| p["id"].clone()).collect();+ run_complete_export(&mut send, &rx, &hold, &ids, &dir);+ let out = dir.join("cancelled");+ std::fs::create_dir_all(&out).unwrap();+ let decoy = out.join("photo999.png");+ std::fs::write(&decoy, b"unrelated existing output").unwrap();+ run_cancelled_export(&mut send, &rx, &hold, &ids, &out);+ assert_cancelled_output(&out, &decoy);+ assert_complete_output(&dir);drop(send);// The fixture's files stay in place until the server (which owns the session) and the reader// have finished: the session reads the originals; the output is what the checks above read.diff --git a/crates/ui-egui/src/headless/tests.rs b/crates/ui-egui/src/headless/tests.rsindex f38ed636a..13bd7a2ae 100644--- a/crates/ui-egui/src/headless/tests.rs+++ b/crates/ui-egui/src/headless/tests.rs@@ -2775,31 +2775,35 @@ fn browse_a_local_folder() {let _ = std::fs::remove_dir_all(&dir);}-/// Local: Remove from Local hides a sidebar location (nothing on disk changes) and the-/// "Show hidden locations" row puts it back. The folder is browsed and kept the way Browse-/// Folder… does it, in the temporary folder — on Windows beneath Home, whose tree must not-/// open down to the hidden folder and push the restore row out of view.-#[test]-fn local_location_can_be_hidden_and_restored() {- let size = [1300.0, 900.0];- let mut h = demo(size);+fn hide_rects(h: &mut Headless) -> Vec<(String, Vec<f64>)> {+ let w = h.request("ui.widgets", json!({"filter": "source:local:"}), Duration::from_secs(10));+ w["result"]+ .as_array()+ .unwrap()+ .iter()+ .map(|x| (x["id"].as_str().unwrap().to_string(), x["rect"].as_array().unwrap().iter().filter_map(|v| v.as_f64()).collect()))+ .collect()+}++fn hide_ids(h: &mut Headless) -> Vec<String> {+ hide_rects(h).into_iter().map(|(id, _)| id).collect()+}++fn hide_menu(h: &mut Headless) -> Vec<String> {+ let w = h.request("ui.widgets", json!({"filter": "local:restoreHidden:"}), Duration::from_secs(10));+ w["result"].as_array().unwrap().iter().map(|x| x["id"].as_str().unwrap().to_string()).collect()+}++/// Hides `path` through the command and settles the frames.+fn hide_path(h: &mut Headless, path: &str) {+ let r = h.request("engine.execute", json!({"command": "local.hide", "params": {"path": path}}), Duration::from_secs(10));+ assert_eq!(r["ok"], true, "{r}");+ h.settle(SETTLE);+}++/// Keeps and browses `path` the way Browse Folder… does; returns whether anything was hidden before.+fn hide_browse_and_hide(h: &mut Headless, path: &str, size: [f32; 2]) -> bool {let t = Duration::from_secs(10);- let dir = std::env::temp_dir().join(format!("lc-ui-hide-{}", std::process::id()));- let _ = std::fs::remove_dir_all(&dir);- std::fs::create_dir_all(&dir).unwrap();- let path = dir.to_string_lossy().to_string();- let rects = |h: &mut Headless| -> Vec<(String, Vec<f64>)> {- let w = h.request("ui.widgets", json!({"filter": "source:local:"}), t);- w["result"]- .as_array()- .unwrap()- .iter()- .map(|x| (x["id"].as_str().unwrap().to_string(), x["rect"].as_array().unwrap().iter().filter_map(|v| v.as_f64()).collect()))- .collect()- };- let ids = |h: &mut Headless| -> Vec<String> { rects(h).into_iter().map(|(id, _)| id).collect() };- h.request("ui.set", json!({"leftPanel": true}), t);- h.hide_home_above(&dir);// Browse Folder… browses the picked folder and keeps it in Local within one frame; a// request runs frames, so keep it first (no frame sees it browsed but not yet kept)let r = h.request("engine.execute", json!({"command": "local.addRoot", "params": {"path": path}}), t);@@ -2808,76 +2812,95 @@ fn local_location_can_be_hidden_and_restored() {assert_eq!(r["ok"], true, "{r}");h.settle(SETTLE);let row = format!("source:local:{path}");- assert!(h.step_until(t, |h| h.app.widgets.iter().any(|(w, _)| *w == row)), "the browsed folder is listed: {:?}", ids(&mut h));+ assert!(h.step_until(t, |h| h.app.widgets.iter().any(|(w, _)| *w == row)), "the browsed folder is listed: {:?}", hide_ids(h));// the "Show hidden locations" row appears only while something is hiddenlet hidden_before = !h.app.ui.hidden_locations.is_empty();- assert_eq!(ids(&mut h).iter().any(|i| i == "source:local:restoreHidden"), hidden_before);+ assert_eq!(hide_ids(h).iter().any(|i| i == "source:local:restoreHidden"), hidden_before);// hide it while it is still being browsed- let r = h.request("engine.execute", json!({"command": "local.hide", "params": {"path": path}}), t);- assert_eq!(r["ok"], true, "{r}");- h.settle(SETTLE);+ hide_path(h, path);// give any listing a reveal would wait for time to arrivefor _ in 0..20 {h.step();std::thread::sleep(Duration::from_millis(5));}h.settle(SETTLE);- let after = rects(&mut h);+ let after = hide_rects(h);let after_ids: Vec<&str> = after.iter().map(|(id, _)| id.as_str()).collect();assert!(!after_ids.contains(&format!("source:local:{path}").as_str()), "{after_ids:?}");let restore = after.iter().find(|(id, _)| id == "source:local:restoreHidden").map(|(_, r)| r.clone());let restore = restore.unwrap_or_else(|| panic!("no restore row: {after_ids:?}"));assert!(restore[1] >= 0.0 && restore[1] + restore[3] <= f64::from(size[1]), "the restore row is in view: {restore:?} {after_ids:?}");assert!(h.app.session.browse.is_some(), "hiding does not stop browsing");- assert!(dir.is_dir(), "the folder itself is untouched");- // a second hidden place: the row lists them, and each comes back on its own (issue #2114:- // the row used to bring every hidden place back at once)- let dir2 = std::env::temp_dir().join(format!("lc-ui-hide-{}-b", std::process::id()));- let _ = std::fs::remove_dir_all(&dir2);- std::fs::create_dir_all(&dir2).unwrap();- let path2 = dir2.to_string_lossy().to_string();+ hidden_before+}++/// A second hidden place: the row lists them, and each comes back on its own (issue #2114:+/// the row used to bring every hidden place back at once).+fn hide_second_place_restores_alone(h: &mut Headless, path: &str, path2: &str) {+ let t = Duration::from_secs(10);for (command, params) in [("local.addRoot", json!({"path": path2})), ("local.hide", json!({"path": path2}))] {let r = h.request("engine.execute", json!({"command": command, "params": params}), t);assert_eq!(r["ok"], true, "{r}");}h.settle(SETTLE);- let menu = |h: &mut Headless| -> Vec<String> {- let w = h.request("ui.widgets", json!({"filter": "local:restoreHidden:"}), t);- w["result"].as_array().unwrap().iter().map(|x| x["id"].as_str().unwrap().to_string()).collect()- };- assert!(menu(&mut h).is_empty(), "the list opens from the row");+ assert!(hide_menu(h).is_empty(), "the list opens from the row");assert_eq!(h.request("ui.clickWidget", json!({"id": "source:local:restoreHidden"}), t)["ok"], true);h.settle(SETTLE);- let items = menu(&mut h);+ let items = hide_menu(h);assert!(items.contains(&format!("local:restoreHidden:{path}")) && items.contains(&"local:restoreHidden:all".to_string()), "{items:?}");assert_eq!(h.request("ui.clickWidget", json!({"id": format!("local:restoreHidden:{path}")}), t)["ok"], true);h.settle(SETTLE);- assert!(!h.app.ui.hidden_locations.iter().any(|x| x == &path), "{:?}", h.app.ui.hidden_locations);- assert!(h.app.ui.hidden_locations.iter().any(|x| x == &path2), "the other place stays hidden");- assert!(ids(&mut h).iter().any(|i| i == "source:local:restoreHidden"), "still something to restore");+ assert!(!h.app.ui.hidden_locations.iter().any(|x| x == path), "{:?}", h.app.ui.hidden_locations);+ assert!(h.app.ui.hidden_locations.iter().any(|x| x == path2), "the other place stays hidden");+ assert!(hide_ids(h).iter().any(|i| i == "source:local:restoreHidden"), "still something to restore");+}++fn hide_restore_all_then_single(h: &mut Headless, path: &str, path2: &str, hidden_before: bool) {+ let t = Duration::from_secs(10);// two hidden again: Restore All brings every one back- let r = h.request("engine.execute", json!({"command": "local.hide", "params": {"path": path}}), t);- assert_eq!(r["ok"], true, "{r}");- h.settle(SETTLE);+ hide_path(h, path);assert!(h.app.ui.hidden_locations.len() >= 2, "{:?}", h.app.ui.hidden_locations);assert_eq!(h.request("ui.clickWidget", json!({"id": "source:local:restoreHidden"}), t)["ok"], true);h.settle(SETTLE);assert_eq!(h.request("ui.clickWidget", json!({"id": "local:restoreHidden:all"}), t)["ok"], true);h.settle(SETTLE);assert!(h.app.ui.hidden_locations.is_empty(), "{:?}", h.app.ui.hidden_locations);- assert!(!ids(&mut h).iter().any(|i| i == "source:local:restoreHidden"), "nothing left to restore");+ assert!(!hide_ids(h).iter().any(|i| i == "source:local:restoreHidden"), "nothing left to restore");// one hidden: the row brings it back itself, no list- let r = h.request("engine.execute", json!({"command": "local.hide", "params": {"path": path2}}), t);- assert_eq!(r["ok"], true, "{r}");- h.settle(SETTLE);+ hide_path(h, path2);assert_eq!(h.request("ui.clickWidget", json!({"id": "source:local:restoreHidden"}), t)["ok"], true);h.settle(SETTLE);- assert!(menu(&mut h).is_empty(), "no list for a single hidden place");+ assert!(hide_menu(h).is_empty(), "no list for a single hidden place");assert!(h.app.ui.hidden_locations.is_empty(), "{:?}", h.app.ui.hidden_locations);if !hidden_before {// (with Home hidden for this test, the folder is back inside Home's tree instead)- assert!(ids(&mut h).contains(&format!("source:local:{path}")));+ assert!(hide_ids(h).contains(&format!("source:local:{path}")));}+}++/// Local: Remove from Local hides a sidebar location (nothing on disk changes) and the+/// "Show hidden locations" row puts it back. The folder is browsed and kept the way Browse+/// Folder… does it, in the temporary folder — on Windows beneath Home, whose tree must not+/// open down to the hidden folder and push the restore row out of view.+#[test]+fn local_location_can_be_hidden_and_restored() {+ let size = [1300.0, 900.0];+ let mut h = demo(size);+ let t = Duration::from_secs(10);+ let dir = std::env::temp_dir().join(format!("lc-ui-hide-{}", std::process::id()));+ let _ = std::fs::remove_dir_all(&dir);+ std::fs::create_dir_all(&dir).unwrap();+ let path = dir.to_string_lossy().to_string();+ h.request("ui.set", json!({"leftPanel": true}), t);+ h.hide_home_above(&dir);+ let hidden_before = hide_browse_and_hide(&mut h, &path, size);+ assert!(dir.is_dir(), "the folder itself is untouched");+ let dir2 = std::env::temp_dir().join(format!("lc-ui-hide-{}-b", std::process::id()));+ let _ = std::fs::remove_dir_all(&dir2);+ std::fs::create_dir_all(&dir2).unwrap();+ let path2 = dir2.to_string_lossy().to_string();+ hide_second_place_restores_alone(&mut h, &path, &path2);+ hide_restore_all_then_single(&mut h, &path, &path2, hidden_before);let _ = std::fs::remove_dir_all(&dir);let _ = std::fs::remove_dir_all(&dir2);}diff --git a/crates/ui-egui/src/i18n/tests.rs b/crates/ui-egui/src/i18n/tests.rsindex 2a44072f0..77bbc14cb 100644--- a/crates/ui-egui/src/i18n/tests.rs+++ b/crates/ui-egui/src/i18n/tests.rs@@ -214,6 +214,32 @@ fn switching_language_translates_and_restores() {assert_eq!(tr("Exposure"), "Exposure");}+fn assert_format_specs(language: &Locale) {+ let text = tr_format!("{count} smart preview{} · {:.1} MB", "s", 12.345, count = 3);+ assert!(text.contains("12.3") && !text.contains("12.34"), "{language:?}: {text}");+ let merging = tr_format!("Merging… {stage} {:.0}%", 42.4, stage = "Aligning");+ assert!(merging.contains("42%"), "{language:?}: {merging}");+ let delta = tr_format!("{label} {d:+} on every selected photo", label = "Exposure", d = 5);+ assert!(delta.contains("+5"), "{language:?}: {delta}");+ let reading = tr_format!("Reading photos… {} of {}", 3, 10);+ let (three, ten) = (reading.find('3'), reading.find("10"));+ assert!(three.is_some() && ten.is_some(), "{language:?}: {reading}");+}++fn assert_format_values_kept(language: &Locale) {+ let name = "Color 1234.56 {title} 日本語";+ let added = tr_format!("Added {n} photo{} to “{}”", "s", name, n = 22);+ assert!(added.contains(name) && added.contains("22"), "{language:?}: {added}");+ for n in [0, 1, 2, 5, 22] {+ let imported = tr_format!("Imported {} photo{}", n, if n == 1 { "" } else { "s" });+ assert!(imported.contains(&n.to_string()), "{language:?}: {imported}");+ }+ // The trailing argument is queue progress, not an English plural suffix.+ let queued = tr_format!(" · {queued} waiting", queued = 5);+ let denoising = tr_format!("Denoising {name}: {done} of {total} tiles{}", queued, name = "IMG.CR3", done = 1, total = 4);+ assert!(denoising.contains("IMG.CR3") && denoising.contains('5'), "{language:?}: {denoising}");+}+/// Format strings carry their values in every language, and a language without a translation/// falls back to the English format rather than dropping the values.#[test]@@ -228,26 +254,8 @@ fn formats_render_in_every_language() {// text (an album name with braces and CJK) and counts are never dropped.for language in Locale::ALL {set_language(*language);- let text = tr_format!("{count} smart preview{} · {:.1} MB", "s", 12.345, count = 3);- assert!(text.contains("12.3") && !text.contains("12.34"), "{language:?}: {text}");- let merging = tr_format!("Merging… {stage} {:.0}%", 42.4, stage = "Aligning");- assert!(merging.contains("42%"), "{language:?}: {merging}");- let delta = tr_format!("{label} {d:+} on every selected photo", label = "Exposure", d = 5);- assert!(delta.contains("+5"), "{language:?}: {delta}");- let reading = tr_format!("Reading photos… {} of {}", 3, 10);- let (three, ten) = (reading.find('3'), reading.find("10"));- assert!(three.is_some() && ten.is_some(), "{language:?}: {reading}");- let name = "Color 1234.56 {title} 日本語";- let added = tr_format!("Added {n} photo{} to “{}”", "s", name, n = 22);- assert!(added.contains(name) && added.contains("22"), "{language:?}: {added}");- for n in [0, 1, 2, 5, 22] {- let imported = tr_format!("Imported {} photo{}", n, if n == 1 { "" } else { "s" });- assert!(imported.contains(&n.to_string()), "{language:?}: {imported}");- }- // The trailing argument is queue progress, not an English plural suffix.- let queued = tr_format!(" · {queued} waiting", queued = 5);- let denoising = tr_format!("Denoising {name}: {done} of {total} tiles{}", queued, name = "IMG.CR3", done = 1, total = 4);- assert!(denoising.contains("IMG.CR3") && denoising.contains('5'), "{language:?}: {denoising}");+ assert_format_specs(language);+ assert_format_values_kept(language);}set_language(Locale::En);assert_eq!(tr_format!("Reading photos… {} of {}", 3, 10), "Reading photos… 3 of 10");@@ -1128,24 +1136,7 @@ fn a_dropped_photos_notice_names_every_outcome_of_the_import_and_is_silent_for_dlet _ = std::fs::remove_dir_all(dir);}-/// Polish: the menu and control channel select it, dates read day.month.year, and every count-/// reads right for any number. Polish has three plural forms (1 zdjęcie, 2 zdjęcia, 5 zdjęć), so-/// counts follow their noun ("Zaimportowane zdjęcia: 22") instead of a form that fits only some.-#[test]-fn polish_switches_formats_dates_and_reads_every_count() {- use crate::control::{ControlRequest, Outcome};- let mut app = crate::LightcraftApp::new(lightcraft_engine::Session::with_demo(), Default::default());- app.run("app.language.polish", serde_json::json!({})).unwrap();- assert_eq!(app.ui.language, Locale::Pl);- assert_eq!(Locale::Pl.name(), "Polski");- assert_eq!(crate::menubar::checked(&app, "app.language.polish"), Some(true));- assert_eq!(tr("File"), "Plik");- assert_eq!(tr("Exposure"), "Ekspozycja");- assert_eq!(date_group_label("2026-09-20", false), "Niedziela, 20.09.2026");- assert_eq!(date_group_label("2026-09-20", true), "Niedziela, 20");- assert_eq!(date_group_label("2026-09", false), "09.2026");- assert_eq!(date_group_label("2026", false), "2026");- assert_eq!(display_time("2026-09-20T16:04:05"), "Niedziela, 20.09.2026 16:04:05");+fn assert_polish_counts() {for n in [0, 1, 2, 3, 4, 5, 12, 21, 22, 25, 111] {let s = if n == 1 { "" } else { "s" };assert_eq!(tr_format!("Imported {} photo{}", n, s), format!("Zaimportowane zdjęcia: {n}"));@@ -1159,20 +1150,20 @@ fn polish_switches_formats_dates_and_reads_every_count() {assert_eq!(tr_format!("Delete {n} Photos", n = n), format!("Usuń zdjęcia ({n})"));assert_eq!(tr_format!("{n} preset{}", s, n = n), format!("Ustawienia: {n}"));}- let name = String::from("Color 1234.56 {title} 日本語");- assert_eq!(tr_format!("Added {n} photo{} to “{}”", "s", name, n = 22), format!("Dodano do „{name}”: 22"));- let saved = serde_json::to_string(&app.ui).unwrap();- assert_eq!(serde_json::from_str::<crate::state::UiState>(&saved).unwrap().language, Locale::Pl);- let ctx = egui::Context::default();+}++fn assert_polish_selected_by_tags(app: &mut crate::LightcraftApp, ctx: &egui::Context) {+ use crate::control::{ControlRequest, Outcome};for tag in ["pl", "pl-PL", "pl_PL.UTF-8", "PL-pl"] {assert_eq!(Locale::parse_tag(tag), Some(Locale::Pl), "{tag}");let (request, _) = ControlRequest::new("ui.set", serde_json::json!({"language": tag}));- let Outcome::Done(reply) = crate::control::handle(&mut app, &ctx, &request) else { panic!("expected reply") };+ let Outcome::Done(reply) = crate::control::handle(app, ctx, &request) else { panic!("expected reply") };assert_eq!(reply["ok"], true);assert_eq!(language(), Locale::Pl);}- let text = painted_text(&ctx, &mut app, Locale::Pl);- assert!(text.contains("Plik") && text.contains("Ekspozycja"), "{text}");+}++fn assert_polish_glyphs(ctx: &egui::Context) {ctx.fonts_mut(|fonts| {for family in [egui::FontFamily::Proportional, egui::FontFamily::Name(crate::theme::FONT_SEMIBOLD.into())] {let font = egui::FontId::new(13.0, family);@@ -1181,5 +1172,34 @@ fn polish_switches_formats_dates_and_reads_every_count() {}}});+}++/// Polish: the menu and control channel select it, dates read day.month.year, and every count+/// reads right for any number. Polish has three plural forms (1 zdjęcie, 2 zdjęcia, 5 zdjęć), so+/// counts follow their noun ("Zaimportowane zdjęcia: 22") instead of a form that fits only some.+#[test]+fn polish_switches_formats_dates_and_reads_every_count() {+ let mut app = crate::LightcraftApp::new(lightcraft_engine::Session::with_demo(), Default::default());+ app.run("app.language.polish", serde_json::json!({})).unwrap();+ assert_eq!(app.ui.language, Locale::Pl);+ assert_eq!(Locale::Pl.name(), "Polski");+ assert_eq!(crate::menubar::checked(&app, "app.language.polish"), Some(true));+ assert_eq!(tr("File"), "Plik");+ assert_eq!(tr("Exposure"), "Ekspozycja");+ assert_eq!(date_group_label("2026-09-20", false), "Niedziela, 20.09.2026");+ assert_eq!(date_group_label("2026-09-20", true), "Niedziela, 20");+ assert_eq!(date_group_label("2026-09", false), "09.2026");+ assert_eq!(date_group_label("2026", false), "2026");+ assert_eq!(display_time("2026-09-20T16:04:05"), "Niedziela, 20.09.2026 16:04:05");+ assert_polish_counts();+ let name = String::from("Color 1234.56 {title} 日本語");+ assert_eq!(tr_format!("Added {n} photo{} to “{}”", "s", name, n = 22), format!("Dodano do „{name}”: 22"));+ let saved = serde_json::to_string(&app.ui).unwrap();+ assert_eq!(serde_json::from_str::<crate::state::UiState>(&saved).unwrap().language, Locale::Pl);+ let ctx = egui::Context::default();+ assert_polish_selected_by_tags(&mut app, &ctx);+ let text = painted_text(&ctx, &mut app, Locale::Pl);+ assert!(text.contains("Plik") && text.contains("Ekspozycja"), "{text}");+ assert_polish_glyphs(&ctx);set_language(Locale::En);}diff --git a/crates/ui-egui/src/render/thumbnail_tests.rs b/crates/ui-egui/src/render/thumbnail_tests.rsindex eaf4e8f2f..2fcd6c5ab 100644--- a/crates/ui-egui/src/render/thumbnail_tests.rs+++ b/crates/ui-egui/src/render/thumbnail_tests.rs@@ -774,66 +774,81 @@ fn undo_to_existing_texture_supersedes_pending_edit() {assert_eq!(app.renderer.thumb(PhotoId(1)).unwrap().pixels.as_ref().unwrap().pixels, original.pixels);}-#[test]-fn cells_at_different_thumbnail_buckets_keep_one_pending_request() {- let (mut app, work, ctx) = fixture();+/// First request: other buckets must not replace the pending job. Returns the pending key.+fn thumb_buckets_pending_request(app: &mut crate::LightcraftApp, work: &std::rc::Rc<std::cell::RefCell<Work>>, ctx: &egui::Context) -> u64 {let id = PhotoId(1);let slot = Slot::Thumb(id);// A print page's cells show the same photo at different sizes. Before any texture arrives,// each frame's other bucket used to replace (and restart) the pending job.- crate::panels::grid::request_thumb(&mut app, id, 256, 10);+ crate::panels::grid::request_thumb(app, id, 256, 10);let built = app.renderer.thumb_jobs_built;assert_eq!(built, 1);- let (submitted, pending) = take_job(&work);+ let (submitted, pending) = take_job(work);assert_eq!(submitted, slot);for _ in 0..12 {- crate::panels::grid::request_thumb(&mut app, id, 512, 10);- crate::panels::grid::request_thumb(&mut app, id, 384, 8);- crate::panels::grid::request_thumb(&mut app, id, 256, 10);+ crate::panels::grid::request_thumb(app, id, 512, 10);+ crate::panels::grid::request_thumb(app, id, 384, 8);+ crate::panels::grid::request_thumb(app, id, 256, 10);}assert_eq!(app.renderer.thumb_jobs_built, built, "another bucket must not replace the pending thumbnail");assert!(work.borrow().jobs.is_empty(), "the pending render is not restarted");assert_eq!(app.renderer.pending[&slot].0, pending.key);let pending_key = pending.key;- finish(&mut app, &work, &ctx, slot, pending.run());+ finish(app, work, ctx, slot, pending.run());assert_eq!(app.renderer.textures[&slot].key, pending_key);assert_eq!(app.renderer.thumb_inputs[&id].1, 256, "the completed request's bucket is remembered");assert!(!app.renderer.is_pending(slot));+ pending_key+}+/// A larger bucket still upgrades; smaller cells wait behind it. Returns the larger key.+fn thumb_buckets_larger_upgrades(+ app: &mut crate::LightcraftApp,+ work: &std::rc::Rc<std::cell::RefCell<Work>>,+ ctx: &egui::Context,+ pending_key: u64,+) -> u64 {+ let id = PhotoId(1);+ let slot = Slot::Thumb(id);// With a completed 256 thumbnail, the larger cell asks for its bucket once; the smaller// cells then wait behind it instead of replacing it back every frame.let built = app.renderer.thumb_jobs_built;- crate::panels::grid::request_thumb(&mut app, id, 512, 10);+ crate::panels::grid::request_thumb(app, id, 512, 10);assert_eq!(app.renderer.thumb_jobs_built, built + 1, "a larger bucket still upgrades");- let (submitted, larger) = take_job(&work);+ let (submitted, larger) = take_job(work);assert_eq!(submitted, slot);assert_ne!(larger.key, pending_key);let larger_key = app.renderer.pending[&slot].0;assert_eq!(larger_key, larger.key);for _ in 0..12 {- crate::panels::grid::request_thumb(&mut app, id, 512, 10);- crate::panels::grid::request_thumb(&mut app, id, 384, 10);- crate::panels::grid::request_thumb(&mut app, id, 256, 10);+ crate::panels::grid::request_thumb(app, id, 512, 10);+ crate::panels::grid::request_thumb(app, id, 384, 10);+ crate::panels::grid::request_thumb(app, id, 256, 10);}assert_eq!(app.renderer.thumb_jobs_built, built + 1, "smaller cells keep the larger render in flight");assert!(work.borrow().jobs.is_empty(), "the larger render is not restarted");assert_eq!(app.renderer.pending[&slot].0, larger_key);assert_eq!(app.renderer.thumb_inputs[&id].1, 512, "the in-flight bucket is still the larger one");- finish(&mut app, &work, &ctx, slot, larger.run());+ finish(app, work, ctx, slot, larger.run());assert_eq!(app.renderer.textures[&slot].key, larger_key);assert_eq!(app.renderer.thumb_inputs[&id].1, 512);assert!(!app.renderer.is_pending(slot));+ larger_key+}+fn thumb_buckets_largest_serves_smaller(app: &mut crate::LightcraftApp, work: &std::rc::Rc<std::cell::RefCell<Work>>, larger_key: u64) {+ let id = PhotoId(1);+ let slot = Slot::Thumb(id);// Once the largest visible bucket is complete, every smaller cell reuses those pixels.// The 8x8 fixture texture cannot show its requested edge, so the remembered bucket, key// and photo identity are what prove no render was built. Repeated frames at all sizes// (the old bug alternated 256/512 forever) must settle with nothing further requested.let built = app.renderer.thumb_jobs_built;for _ in 0..24 {- crate::panels::grid::request_thumb(&mut app, id, 256, 10);- crate::panels::grid::request_thumb(&mut app, id, 384, 10);- crate::panels::grid::request_thumb(&mut app, id, 512, 10);- crate::panels::grid::request_thumb(&mut app, id, 384, 8);+ crate::panels::grid::request_thumb(app, id, 256, 10);+ crate::panels::grid::request_thumb(app, id, 384, 10);+ crate::panels::grid::request_thumb(app, id, 512, 10);+ crate::panels::grid::request_thumb(app, id, 384, 8);}assert_eq!(app.renderer.thumb_jobs_built, built, "completed larger thumbnails serve smaller cells");assert!(work.borrow().jobs.is_empty());@@ -841,7 +856,16 @@ fn cells_at_different_thumbnail_buckets_keep_one_pending_request() {assert_eq!(app.renderer.textures[&slot].key, larger_key);assert_eq!(app.renderer.thumb_inputs[&id].1, 512);assert_eq!(app.renderer.thumb_inputs[&id].2, larger_key);+}+fn thumb_buckets_edit_requests_again(+ app: &mut crate::LightcraftApp,+ work: &std::rc::Rc<std::cell::RefCell<Work>>,+ ctx: &egui::Context,+ larger_key: u64,+) {+ let id = PhotoId(1);+ let slot = Slot::Thumb(id);// The renderer remembers the photo through a `Weak<Photo>` only. That is enough for// `Catalog`'s `Arc::make_mut` to copy the photo on edit (std: an existing weak pointer// forces a new allocation even with a single strong reference), so the identity below is@@ -861,18 +885,27 @@ fn cells_at_different_thumbnail_buckets_keep_one_pending_request() {assert_eq!(remembered.strong_count(), 0, "the renderer's Weak now points at the old, unowned allocation");assert_eq!(Arc::strong_count(current), 1, "the edit left one strong owner; no extra Arc was needed");let built = app.renderer.thumb_jobs_built;- crate::panels::grid::request_thumb(&mut app, id, 256, 10);+ crate::panels::grid::request_thumb(app, id, 256, 10);assert_eq!(app.renderer.thumb_jobs_built, built + 1, "an edited photo is requested again");- let (submitted, edited) = take_job(&work);+ let (submitted, edited) = take_job(work);assert_eq!(submitted, slot);assert_ne!(edited.key, larger_key);let edited_key = edited.key;- finish(&mut app, &work, &ctx, slot, edited.run());+ finish(app, work, ctx, slot, edited.run());assert_eq!(app.renderer.textures[&slot].key, edited_key);assert_eq!(app.renderer.thumb_inputs[&id].1, 256);assert!(!app.renderer.is_pending(slot));}+#[test]+fn cells_at_different_thumbnail_buckets_keep_one_pending_request() {+ let (mut app, work, ctx) = fixture();+ let pending_key = thumb_buckets_pending_request(&mut app, &work, &ctx);+ let larger_key = thumb_buckets_larger_upgrades(&mut app, &work, &ctx, pending_key);+ thumb_buckets_largest_serves_smaller(&mut app, &work, larger_key);+ thumb_buckets_edit_requests_again(&mut app, &work, &ctx, larger_key);+}+/// The remembered larger bucket is not a picture by itself: once its texture is evicted, a/// smaller cell must render again rather than trust the stale record.#[test]diff --git a/crates/ui-egui/src/tests/open_lightroom.rs b/crates/ui-egui/src/tests/open_lightroom.rsindex d97f9d0e8..684883aa0 100644--- a/crates/ui-egui/src/tests/open_lightroom.rs+++ b/crates/ui-egui/src/tests/open_lightroom.rs@@ -22,8 +22,16 @@ fn names(dir: &std::path::Path) -> Vec<std::ffi::OsString> {v}-#[test]-fn open_library_on_a_lightroom_catalog_offers_its_import() {+struct Fx {+ dir: std::path::PathBuf,+ lib: std::path::PathBuf,+ lr: std::path::PathBuf,+ lrcat: std::path::PathBuf,+ before: Vec<std::ffi::OsString>,+ photos: usize,+}++fn setup() -> (Headless, Fx) {let dir = std::env::temp_dir().join(format!("lc-ui-openlrcat-{}", std::process::id()));let _ = std::fs::remove_dir_all(&dir);let lib = dir.join("LightCraft Library");@@ -52,7 +60,12 @@ fn open_library_on_a_lightroom_catalog_offers_its_import() {};let mut h = Headless::new(LightcraftApp::new(session, services), [1200.0, 800.0], 1.0);h.step();+ (h, Fx { dir, lib, lr, lrcat, before, photos })+}+fn offer_and_cancel(h: &mut Headless, fx: &Fx) {+ let Fx { lib, lr, lrcat, before, photos, .. } = fx;+ let (photos, lib, lr, lrcat, before) = (*photos, lib.clone(), lr.clone(), lrcat.clone(), before.clone());// File ▸ Open Library…, the Lightroom folder chosen in the folder dialoglet r = h.app.run("app.openLibrary", json!({})).unwrap();assert_eq!(r["opened"], false, "{r}");@@ -64,7 +77,7 @@ fn open_library_on_a_lightroom_catalog_offers_its_import() {"{:?}",h.app.ui.dialog);- assert!(has(&h, "button:dialogOk") && has(&h, "button:dialogCancel"));+ assert!(has(h, "button:dialogOk") && has(h, "button:dialogCancel"));// the library open before is still open, and nothing was made in Lightroom's folderassert_eq!(h.app.session.library.as_ref().map(|l| l.dir.clone()), Some(lib.clone()));assert_eq!(h.app.session.catalog.len(), photos);@@ -79,7 +92,10 @@ fn open_library_on_a_lightroom_catalog_offers_its_import() {h.step();assert!(h.app.ui.dialog.is_none());assert!(h.app.lightroom.is_none() && h.app.lightroom_last.is_none());+}+fn reoffer_import_and_merge(h: &mut Headless, fx: &Fx) {+ let (lib, lr, lrcat, before) = (fx.lib.clone(), fx.lr.clone(), fx.lrcat.clone(), fx.before.clone());// a previews folder given by path (control channel, agents): the same offerlet r = h.app.run("app.openLibrary", json!({"path": lr.join("Lightroom Catalog Previews.lrdata").to_string_lossy()})).unwrap();assert_eq!(r["lightroomCatalog"], json!(lrcat.to_string_lossy()), "{r}");@@ -108,6 +124,13 @@ fn open_library_on_a_lightroom_catalog_offers_its_import() {assert_eq!(last["path"], json!(lrcat), "{last}");assert_eq!(h.app.session.library.as_ref().map(|l| l.dir.clone()), Some(lib.clone()));assert_eq!(names(&lr), before, "the catalog is only read");+}++#[test]+fn open_library_on_a_lightroom_catalog_offers_its_import() {+ let (mut h, fx) = setup();+ offer_and_cancel(&mut h, &fx);+ reoffer_import_and_merge(&mut h, &fx);drop(h);- let _ = std::fs::remove_dir_all(&dir);+ let _ = std::fs::remove_dir_all(&fx.dir);}diff --git a/crates/ui-egui/src/tests/preview_limit.rs b/crates/ui-egui/src/tests/preview_limit.rsindex 07a30c8a5..3687199c9 100644--- a/crates/ui-egui/src/tests/preview_limit.rs+++ b/crates/ui-egui/src/tests/preview_limit.rs@@ -840,25 +840,8 @@ mod in_the_loupe {}}- // Given a 400 % view of a real 24 MP photo, when the first window is decoded and accepted and- // later drag ticks supersede each other, then the original stays in the cache and every later- // window is cut from it. The first accepted result is the actual Detail wiring's job: the- // window `request_window` asked for (respecting `defer_window`), drafted while the drag runs.- #[test]- fn a_drag_keeps_the_decoded_original_after_the_window_is_accepted() {- let (_fx, mut h, native) = detail();- let id = h.app.session.active().expect("a photo");- assert_eq!(native, WIDTH as usize);- assert_eq!(h.app.session.memory_report().full_source.bytes, 0, "fit needed no original");- h.app.session.media.set_on_screen(Some(id));- let work = Rc::new(RefCell::new(OffloadWork::default()));- h.app.renderer.set_offload(Box::new(RegionGate(work.clone())));- let discarded = h.app.renderer.discarded;- h.app.ui.zoom = crate::state::Zoom::Percent(400.0);- h.app.session.begin_interaction("Exposure").expect("a drag");-- let first = next_region_job(&mut h, &work);- let (first_key, first_request) = (first.key, first.request_id);+ fn drag_first_window(h: &mut Headless, work: &Rc<RefCell<OffloadWork>>, id: lightcraft_catalog::PhotoId) -> RenderJob {+ let first = next_region_job(h, work);let view = h.app.region_view.expect("Detail asked for a window");assert_eq!(view.photo, id);assert_eq!(view.full, (WIDTH as usize, HEIGHT as usize), "at 400 % the window's frame is the photo's own pixels");@@ -869,10 +852,20 @@ mod in_the_loupe {assert_eq!(first.request.quality, lightcraft_pipeline::Quality::Draft, "a drag drafts the window");assert_eq!(first.level, SourceLevel::Full);assert!(matches!(&first.source, SourceRef::File { .. }), "the first window decodes the real file");- assert_ne!(first_request, 0, "the renderer gave the request its own identity");+ assert_ne!(first.request_id, 0, "the renderer gave the request its own identity");+ first+ }+ /// An edit during the first decode waits; the first result is accepted with its original.+ fn drag_accepts_first_original(+ h: &mut Headless,+ work: &Rc<RefCell<OffloadWork>>,+ id: lightcraft_catalog::PhotoId,+ first: RenderJob,+ ) -> (u64, u64) {// An edit changes the desired window key while the first original is still held.// Detail must defer a second decode until this first result has populated the cache.+ let (first_key, first_request) = (first.key, first.request_id);let reply = h.request("engine.execute", json!({"command": "develop.set", "params": {"control": "light.exposure", "value": 0.5}}), T);assert_eq!(reply["ok"], true);h.step();@@ -880,14 +873,18 @@ mod in_the_loupe {assert_eq!(h.app.renderer.wanted(Slot::Region), Some(first_key));assert_eq!(h.app.session.memory_report().full_source.bytes, 0);- deliver(&work, Slot::Region, first.run());+ deliver(work, Slot::Region, first.run());h.step();assert!(h.app.region_view.is_some());assert_eq!(h.app.renderer.textures.get(&Slot::Region).map(|t| t.key), Some(first_key), "the first window arrived");assert!(h.app.session.memory_report().full_source.bytes >= WIDTH as usize * HEIGHT as usize * 3 * 4);assert!(h.app.session.media.has_source(id, SourceLevel::Full), "the original was accepted before any supersession");+ (first_key, first_request)+ }- let second = next_region_job(&mut h, &work);+ fn drag_later_windows_reuse_original(h: &mut Headless, work: &Rc<RefCell<OffloadWork>>, first: (u64, u64), discarded: u64) {+ let (first_key, first_request) = first;+ let second = next_region_job(h, work);let (second_key, second_request) = (second.key, second.request_id);assert_ne!(second_key, first_key);assert_ne!(second_request, first_request);@@ -896,11 +893,11 @@ mod in_the_loupe {let reply = h.request("engine.execute", json!({"command": "develop.set", "params": {"control": "light.exposure", "value": 1.0}}), T);assert_eq!(reply["ok"], true);- let third = next_region_job(&mut h, &work);+ let third = next_region_job(h, work);assert_ne!(third.key, second_key);assert_eq!(h.app.renderer.wanted(Slot::Region), Some(third.key));- deliver(&work, Slot::Region, second.run());+ deliver(work, Slot::Region, second.run());h.step();assert_eq!(h.app.renderer.textures.get(&Slot::Region).map(|t| t.key), Some(second_key), "the superseded draft still reached the screen");assert_eq!(h.app.renderer.wanted(Slot::Region), Some(third.key), "the newest request is still pending");@@ -909,6 +906,27 @@ mod in_the_loupe {assert!(matches!(&third.source, SourceRef::Loaded(_)), "the pending window still reuses the original");}+ // Given a 400 % view of a real 24 MP photo, when the first window is decoded and accepted and+ // later drag ticks supersede each other, then the original stays in the cache and every later+ // window is cut from it. The first accepted result is the actual Detail wiring's job: the+ // window `request_window` asked for (respecting `defer_window`), drafted while the drag runs.+ #[test]+ fn a_drag_keeps_the_decoded_original_after_the_window_is_accepted() {+ let (_fx, mut h, native) = detail();+ let id = h.app.session.active().expect("a photo");+ assert_eq!(native, WIDTH as usize);+ assert_eq!(h.app.session.memory_report().full_source.bytes, 0, "fit needed no original");+ h.app.session.media.set_on_screen(Some(id));+ let work = Rc::new(RefCell::new(OffloadWork::default()));+ h.app.renderer.set_offload(Box::new(RegionGate(work.clone())));+ let discarded = h.app.renderer.discarded;+ h.app.ui.zoom = crate::state::Zoom::Percent(400.0);+ h.app.session.begin_interaction("Exposure").expect("a drag");+ let first = drag_first_window(&mut h, &work, id);+ let keys = drag_accepts_first_original(&mut h, &work, id, first);+ drag_later_windows_reuse_original(&mut h, &work, keys, discarded);+ }+// The collector's accept branch on its own: a superseded window result still carries the// original it decoded, and `Renderer::poll` must insert it (`session.accept(&r)` at// render.rs:911) although a newer request for the same slot is pending. The Detail wiringdiff --git a/crates/ui-egui/src/tests/slideshow.rs b/crates/ui-egui/src/tests/slideshow.rsindex 01a468ed8..26c72c2cd 100644--- a/crates/ui-egui/src/tests/slideshow.rs+++ b/crates/ui-egui/src/tests/slideshow.rs@@ -871,20 +871,8 @@ fn settings_shows_the_titles_and_the_preview_shows_a_title_screen() {h.settle(SETTLE);}-/// Settings ▸ Slideshow ▸ Templates: built-ins listed, hover previews on the selected photo-/// without changing anything, a click applies, and the user's own templates are saved, updated,-/// renamed and deleted from the browser.-#[test]-fn template_browser_previews_on_hover_applies_and_manages_user_templates() {+fn tpl_hover_previews_without_changes(h: &mut Headless) -> lightcraft_engine::slide_template::SlideLook {use lightcraft_engine::slide_template::SlideLook;- let mut h = grid();- let dir = std::env::temp_dir().join(format!("lc-ui-sstpl-{}", std::process::id()));- let _ = std::fs::remove_dir_all(&dir);- h.app.session.slide_templates_dir = Some(dir.clone());- let first = h.app.session.visible_cloned()[0];- run(&mut h, "library.select", json!({"ids": [first.0]}));- run(&mut h, "view.slideshowOptions", json!({}));- assert!(h.step_until(SETTLE, |h| h.app.renderer.textures.get(&Slot::SlidePreview).is_some_and(|t| t.photo == first)));let has = |h: &Headless, w: &str| h.app.widgets.iter().any(|(id, _)| id == w);let rect = |h: &Headless, w: &str| h.app.widgets.iter().find(|(id, _)| id == w).map(|(_, r)| *r).unwrap();for w in [@@ -896,7 +884,7 @@ fn template_browser_previews_on_hover_applies_and_manages_user_templates() {"field:slideshowTemplateName","button:slideshowTemplateSave",] {- assert!(has(&h, w), "{w}");+ assert!(has(h, w), "{w}");}// hover: the preview shows Gallery Wall (its light grey wall in the margin), nothing changeslet before = SlideLook::of(&h.app.session);@@ -915,42 +903,55 @@ fn template_browser_previews_on_hover_applies_and_manages_user_templates() {assert!(h.step_until(SETTLE, grey), "the hovered template on the selected photo");assert_eq!(SlideLook::of(&h.app.session), before, "hovering changes nothing");assert!(h.app.session.slide_templates_previous.is_none());+ before+}++fn tpl_click_applies_and_saves_own(h: &mut Headless, dir: &std::path::Path) {+ let has = |h: &Headless, w: &str| h.app.widgets.iter().any(|(id, _)| id == w);// a click applies it- reveal(&mut h, "template:builtin:gallery-wall");+ reveal(h, "template:builtin:gallery-wall");let r = h.request("ui.clickWidget", json!({"id": "template:builtin:gallery-wall"}), T);assert_eq!(r["ok"], true, "{r}");h.step();assert!(h.app.session.slide_overlays.rating_stars.enabled && h.app.session.slide_layout.stroke_border);- assert!(has(&h, "template:previous"), "Previous settings appear");+ assert!(has(h, "template:previous"), "Previous settings appear");// save as a template of our own- reveal(&mut h, "field:slideshowTemplateName");+ reveal(h, "field:slideshowTemplateName");let r = h.request("ui.clickWidget", json!({"id": "field:slideshowTemplateName"}), T);assert_eq!(r["ok"], true, "{r}");let r = h.request("ui.text", json!({"text": "Holiday / 2026"}), T);assert_eq!(r["ok"], true, "{r}");- reveal(&mut h, "button:slideshowTemplateSave");+ reveal(h, "button:slideshowTemplateSave");let r = h.request("ui.clickWidget", json!({"id": "button:slideshowTemplateSave"}), T);assert_eq!(r["ok"], true, "{r}");h.step();assert!(dir.join("Holiday _ 2026.json").exists(), "the separator never makes a folder");h.step();- assert!(has(&h, "template:user:Holiday _ 2026"));+ assert!(has(h, "template:user:Holiday _ 2026"));+}++fn tpl_update_from_menu(h: &mut Headless) {+ let has = |h: &Headless, w: &str| h.app.widgets.iter().any(|(id, _)| id == w);// update it from its menu with changed settings- run(&mut h, "slideshow.layout", json!({"backdropColor": "#123456"}));- reveal(&mut h, "template:user:Holiday _ 2026");+ run(h, "slideshow.layout", json!({"backdropColor": "#123456"}));+ reveal(h, "template:user:Holiday _ 2026");let r = h.request("ui.clickWidget", json!({"id": "template:user:Holiday _ 2026", "button": "right"}), T);assert_eq!(r["ok"], true, "{r}");h.step();for w in ["button:slideshowTemplateUpdate", "button:slideshowTemplateRename", "button:slideshowTemplateExport", "button:slideshowTemplateDelete"]{- assert!(has(&h, w), "{w}");+ assert!(has(h, w), "{w}");}let r = h.request("ui.clickWidget", json!({"id": "button:slideshowTemplateUpdate"}), T);assert_eq!(r["ok"], true, "{r}");h.step();assert_eq!(h.app.session.slide_template("user:Holiday _ 2026").unwrap().look.layout.backdrop_color, [0x12, 0x34, 0x56]);+}++fn tpl_rename_in_place(h: &mut Headless) {+ let has = |h: &Headless, w: &str| h.app.widgets.iter().any(|(id, _)| id == w);// rename it in place- reveal(&mut h, "template:user:Holiday _ 2026");+ reveal(h, "template:user:Holiday _ 2026");let r = h.request("ui.clickWidget", json!({"id": "template:user:Holiday _ 2026", "button": "right"}), T);assert_eq!(r["ok"], true, "{r}");h.step();@@ -958,7 +959,7 @@ fn template_browser_previews_on_hover_applies_and_manages_user_templates() {assert_eq!(r["ok"], true, "{r}");h.step();h.step();- assert!(has(&h, "field:slideshowTemplateRename"));+ assert!(has(h, "field:slideshowTemplateRename"));let r = h.request("ui.key", json!({"key": "a", "cmd": true}), T);assert_eq!(r["ok"], true, "{r}");let r = h.request("ui.text", json!({"text": "Summer"}), T);@@ -967,9 +968,13 @@ fn template_browser_previews_on_hover_applies_and_manages_user_templates() {assert_eq!(r["ok"], true, "{r}");h.step();h.step();- assert!(has(&h, "template:user:Summer"), "{:?}", h.app.session.slide_templates().templates.iter().map(|t| t.id.clone()).collect::<Vec<_>>());+ assert!(has(h, "template:user:Summer"), "{:?}", h.app.session.slide_templates().templates.iter().map(|t| t.id.clone()).collect::<Vec<_>>());+}++fn tpl_delete_then_back_to_previous(h: &mut Headless, dir: &std::path::Path, before: &lightcraft_engine::slide_template::SlideLook) {+ use lightcraft_engine::slide_template::SlideLook;// delete it (after confirming)- reveal(&mut h, "template:user:Summer");+ reveal(h, "template:user:Summer");let r = h.request("ui.clickWidget", json!({"id": "template:user:Summer", "button": "right"}), T);assert_eq!(r["ok"], true, "{r}");h.step();@@ -983,12 +988,33 @@ fn template_browser_previews_on_hover_applies_and_manages_user_templates() {h.step();assert!(!dir.join("Summer.json").exists());// back to the settings before Gallery Wall- reveal(&mut h, "template:previous");+ reveal(h, "template:previous");let r = h.request("ui.clickWidget", json!({"id": "template:previous"}), T);assert_eq!(r["ok"], true, "{r}");h.step();assert_eq!(SlideLook::of(&h.app.session).overlays, before.overlays);h.settle(SETTLE);+}++/// Settings ▸ Slideshow ▸ Templates: built-ins listed, hover previews on the selected photo+/// without changing anything, a click applies, and the user's own templates are saved, updated,+/// renamed and deleted from the browser.+#[test]+fn template_browser_previews_on_hover_applies_and_manages_user_templates() {+ let mut h = grid();+ let dir = std::env::temp_dir().join(format!("lc-ui-sstpl-{}", std::process::id()));+ let _ = std::fs::remove_dir_all(&dir);+ h.app.session.slide_templates_dir = Some(dir.clone());+ let first = h.app.session.visible_cloned()[0];+ run(&mut h, "library.select", json!({"ids": [first.0]}));+ run(&mut h, "view.slideshowOptions", json!({}));+ assert!(h.step_until(SETTLE, |h| h.app.renderer.textures.get(&Slot::SlidePreview).is_some_and(|t| t.photo == first)));+ let before = tpl_hover_previews_without_changes(&mut h);+ tpl_click_applies_and_saves_own(&mut h, &dir);+ tpl_update_from_menu(&mut h);+ tpl_rename_in_place(&mut h);+ tpl_delete_then_back_to_previous(&mut h, &dir, &before);+ h.settle(SETTLE);let _ = std::fs::remove_dir_all(dir);}