LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge main into LRC-LIB-SMARTCOLL (keep both sides of catalog tests and What's new)
Brandon Thomas8fd5a6f42fc7
diff --cc crates/catalog/src/tests.rsindex 09cf98f4b,4c2bb33eb..d997ceb17--- a/crates/catalog/src/tests.rs+++ b/crates/catalog/src/tests.rs@@@ -457,155 -457,47 +457,200 @@@ fn random_sort_has_no_date_headers()assert!(c.date_runs(&ids, SortKey::Random, GroupBy::Day).is_empty());}+/// A saved smart album whose rules no longer check (the album a rule tests was deleted) is found,+/// with its problems; a good one has none; an old album operator is read as it was meant.+#[test]+fn smart_album_problems_flag_stale_rules() {+ let mut c = Catalog::new();+ c.apply(Op::AddAlbum { album: Album::new(AlbumId(1), "Trip") }).unwrap();+ let smart = |id: u64, rules: serde_json::Value| {+ let f: Filter = serde_json::from_value(serde_json::json!({"ruleSet": {"rules": rules}})).unwrap();+ Album { smart: Some(Box::new(f)), ..Album::new(AlbumId(id), "Smart") }+ };+ c.apply(Op::AddAlbum { album: smart(2, serde_json::json!([{"field": "album", "op": "is", "value": 1}])) }).unwrap();+ c.apply(Op::AddAlbum { album: smart(3, serde_json::json!([{"field": "album", "op": "gte", "value": 1}])) }).unwrap();+ assert!(c.smart_album_problems(AlbumId(2)).is_empty());+ assert!(c.smart_album_problems(AlbumId(3)).is_empty(), "an old operator is upgraded, not a problem");+ assert!(c.smart_album_problems(AlbumId(1)).is_empty(), "a plain album has no rules");+ c.apply(Op::RemoveAlbum { id: AlbumId(1) }).unwrap();+ let p = c.smart_album_problems(AlbumId(2));+ assert_eq!(p.iter().map(ToString::to_string).collect::<Vec<_>>(), vec!["rule 1: no album 1".to_string()]);+}++/// A smart album can test another smart album: "Keywords contain travel" and "Album isn't Excluded+/// Photos" (red or rejected) leaves out the excluded photos, and follows that album's rules as they+/// change.+#[test]+fn a_smart_album_can_exclude_another() {+ let mut c = Catalog::new();+ let smart = |id: u64, name: &str, rules: serde_json::Value| {+ let f: Filter = serde_json::from_value(serde_json::json!({"ruleSet": rules})).unwrap();+ Album { smart: Some(Box::new(f)), ..Album::new(AlbumId(id), name) }+ };+ c.apply(Op::AddAlbum {+ album: smart(+ 1,+ "Excluded Photos",+ serde_json::json!({"match": "any", "rules": [+ {"field": "label", "op": "is", "value": "red"}, {"field": "flag", "op": "is", "value": "reject"}]}),+ ),+ })+ .unwrap();+ let travel = |c: &mut Catalog, name: &str, label: Option<ColorLabel>, flag: Flag| {+ let id = c.alloc_photo_id();+ let mut p = Photo::new(id, Source::Demo { scene: 1 }, name, "JPEG", 6000, 4000, "2026-09-30T10:00:00");+ p.meta.keywords = vec!["travel".into()];+ p.label = label;+ p.flag = flag;+ c.apply(Op::AddPhoto { photo: Box::new(p) }).unwrap();+ id+ };+ let keep = travel(&mut c, "keep.jpg", None, Flag::Pick);+ let red = travel(&mut c, "red.jpg", Some(ColorLabel::Red), Flag::None);+ let rejected = travel(&mut c, "rejected.jpg", None, Flag::Reject);+ let rules: RuleSet = serde_json::from_value(serde_json::json!({"rules": [+ {"field": "keywords", "op": "contains", "value": "travel"}, {"field": "album", "op": "isNot", "value": 1}]}))+ .unwrap();+ assert!(rules.check(&c).is_empty(), "a smart album can be tested: {:?}", rules.check(&c));+ let matched = |c: &Catalog| c.photos().filter(|p| rules.matches(p, c)).map(|p| p.id).collect::<Vec<_>>();+ assert_eq!(matched(&c), vec![keep]);+ // "is" works the other way round+ let inside: RuleSet = serde_json::from_value(serde_json::json!({"rules": [{"field": "album", "op": "is", "value": 1}]})).unwrap();+ assert_eq!(c.photos().filter(|p| inside.matches(p, &c)).count(), 2);+ let _ = (red, rejected);+}++/// An album can't include itself, directly or through other smart albums: the check refuses the+/// loop for the album being edited, and a loop saved anyway (an older version, a hand-edited file)+/// neither recurses forever nor crashes: inside it, the album being evaluated counts as holding no+/// photos, and every album in it is reported.+#[test]+fn smart_album_loops_are_refused_and_survived() {+ let mut c = Catalog::new();+ let refers = |to: u64| -> Filter {+ serde_json::from_value(serde_json::json!({"ruleSet": {"rules": [{"field": "album", "op": "isNot", "value": to}]}})).unwrap()+ };+ let smart = |id: u64, f: Filter| Album { smart: Some(Box::new(f)), ..Album::new(AlbumId(id), "S") };+ // A → B → C+ c.apply(Op::AddAlbum { album: smart(3, Filter::default()) }).unwrap();+ c.apply(Op::AddAlbum { album: smart(2, refers(3)) }).unwrap();+ c.apply(Op::AddAlbum { album: smart(1, refers(2)) }).unwrap();+ let rules = |to: u64| refers(to).rule_set.unwrap();+ assert!(rules(1).check_for(&c, Some(AlbumId(3))).iter().any(|p| p.issue == crate::rules::Issue::AlbumLoop), "C → A closes A → B → C → A");+ assert!(rules(3).check_for(&c, Some(AlbumId(3))).iter().any(|p| p.issue == crate::rules::Issue::AlbumLoop), "an album testing itself");+ assert!(rules(1).check_for(&c, None).is_empty(), "a new album can't be in a loop yet");+ assert!(rules(3).check_for(&c, Some(AlbumId(1))).is_empty(), "A testing C again is no loop");+ assert!(!c.album_reaches(AlbumId(3), AlbumId(1)) && c.album_reaches(AlbumId(1), AlbumId(3)));+ // a loop saved anyway: C → A+ c.apply(Op::SetAlbumRules { id: AlbumId(3), rules: Box::new(refers(1)) }).unwrap();+ let id = photo(&mut c, "a.jpg", "2026-09-01T10:00:00");+ let p = c.photo(id).unwrap().clone();+ for a in [1, 2, 3] {+ let _ = c.album_contains(AlbumId(a), &p); // returns, no stack overflow+ assert!(c.smart_album_problems(AlbumId(a)).iter().any(|p| p.issue == crate::rules::Issue::AlbumLoop), "album {a} is reported");+ }+}++/// Summaries name the albums Album rules test ("album isn't “Excluded Photos”"), not their ids;+/// one that is gone shows as its number.+#[test]+fn summaries_name_albums() {+ let mut c = Catalog::new();+ c.apply(Op::AddAlbum { album: Album::new(AlbumId(4), "Excluded Photos") }).unwrap();+ let rules: RuleSet = serde_json::from_value(serde_json::json!({"rules": [+ {"field": "keywords", "op": "contains", "value": "travel"},+ {"group": {"match": "any", "rules": [{"field": "album", "op": "isNot", "value": 4}, {"field": "album", "op": "is", "value": 9}]}}]}))+ .unwrap();+ assert_eq!(rules.describe_with(&c), "keywords contains travel and (album isn't “Excluded Photos” or album is #9)");+ let f = Filter { rule_set: Some(rules), ..Default::default() };+ assert!(f.describe_with(&c).contains("album isn't “Excluded Photos”"));+}++/// A chain of smart albums each testing the one before twice ("all of: album is X(k-1), album is+/// X(k-1)") costs a pass per album, not 2^depth: each album's answer for a photo is worked out once+/// per question. 25 albums deep stays instant.+#[test]+fn chains_of_smart_albums_stay_linear() {+ let mut c = Catalog::new();+ let smart = |id: u64, f: Filter| Album { smart: Some(Box::new(f)), ..Album::new(AlbumId(id), "X") };+ c.apply(Op::AddAlbum { album: smart(1, Filter::default()) }).unwrap();+ for k in 2..=26u64 {+ let f: Filter = serde_json::from_value(serde_json::json!({"ruleSet": {"rules": [+ {"field": "album", "op": "is", "value": k - 1}, {"field": "album", "op": "is", "value": k - 1}]}}))+ .unwrap();+ c.apply(Op::AddAlbum { album: smart(k, f) }).unwrap();+ }+ for i in 0..20 {+ photo(&mut c, &format!("p{i}.jpg"), "2026-09-01T10:00:00");+ }+ let start = std::time::Instant::now();+ assert_eq!(c.album_count(AlbumId(26)), 20);+ assert!(start.elapsed() < std::time::Duration::from_secs(2), "took {:?}", start.elapsed());+}++/// A smart album's own album filter (not only its rules) counts in loops: A filtered to "in A" is+/// reported, and so is A filtered to B while B's rules test A.+#[test]+fn an_album_filter_counts_in_loops() {+ let mut c = Catalog::new();+ let smart = |id: u64, f: Filter| Album { smart: Some(Box::new(f)), ..Album::new(AlbumId(id), "S") };+ c.apply(Op::AddAlbum { album: smart(1, Filter { album: Some(AlbumId(1)), ..Default::default() }) }).unwrap();+ let loops = |c: &Catalog, id: u64| c.smart_album_problems(AlbumId(id)).iter().any(|p| p.issue == crate::rules::Issue::AlbumLoop);+ assert!(loops(&c, 1), "filtered to itself");+ let tests_3: Filter = serde_json::from_value(serde_json::json!({"ruleSet": {"rules": [{"field": "album", "op": "is", "value": 3}]}})).unwrap();+ c.apply(Op::AddAlbum { album: smart(2, Filter { album: Some(AlbumId(3)), ..Default::default() }) }).unwrap();+ c.apply(Op::AddAlbum {+ album: smart(3, serde_json::from_value(serde_json::json!({"ruleSet": {"rules": [{"field": "album", "op": "is", "value": 2}]}})).unwrap()),+ })+ .unwrap();+ assert!(c.album_reaches(AlbumId(3), AlbumId(2)) && c.album_reaches(AlbumId(2), AlbumId(3)));+ assert!(loops(&c, 2) && loops(&c, 3));+ let _ = tests_3;+ let shown: Vec<String> = c.smart_album_problems(AlbumId(1)).iter().map(ToString::to_string).collect();+ assert!(shown.iter().all(|s| !s.starts_with("rule :")), "{shown:?}");+}+++ #[test]+ fn undated_photos_group_under_unknown_date_and_sort_together() {+ let mut c = Catalog::new();+ let add_photo = |c: &mut Catalog, name: &str, captured: Option<&str>, imported: &str| {+ let id = c.alloc_photo_id();+ let mut p = Photo::new(id, Source::Demo { scene: 0 }, name, "JPEG", 100, 100, imported);+ p.captured = captured.map(str::to_string);+ c.apply(Op::AddPhoto { photo: Box::new(p) }).unwrap();+ id+ };+ let p_dated1 = add_photo(&mut c, "dated1.jpg", Some("2026-05-10T12:00:00"), "2026-10-01T00:00:00");+ let p_dated2 = add_photo(&mut c, "dated2.jpg", Some("2026-05-20T12:00:00"), "2026-10-01T00:00:00");+ let p_undated1 = add_photo(&mut c, "undated1.jpg", None, "2026-10-05T00:00:00");+ let p_undated2 = add_photo(&mut c, "undated2.jpg", None, "2026-10-02T00:00:00");++ // Descending sort (default, newest first): dated photos first (newest to oldest), undated photos at the end+ let desc = c.query(&Filter::default(), &Sort { key: SortKey::CaptureDate, ascending: false, ..Default::default() });+ assert_eq!(desc, vec![p_dated2, p_dated1, p_undated1, p_undated2]);++ // Ascending sort (oldest first): undated photos at the beginning, dated photos from oldest to newest+ let asc = c.query(&Filter::default(), &Sort { key: SortKey::CaptureDate, ascending: true, ..Default::default() });+ assert_eq!(asc, vec![p_undated2, p_undated1, p_dated1, p_dated2]);++ // date_runs groups undated photos under Unknown Date+ let runs = c.date_runs(&desc, SortKey::CaptureDate, GroupBy::Day);+ assert_eq!(runs.len(), 3);+ assert_eq!(runs[0].key, "2026-05-20");+ assert_eq!(runs[1].key, "2026-05-10");+ assert_eq!(runs[2].key, "");+ assert_eq!(runs[2].label, "Unknown Date");+ assert_eq!(runs[2].count, 2);++ // date_groups sidebar tree only counts photos with capture dates+ let groups = c.date_groups();+ assert_eq!(groups.len(), 1);+ assert_eq!(groups[0].year, "2026");+ assert_eq!(groups[0].count, 2);++ // Filter by capture date prefix does not match undated photos+ let filter_day = Filter { date: Some("2026-10-05".into()), ..Default::default() };+ assert_eq!(c.query(&filter_day, &Sort::default()), vec![]);+ let filter_year = Filter { date: Some("2026".into()), ..Default::default() };+ assert_eq!(c.query(&filter_year, &Sort { key: SortKey::CaptureDate, ascending: false, ..Default::default() }), vec![p_dated2, p_dated1]);+ }diff --cc docs/whats-new.mdindex faadc0de6,33557867d..1eca91b4e--- a/docs/whats-new.md+++ b/docs/whats-new.md@@@ -2,42 -2,11 +2,47 @@@## October 2026+### Smart album rules+- The rule editor's field menu is grouped: Rating, Pick Flag, Color Label and Any Searchable Text at the top, then+ submenus for Source, File, Date, Keywords & People, Description, Camera Info, Location, Size, Develop and Assisted+ Culling.+- New fields: Keyword Count ("2 or more", "exactly 2"…), People and People Count (named faces), Shutter Speed (written+ as 1/250), File Extension, Video Duration, Copy Name, In a Stack, Alt Text, City, State / Province, Country, Long+ Edge, Short Edge, Aspect Ratio (landscape / portrait / square), Cropped and Treatment (in color / black & white).+ Size rules measure the photo as shown: Megapixels now counts the cropped photo, like Long Edge, Short Edge and+ Aspect Ratio (a 24 MP photo cropped to a square is 16 MP).+- Choice values read as words in every language: "Public Domain", "Picked", "Black & White" rather than ids like+ `publicDomain` (rules and agents keep using the ids; `album.ruleFields` adds `choiceLabels`).+- Rule values are checked: a rating of 9, a date like 2026-13 or "banana", a "between" whose dates are the wrong+ way round, "in the last 0 days", a colour label that doesn't exist, "contains" with nothing to look for, an+ album that is gone, or an empty group is reported with its rule ("rule 2.1: no rating 0–5 is 9")+ instead of quietly matching nothing or everything. New date rules start at the current year.+- A smart album can include or exclude another smart album: "Keywords contain travel" and "Album isn't Excluded Photos"+ leaves out whatever Excluded Photos matches, as its rules change. The album picker shows your albums as in the sidebar+ (folders open on click) or finds them as you type part of a name or folder (↑ / ↓ and Enter to pick); albums that+ can't be picked, such as one that would make an album include itself, are greyed with the reason. Esc with a dropdown or calendar open in a dialog+ closes just that.+- Date rules have a calendar button: pick a day, a month or a whole year (Year / Month / Day), in your language; the+ two dates of a "between" can't be picked out of order; Esc closes just the calendar. It picks dates, not times (a+ time is typed, and picking a day replaces one). Typing still works, and "2026-10-01 10:00" (a space for the+ T) now matches.+- Rule problems are shown in your language and name the field the way the menu does ("Title: needs something to look+ for").+- A smart album whose rules no longer check (an album they test was deleted) is marked ⚠ in the sidebar; its tooltip+ says what to fix, and `albums.list` reports `problems`.+- Editing a smart album's name and rules is one step: both or neither, and one undo takes both back+ (`album.setRules` takes `name`).+- The rule editor marks each rule that needs fixing right under it and keeps OK disabled until they are fixed. An+ Album rule is "is" or "isn't" an album, picked with the album picker.+- Yes/no fields (Has Edits, Cropped, Has GPS…) read Yes / No instead of true / false. A rule sent as `"false"` now+ means no (it used to count as yes), and a value that is neither yes nor no is refused.+- Any Searchable Text also finds the state / province, alt text, people and a virtual copy's name.++ ### Masking+ - Drag anywhere inside the selected radial gradient's ellipse to move it, including rotated+ ellipses and radial components in compound masks. Edge and rotation handles keep their existing+ functions, and one Undo restores the entire drag.+### Albums tree- Album folders fold with the same disclosure triangle as Local, By Date, Folders and Keywords.- Right-click a folder ▸ New ▸ Create Album… / Create Smart Album… / Create Smart Album from Filter… / Create Folder…