Cotton code
83 lines · 5.8 KB · RustRaw
use super::*;/// RULE: Catalogue rows retain board order and identity; the engine must refuse malformed routes instead of manufacturing a working-looking slip.#[test]fn catalogue_projects_declared_rows_and_refuses_broken_routes() {    let board = serde_json::json!({"parts":[{"kind":"list","table":"settings","rows":[        {"id":"one","data":{"name":"One","route":"/devices"}},        {"id":"two","data":{"name":"Two","route":"/storage"}}    ]}]});    let rows = project(&board, Some("two"), crate::presentation::SettingsReach::EVERY).unwrap();    assert_eq!(rows[0].id, "two");    assert_eq!(rows[0].data["position"], 1);    assert_eq!(raised_on_me(&rows[0].data), None);    let mut raised = Data::new();    raised.insert("route".into(), Value::from("/me?raise=city"));    assert_eq!(raised_on_me(&raised), Some("city"));    raised.insert("route".into(), Value::from("/device?raise=city"));    assert_eq!(raised_on_me(&raised), None);    let mut broken = board;    broken["parts"][0]["rows"][0]["data"]["route"] = Value::from("//external.test");    assert!(project(&broken, None, crate::presentation::SettingsReach::EVERY).is_err());}/// RULE: a Settings row may say what it needs (`needs`); the list hides a row whose need the app's manifest does not meet, so a manifest saying `"databases": "only"` (one database ever: Rigby) lists no Databases row while one saying `single` (one shown at a time: Cotton) keeps it, and a row with no `needs` always shows (architect, 22 Oct 2026). Positions count the rows listed.#[test]fn a_row_whose_need_the_manifest_does_not_meet_is_not_listed() {    use crate::presentation::SettingsReach;    let board = serde_json::json!({"parts":[{"kind":"list","table":"settings","rows":[        {"id":"device","data":{"name":"This device","route":"/device"}},        {"id":"databases","needs":"several_databases","data":{"name":"Databases","route":"/database"}},        {"id":"runners","needs":"serving","data":{"name":"Runners","route":"/code/runners"}},        {"id":"about","data":{"name":"About","route":"/about"}}    ]}]});    let ids = |reach| project(&board, None, reach).unwrap().into_iter().map(|row| row.id).collect::<Vec<_>>();    // Cotton's manifest says `single` (one shown at a time); Rigby's says `only`    // (GenesisTests pins which shipped manifest says which).    let cotton = SettingsReach::of(&serde_json::json!({"flavour": "cotton", "databases": "single", "business": {"server": {"real": "https://cotton.example.com"}}}));    assert_eq!(cotton, SettingsReach::EVERY);    assert_eq!(ids(cotton), ["device", "databases", "runners", "about"]);    let rigby = SettingsReach::of(&serde_json::json!({"flavour": "rigby", "databases": "only"}));    assert_eq!(ids(rigby), ["device", "runners", "about"]);    let about = project(&board, Some("about"), rigby).unwrap();    assert_eq!(about[0].data["position"], 2, "positions count the rows listed");    assert!(project(&board, Some("databases"), rigby).unwrap().is_empty());    let unserved = SettingsReach { serving: false, ..rigby };    assert_eq!(ids(unserved), ["device", "about"]);    assert!(SettingsReach::EVERY.meets("a_newer_builds_need"));}/// RULE: Backup and Cotton server are Settings' first two cards in an app whose manifest names a personal object (Cotton: genesis personal and a server), and are not listed where it names none — Rigby's manifest names no server, a business app's genesis is none — so nothing in the shell branches on the flavour (owner, 1 Nov 2026).#[test]fn backup_and_server_lead_only_where_the_manifest_names_a_personal_object() {    use crate::presentation::SettingsReach;    let shipped: Value = serde_json::from_str(include_str!("../../../../../cotton-core/kits/shell/boards/settings.json")).unwrap();    let ids = |manifest: Value| project(&shipped, None, SettingsReach::of(&manifest)).unwrap().into_iter().map(|row| row.id).collect::<Vec<_>>();    let cotton = ids(serde_json::from_str(include_str!("../../../../../../apps/cotton/App/CottonManifest/flavour.json")).unwrap());    assert_eq!(cotton[..2], ["backup", "server"], "Backup, then Cotton server, first: {cotton:?}");    let rigby = ids(serde_json::from_str(include_str!("../../../../../../apps/cotton/Tests/Fixtures/Flavours/rigby.json")).unwrap());    assert!(!rigby.iter().any(|id| id == "backup" || id == "server"), "{rigby:?}");    let business = ids(serde_json::json!({"genesis": "none", "databases": "single", "business": {"server": "https://cotton.example.com", "slug": "studio"}}));    assert!(!business.iter().any(|id| id == "backup" || id == "server"), "{business:?}");}/// RULE: every Settings row Rigby lists opens a page Rigby can draw: no Your/// city (Me is the person an object names, and Rigby has no object) and no/// Voice words (its table left every kit on 21 Oct 2026), walked whole for/// Rigby 11 (8 Nov 2026).#[test]fn rigby_lists_only_settings_it_can_open() {    use crate::presentation::SettingsReach;    let shipped: Value = serde_json::from_str(include_str!("../../../../../cotton-core/kits/shell/boards/settings.json")).unwrap();    let rigby: Value = serde_json::from_str(include_str!("../../../../../../apps/cotton/Tests/Fixtures/Flavours/rigby.json")).unwrap();    let ids = project(&shipped, None, SettingsReach { serving: false, ..SettingsReach::of(&rigby) })        .unwrap()        .into_iter()        .map(|row| row.id)        .collect::<Vec<_>>();    assert_eq!(ids, ["this-device", "bring-in", "export", "about"]);    let cotton: Value = serde_json::from_str(include_str!("../../../../../../apps/cotton/App/CottonManifest/flavour.json")).unwrap();    let cotton = project(&shipped, None, SettingsReach::of(&cotton)).unwrap().into_iter().map(|row| row.id).collect::<Vec<_>>();    assert!(cotton.iter().any(|id| id == "city"), "{cotton:?}");    assert!(!cotton.iter().any(|id| id == "voice-words"), "{cotton:?}");}