LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge main into #243 (combine with #207's Windows test fixes: hide_home_above plus local.addRoot, FakeFs path normalising plus case folding)
Brandon Thomasd716d74af51a
diff --cc crates/engine/src/rename.rsindex 0479a4e59,788638416..259d51fcd--- a/crates/engine/src/rename.rs+++ b/crates/engine/src/rename.rs@@@ -774,12 -768,13 +774,13 @@@ mod testsfail: RefCell::new(Vec::new()),}}+ /// The model volume spells paths with `/`; the code under test joins them with the host's separator.+ fn norm(p: &Path) -> String {+ p.to_string_lossy().replace('\\', "/")+ }fn idx(&self, p: &Path) -> Option<usize> {- let p = p.to_string_lossy();- self.files- .borrow()- .iter()- .position(|(f, _)| if self.ci { folded_path(f) == folded_path(&p) } else { Path::new(f) == Path::new(p.as_ref()) })+ let p = Self::norm(p);- self.files.borrow().iter().position(|(f, _)| if self.ci { f.to_lowercase() == p.to_lowercase() } else { *f == p })++ self.files.borrow().iter().position(|(f, _)| if self.ci { folded_path(f) == folded_path(&p) } else { *f == p })}/// The listing: (exact path, contents), sorted.pub fn listing(&self) -> Vec<(String, String)> {@@@ -835,50 -830,10 +836,55 @@@fn file_photo(id: u64, path: &str) -> Photo {let name = Path::new(path).file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default();- Photo::new(PhotoId(id), Source::File { path: path.into() }, &name, "JPG", 1, 1, "2026-01-01T00:00:00")+ // the host's separator, so `dir.join(name)` in the planner spells the same path the same way+ let path = path.replace('/', std::path::MAIN_SEPARATOR_STR);+ Photo::new(PhotoId(id), Source::File { path }, &name, "JPG", 1, 1, "2026-01-01T00:00:00")}++ #[cfg(windows)]+ #[test]+ fn mixed_separator_noop_rename_preserves_files_catalog_and_undo() {+ let fs = FakeFs::new(true, &[("N:/photos/IMG.jpg", "image"), ("N:/photos/IMG.xmp", "edits"), ("N:/photos/other.jpg", "other")]);+ // Any attempt to move the unchanged photo (including rollback) must fail.+ fs.fail.borrow_mut().push("IMG".into());+ let mut s = Session::new();++ // spelled with `/` on purpose (not `file_photo`, which uses the host's separator)+ for (id, path) in [(1, "N:/photos/IMG.jpg"), (2, "N:/photos/other.jpg")] {- s.catalog.apply(Op::AddPhoto { photo: Box::new(file_photo(id, path)) }).unwrap();++ let name = Path::new(path).file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default();++ let photo = Photo::new(PhotoId(id), Source::File { path: path.into() }, &name, "JPG", 1, 1, "2026-01-01T00:00:00");++ s.catalog.apply(Op::AddPhoto { photo: Box::new(photo) }).unwrap();+ }+ let before = fs.listing();+ let plans = s.plan_rename_with(&fs, &[PhotoId(1)], "{name}", 1);+ assert_ne!(plans[0].from_path, plans[0].to_path, "fixture exercises different separator spelling");+ assert_eq!(s.apply_rename_with(&fs, &plans).unwrap(), 0);+ assert_eq!(fs.listing(), before);+ assert_eq!(s.catalog.photo(PhotoId(1)).unwrap().source, Source::File { path: "N:/photos/IMG.jpg".into() });+ assert!(s.undo.is_empty());+ move_file_with(&fs, "N:/photos/IMG.jpg", "N:/photos\\IMG.jpg").unwrap();+ let separator_only = Op::SetFile { id: PhotoId(1), file_name: "IMG.jpg".into(), source: Source::File { path: "N:/photos\\IMG.jpg".into() } };+ assert!(s.file_moves(&separator_only).is_empty());++ // A batch may combine that no-op with a genuine rename, without touching IMG or its sidecar.+ let mut batch = plans;+ batch.extend(s.plan_rename_with(&fs, &[PhotoId(2)], "renamed", 1));+ assert_eq!(s.apply_rename_with(&fs, &batch).unwrap(), 1);+ assert_eq!(+ fs.listing(),+ vec![+ ("N:/photos/IMG.jpg".into(), "image".into()),+ ("N:/photos/IMG.xmp".into(), "edits".into()),+ ("N:/photos/renamed.jpg".into(), "other".into())+ ]+ );+ let undo = &s.undo.last().unwrap().op;+ let moves = s.file_moves(undo);+ assert_eq!(moves.len(), 1);+ assert_eq!(Path::new(&moves[0].1), Path::new("N:/photos/other.jpg"));+ move_all(&fs, &moves).unwrap();+ s.catalog.apply(undo.clone()).unwrap();+ assert_eq!(fs.listing(), before);+ }/// Issue #95: a case-only rename is a real change on a case-insensitive volume and never/// replaces a different file that differs only by case on a case-sensitive one.diff --cc crates/ui-egui/src/headless.rsindex 4b8ec39e6,f6dc8a9bd..a77e34e71--- a/crates/ui-egui/src/headless.rs+++ b/crates/ui-egui/src/headless.rs@@@ -231,20 -229,18 +231,32 @@@ impl Headlessself.paint()}+ /// Wait for a fixture widget whose background directory listing may still be loading.+ #[cfg(test)]+ pub(crate) fn wait_for_widget(&mut self, id: &str, timeout: Duration) -> bool {+ let start = Instant::now();+ while let Some(remaining) = timeout.checked_sub(start.elapsed()) {+ let reply = self.request("ui.widgets", json!({"filter": id}), remaining);+ if reply["result"].as_array().is_some_and(|widgets| widgets.iter().any(|w| w["id"].as_str() == Some(id))) {+ return true;+ }+ std::thread::sleep(Duration::from_millis(1));+ }+ false+ }++ /// Tests that browse a folder in the temp directory expect it to be a Local location of its+ /// own. Where the temp directory lies inside the home folder (Windows), the sidebar lists it+ /// inside Home's tree instead, so hide Home for the test; elsewhere this does nothing.+ #[cfg(test)]+ pub(crate) fn hide_home_above(&mut self, path: &std::path::Path) {+ let home = std::env::var("HOME").or_else(|_| std::env::var("USERPROFILE")).unwrap_or_default();+ if !home.is_empty() && lightcraft_catalog::query::folder_within(&path.to_string_lossy(), &home) {+ let r = self.request("engine.execute", json!({"command": "local.hide", "params": {"path": home}}), Duration::from_secs(10));+ assert_eq!(r["ok"], true, "{r}");+ }+ }+/// Send a control-protocol request (see [`crate::control`]) and run frames until it is/// answered, then until its input has been consumed. Returns `{"ok": …, "result"|"error": …}`.pub fn request(&mut self, method: &str, params: Value, timeout: Duration) -> Value {@@@ -889,27 -852,18 +901,30 @@@ mod testslet _ = std::fs::remove_dir_all(&dir);std::fs::create_dir_all(&dir).unwrap();let path = dir.to_string_lossy().to_string();- let ids = |h: &mut Headless| -> Vec<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().filter_map(|x| x["id"].as_str().map(String::from)).collect()+ 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);- h.request("engine.execute", json!({"command": "library.browse", "params": {"path": path}}), t);+ // 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);+ assert_eq!(r["ok"], true, "{r}");+ let r = h.request("engine.execute", json!({"command": "library.browse", "params": {"path": path}}), t);+ assert_eq!(r["ok"], true, "{r}");h.settle(SETTLE);- assert!(ids(&mut h).contains(&format!("source:local:{path}")));+ assert!(h.wait_for_widget(&format!("source:local:{path}"), t), "the browsed folder is listed: {:?}", ids(&mut h));- assert!(!ids(&mut h).iter().any(|i| i == "source:local:restoreHidden"));+ // the "Show hidden locations" row appears only while something is hidden+ let hidden_before = !h.app.ui.hidden_locations.is_empty();+ assert_eq!(ids(&mut h).iter().any(|i| i == "source:local:restoreHidden"), hidden_before);+ // hide it while it is still being browsedlet r = h.request("engine.execute", json!({"command": "local.hide", "params": {"path": path}}), t);assert_eq!(r["ok"], true, "{r}");h.settle(SETTLE);diff --cc crates/ui-egui/src/tests_masking.rsindex bdf9a852c,ea6589cd2..8e2c81391--- a/crates/ui-egui/src/tests_masking.rs+++ b/crates/ui-egui/src/tests_masking.rs@@@ -366,7 -366,7 +366,8 @@@ fn local_folder_tree_expands_and_browsestd::fs::create_dir_all(base.join(".hidden")).unwrap();let mut h = detail("panel.edit");exec(&mut h, "view.leftPanel", json!({"show": true}));+ h.hide_home_above(&base);+ exec(&mut h, "local.addRoot", json!({"path": base.to_string_lossy()}));exec(&mut h, "library.browse", json!({"path": base.to_string_lossy()}));h.settle(SETTLE);let base_s = base.to_string_lossy().to_string();