mirror of
https://github.com/storytold/lightcraft.git
synced 2026-10-27 11:37:13 -06:00
LRC-LIB-SMARTCOLL: report saved smart albums whose rules no longer check
Rules are checked when they are made, but a saved smart album can go bad later. The usual case is a rule testing an album that is then deleted; it silently matches nothing. Catalog::smart_album_problems(id) checks a saved album's rules as they are now (RuleSet::upgrade, then RuleSet::check). It is empty for a sound smart album, a plain album or no album. albums.list reports `problems` for every smart album, e.g. ["rule 1: no album 8"]. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
31abbcee4f
commit
bb50127de4
@@ -44,6 +44,8 @@ fn album_json(a: &Album, all: &[Album], cat: &lightcraft_catalog::Catalog) -> Va
|
||||
v["smart"] = json!(true);
|
||||
v["rules"] = serde_json::to_value(rules).unwrap_or_default();
|
||||
v["rulesText"] = json!(rules.describe());
|
||||
// rules that no longer check (an album they test was deleted…), as `rule 1: …`
|
||||
v["problems"] = json!(cat.smart_album_problems(a.id).iter().map(ToString::to_string).collect::<Vec<_>>());
|
||||
}
|
||||
v
|
||||
}
|
||||
|
||||
@@ -555,3 +555,19 @@ fn set_rules_with_a_name_is_one_step() {
|
||||
s.execute("album.setRules", &serde_json::json!({"id": id, "name": " ", "rules": {"rating": 5}})).unwrap();
|
||||
assert_eq!(album(&s).name, "Old");
|
||||
}
|
||||
|
||||
/// albums.list says which smart albums have rules that no longer check, and why.
|
||||
#[test]
|
||||
fn album_list_reports_problems() {
|
||||
let mut s = crate::Session::with_demo();
|
||||
let trip = s.execute("album.create", &serde_json::json!({"name": "Trip", "addSelected": false})).unwrap()["id"].as_u64().unwrap();
|
||||
let rules = serde_json::json!({"ruleSet": {"rules": [{"field": "album", "op": "is", "value": trip}]}});
|
||||
let id = s.execute("album.createSmart", &serde_json::json!({"name": "In Trip", "rules": rules})).unwrap()["id"].as_u64().unwrap();
|
||||
let find = |s: &mut crate::Session| {
|
||||
let list = s.execute("albums.list", &serde_json::json!({})).unwrap();
|
||||
list.as_array().unwrap().iter().find(|a| a["id"] == id).cloned().unwrap()
|
||||
};
|
||||
assert_eq!(find(&mut s)["problems"], serde_json::json!([]));
|
||||
s.execute("album.delete", &serde_json::json!({"id": trip})).unwrap();
|
||||
assert_eq!(find(&mut s)["problems"], serde_json::json!([format!("rule 1: no album {trip}")]));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user