Cotton code
387 lines · 25.8 KB · RustRaw
use super::*;use crate::shell::client::phone_tests::attached;use rusqlite::types::Value as SqlValue;const DAY: &str = "2026-11-05";/// Cotton's dial: Home and Tools, ending in the Settings card (`CottonManifest/flavour.json`).fn cotton() -> FanCards { FanCards { home: true, tools: true, settings: true, opens: None, stream: false } }/// Cotton Books': no Home, no Tools, opening on Books.fn books() -> FanCards { FanCards { home: false, tools: false, settings: false, opens: Some("books".into()), stream: false } }/// Rigby's: no Home, no Tools, a Settings card, opening on Todos.fn rigby() -> FanCards { FanCards { home: false, tools: false, settings: true, opens: Some("todos".into()), stream: false } }/// A business kit's (Nancy's Naga Kitchen): Home, no Tools.fn business() -> FanCards { FanCards { home: true, tools: false, settings: false, opens: None, stream: false } }fn fan(client: &ClientController, cards: &FanCards, request: Value) -> Value {    let mut request = request;    request["today"] = json!(DAY);    request["timezone"] = json!("UTC");    read(client, cards, &request).expect("the fan reads")}fn keys(answer: &Value) -> Vec<String> {    answer["tiles"].as_array().unwrap().iter().map(|tile| tile["key"].as_str().unwrap().to_string()).collect()}fn tile<'a>(answer: &'a Value, key: &str) -> &'a Value {    answer["tiles"].as_array().unwrap().iter().find(|tile| tile["key"] == key).unwrap_or_else(|| panic!("no tile {key}: {answer}"))}fn seed(client: &ClientController, sql: &str, params: &[SqlValue]) {    client.with_writer(|file| {        file.driver.run(sql, params).map_err(|error| error.to_string())?;        crate::fixture::receipted(file.driver, sql);        Ok(())    }).unwrap();}fn workspace(client: &ClientController) -> String {    client.with_writer(|file| Ok(file.workspace_id.to_string())).unwrap()}/// The database holds these tools alone, as a kit's app pulls its own.fn keeps_only(client: &ClientController, tools: &[&str]) {    let held = tools.iter().map(|tool| format!("'{tool}'")).collect::<Vec<_>>().join(",");    seed(client, &format!("DELETE FROM cotton_tool_definitions WHERE id NOT IN ({held})"), &[]);}/// The home board as the object keeps it: its fan part naming the tools whose tables hold no rows.fn empty_tools(client: &ClientController, empty: &[&str]) {    let board = json!({"format_version": 1, "id": "home", "parts": [{"kind": "tools", "face": "fan", "empty": empty}]});    seed(client, "INSERT OR REPLACE INTO cotton_board_definitions (id, workspace_id, definition, builtin, created_at, updated_at) \                  VALUES ('home', ?, ?, 0, '2026-11-05T09:00:00.000Z', '2026-11-05T09:00:00.000Z')",        &[SqlValue::Text(workspace(client)), SqlValue::Text(board.to_string())]);}/// The names the fan says, in the order the ICU root collation sorts them.fn by_name(answer: &Value, keys: &[String]) -> Vec<String> {    let mut named: Vec<(String, String)> = keys.iter().map(|key| (tile(answer, key)["name"].as_str().unwrap().to_string(), key.clone())).collect();    cotton_core::js_text::sort_by_name(&mut named, |(name, _)| name.clone(), |_| String::new());    named.into_iter().map(|(_, key)| key).collect()}// RULE (owner, 17 Oct 2026; owner 23 Oct 2026): Cotton's fan is every tool by name, Home and Tools among them, the Settings card last; it opens on its tools at Home.#[test]fn cotton_opens_on_its_tools_every_kit_tool_by_name() {    assert!(crate::methods::read_only("shell.fan"));    let (_dir, client) = attached();    let answer = fan(&client, &cotton(), json!({}));    let dealt = keys(&answer);    let held: Vec<String> = client.with_file(|file| Ok(file.driver.all("SELECT id FROM cotton_tool_definitions", &[]).unwrap()        .iter().map(|row| row.text("id").unwrap().to_string()).collect())).unwrap();    for tool in &held { assert!(dealt.contains(tool), "every kit tool is a tile: {tool} in {dealt:?}"); }    assert_eq!(dealt.last().map(String::as_str), Some(SETTINGS), "Settings last");    let before: Vec<String> = dealt[..dealt.len() - 1].to_vec();    assert_eq!(before, by_name(&answer, &before), "by name, Home and Tools among them");    assert!(before.contains(&HOME.to_string()) && before.contains(&TOOLS.to_string()));    assert_eq!(answer["opens"], json!({"tier": "tools", "tool": HOME}));    assert_eq!(answer["root"]["id"], TOOLS_TIER);    assert_eq!(answer["root"]["cards"], json!(dealt));    assert_eq!(answer["root"]["raised"], HOME);    // The words are the kit's.    assert_eq!((tile(&answer, HOME)["name"].as_str(), tile(&answer, TOOLS)["name"].as_str(), tile(&answer, SETTINGS)["name"].as_str()),        (Some("Home"), Some("Tools"), Some("Settings")));    // Home is the person's page, rung by no views; Tools rings Shown and Hidden.    assert_eq!(tile(&answer, HOME)["ringed"], false);    let tools: Vec<&Value> = tile(&answer, TOOLS)["views"].as_array().unwrap().iter().map(|view| &view["id"]).collect();    assert_eq!(tools, [&json!("shown"), &json!("hidden")]);    // A tool's tile names its picture and page: Todos' own screen, Books' views over its table.    assert_eq!(tile(&answer, "todos")["picture"]["object"], "tool-todos");    assert_eq!((tile(&answer, "todos")["ringed"].as_bool(), tile(&answer, "todos")["views_table"].as_str()), (Some(true), None));    assert_eq!(tile(&answer, "books")["views_table"], "book");    assert_eq!(tile(&answer, "books")["whole"], "all", "the view holding every book");    assert!(answer["tiles"].as_array().unwrap().iter().all(|tile| tile["poster"] == false), "every page here is a list or a page");}// RULE (owner on Cotton Books 1.0.0 (1), 5 Nov 2026): a fan of one tool whose page its views ring opens on that tool's views — the seven painted tiles, then the lists, counted.#[test]fn books_opens_on_the_views_of_books_with_its_painted_and_list_tiles() {    let (_dir, client) = attached();    keeps_only(&client, &["books"]);    let book = crate::phone::records::call(&client, "records.create", &json!({"table": "book", "data": {"title": "Synthetic book", "status": "reading"}})).unwrap();    let id = book["record"]["id"].as_str().unwrap();    crate::phone::records::call(&client, "groups.create", &json!({"table": "book", "name": "Synthetic shelf", "records": [id]})).unwrap();    client.bring_moves_done_for_tests().unwrap();    let answer = fan(&client, &books(), json!({}));    assert_eq!(keys(&answer), ["books"], "the one tool");    let books = tile(&answer, "books");    assert_eq!(books["counted"], true, "the tile it opens on is counted");    let views = books["views"].as_array().unwrap();    let painted: Vec<&str> = views.iter().filter(|view| view["picture"].is_string()).map(|view| view["id"].as_str().unwrap()).collect();    assert_eq!(painted.len(), 7, "seven painted tiles: {painted:?}");    let lists: Vec<&Value> = views.iter().filter(|view| view["id"].as_str().unwrap().starts_with("group:")).collect();    assert_eq!(lists.len(), 1, "the list's tile");    assert_eq!((lists[0]["label"].as_str(), lists[0]["count"].as_u64()), (Some("Synthetic shelf"), Some(1)));    assert!(views.iter().all(|view| view["count"].is_u64()), "every view counted");    assert_eq!(views[0]["default"], true, "the default first");    assert_eq!(answer["opens"]["tier"], "views");    assert_eq!(answer["opens"]["tool"], "books");    assert_eq!(answer["opens"]["view"], views[0]["id"]);    assert_eq!(answer["root"]["id"], "views-books");    assert_eq!(answer["root"]["cards"], json!(views.iter().map(|view| view["id"].clone()).collect::<Vec<_>>()));}// RULE (owner and architect, 22 Oct 2026): Rigby's fan is its tools by name, no Home and no Tools, a Settings card last; it opens on Todos.#[test]fn rigby_holds_its_tools_and_opens_on_todos() {    let (_dir, client) = attached();    // Rigby's tools are its manifest's, never listed here.    let manifest: Value = serde_json::from_slice(&std::fs::read(cotton_store::manifest_dir().join("../../apps/cotton/Tests/Fixtures/Flavours/rigby.json")).expect("Rigby's manifest")).expect("JSON");    let own: Vec<&str> = manifest["tools"].as_array().expect("Rigby names its tools").iter().map(|tool| tool.as_str().unwrap()).collect();    assert!(own.contains(&"todos"), "Rigby opens on Todos, so it carries it");    keeps_only(&client, &own);    let answer = fan(&client, &rigby(), json!({}));    let dealt = keys(&answer);    let tools: Vec<String> = dealt[..dealt.len() - 1].to_vec();    let mut expected: Vec<String> = own.iter().map(|tool| tool.to_string()).collect();    expected.sort();    let mut sorted = tools.clone();    sorted.sort();    assert_eq!(sorted, expected, "its own tools and nothing of Cotton's");    assert_eq!(tools, by_name(&answer, &tools));    assert_eq!(dealt.last().map(String::as_str), Some(SETTINGS));    assert_eq!(answer["opens"], json!({"tier": "tools", "tool": "todos"}));    assert_eq!(tile(&answer, "todos")["counted"], true, "the tile it opens on is the one counted");    assert_eq!(tile(&answer, "people")["counted"], false);    assert!(tile(&answer, "people")["views"].as_array().unwrap().iter().all(|view| view["count"].is_null()), "declared, uncounted");}// RULE (owner, 26 Oct 2026): a business kit's fan holds Home and its tools by name; a tool the object says holds no rows sits after them, in the object's order.#[test]fn a_business_kits_fan_rests_its_empty_tools_last() {    let (_dir, client) = attached();    keeps_only(&client, &["people", "messages", "todos", "calendar"]);    empty_tools(&client, &["todos", "calendar"]);    let answer = fan(&client, &business(), json!({}));    assert_eq!(keys(&answer), ["home", "messages", "people", "todos", "calendar"]);    assert_eq!(answer["opens"], json!({"tier": "tools", "tool": HOME}));    // An app that opens on a tool and keeps Home deals Home last (Cotton Music, 4 Nov 2026).    let music = FanCards { home: true, tools: false, settings: false, opens: Some("people".into()), stream: false };    let answer = fan(&client, &music, json!({}));    assert_eq!(keys(&answer), ["messages", "people", "todos", "calendar", "home"]);    assert_eq!(answer["opens"], json!({"tier": "tools", "tool": "people"}));}// RULE (the owner, 23 Oct 2026): the Settings card's views are the settings rows in the engine's order, each said by its name and opening its route, the first its default; read when the fan stands on it.#[test]fn the_settings_ring_is_its_rows() {    let (_dir, client) = attached();    let unasked = fan(&client, &cotton(), json!({}));    assert_eq!(tile(&unasked, SETTINGS)["views"], json!([]), "not read until the fan stands on it");    let answer = fan(&client, &cotton(), json!({"tool": SETTINGS}));    let settings = tile(&answer, SETTINGS);    assert_eq!(settings["counted"], true);    let views = settings["views"].as_array().unwrap();    let rows = crate::phone::records::call(&client, "records.list", &json!({"table": "settings", "limit": 200})).unwrap();    let rows = rows["records"].as_array().unwrap();    assert!(!rows.is_empty());    assert_eq!(views.len(), rows.len());    for (view, row) in views.iter().zip(rows) {        assert_eq!((&view["id"], &view["label"]), (&row["id"], &row["data"]["name"]));    }    assert_eq!(views[0]["default"], true);    assert_eq!(settings["current"], views[0]["id"]);    assert!(views.iter().any(|view| view["address"].is_string()), "a view opens its row's route");}// RULE: a tool shows exactly one of its views: the one chosen while it is still the tool's, else its default; only the tile the fan stands on is counted.#[test]fn the_chosen_view_stands_while_it_is_the_tools() {    let (_dir, client) = attached();    let answer = fan(&client, &cotton(), json!({"tool": "todos", "chosen": {"todos": "all", "people": "group:gone"}}));    let todos = tile(&answer, "todos");    assert_eq!(todos["counted"], true);    assert_eq!(todos["current"], "all");    assert!(todos["views"].as_array().unwrap().iter().all(|view| view["count"].is_u64()));    let people = tile(&answer, "people");    assert_eq!(people["counted"], false);    let default = people["views"].as_array().unwrap().iter().find(|view| view["default"] == true).unwrap();    assert_eq!(people["current"], default["id"], "a chosen list since deleted falls to the default");    assert_eq!(answer["root"]["raised"], HOME, "the tools tier raises where it opens");    assert!(read(&client, &cotton(), &json!({"chosen": ["all"]})).is_err(), "chosen is {{tool: view}}");}// RULE (event-create walk, 6 Nov 2026 01:22 IST): Calendar's Today and Upcoming split on the phone's own day in its own zone, never UTC's — between midnight and 05:30 in Kolkata, UTC still says yesterday.#[test]fn calendar_sections_split_on_the_phones_day_not_utcs() {    let (_dir, client, clock) = crate::shell::client::phone_tests::attached_on_a_clock();    let ws = SqlValue::Text(workspace(&client));    seed(&client, "INSERT OR REPLACE INTO cotton_news_settings (workspace_id, timezone, created_at, updated_at) \                   VALUES (?, 'Asia/Kolkata', '2026-11-01T00:00:00.000Z', '2026-11-01T00:00:00.000Z')", std::slice::from_ref(&ws));    seed(&client, "INSERT OR IGNORE INTO cotton_collections (id, workspace_id, kind, name, is_default, created_at) \                   VALUES ('cal-1', ?, 'calendar', 'Personal', 1, '2026-11-01T00:00:00.000Z')", &[ws]);    // Each as it is stored: a whole day is its first midnight and last millisecond in Kolkata.    for (id, title, starts, ends, all_day) in [        ("ev-fri", "Invented dentist", "2026-11-05T18:30:00.000Z", "2026-11-06T18:29:59.999Z", 1),        ("ev-fri-ten", "Invented call", "2026-11-06T04:30:00.000Z", "2026-11-06T05:30:00.000Z", 0),        ("ev-sat", "Invented picnic", "2026-11-06T18:30:00.000Z", "2026-11-07T18:29:59.999Z", 1),    ] {        seed(&client, "INSERT INTO cotton_events (id, collection_id, title, starts_at, ends_at, all_day, my_response, created_at, updated_at) \                       VALUES (?, 'cal-1', ?, ?, ?, ?, 'accepted', '2026-11-01T00:00:00.000Z', '2026-11-01T00:00:00.000Z')",            &[SqlValue::Text(id.into()), SqlValue::Text(title.into()), SqlValue::Text(starts.into()), SqlValue::Text(ends.into()), SqlValue::Integer(all_day)]);    }    // 01:00 in Kolkata (UTC's 5 Nov) and 06:00 (UTC's 6 Nov): Friday both times.    for at in ["2026-11-05T19:30:00Z", "2026-11-06T00:30:00Z"] {        clock.set(chrono::DateTime::parse_from_rfc3339(at).unwrap().with_timezone(&chrono::Utc));        let answer = read(&client, &cotton(), &json!({"tool": "calendar", "timezone": "Asia/Kolkata"})).expect("the fan reads");        let views = tile(&answer, "calendar")["views"].as_array().unwrap().clone();        let count = |id: &str| views.iter().find(|view| view["id"] == id).unwrap_or_else(|| panic!("no view {id}: {views:?}"))["count"].clone();        assert_eq!((count("today"), count("upcoming")), (json!(2), json!(1)), "at {at}: Friday's two today, Saturday's ahead");    }}// RULE (owner, 6 Nov 2026): a tool naming a fan tile is answered with it — its stock, type and role pictures — and each of its views with its pictogram, a list with the tile's `list` role; every other tool's tile is answered as it was, with no tile and no pictogram.#[test]fn cinemas_answers_its_letterboard_and_every_view_its_pictogram() {    let (_dir, client) = attached();    keeps_only(&client, &["cinemas", "books"]);    let film = crate::phone::records::call(&client, "records.create", &json!({"table": "film", "data": {"title": "Synthetic film", "kind": "film"}})).unwrap();    let id = film["record"]["id"].as_str().unwrap();    crate::phone::records::call(&client, "groups.create", &json!({"table": "film", "name": "Synthetic nights", "records": [id]})).unwrap();    client.bring_moves_done_for_tests().unwrap();    // Cotton Cinemas' own fan, opening on Cinemas: its views counted, its lists among them.    let opens = FanCards { home: false, tools: false, settings: false, opens: Some("cinemas".into()), stream: false };    let answer = fan(&client, &opens, json!({}));    let cinemas = tile(&answer, "cinemas");    assert_eq!(cinemas["tile"]["type"], "letterboard");    // RULE (owner on Cotton Cinemas 1.0 (4), 7 Nov 2026): a series' seasons and a season's episodes are drawn on the tool's letterboard too: the tile names every table the tool owns.    assert_eq!(cinemas["tile"]["tables"], json!(["film", "film_episode", "film_season", "watch"]), "{}", cinemas["tile"]);    assert!(cinemas["tile"]["stock"].as_str().is_some_and(|stock| stock.starts_with("photo:")));    let views = cinemas["views"].as_array().unwrap();    let list = views.iter().find(|view| view["id"].as_str().unwrap().starts_with("group:")).expect("the list's tile");    assert_eq!(list["pictogram"], cinemas["tile"]["pictures"]["list"], "a list wears the list role");    for view in views {        assert!(view["pictogram"].as_str().is_some_and(|photo| photo.starts_with("photo:")), "{} has no pictogram", view["id"]);    }    let books = tile(&answer, "books");    assert!(books.get("tile").is_none(), "Books names no tile: {books}");    assert!(books["views"].as_array().unwrap().iter().all(|view| view.get("pictogram").is_none()));    let whole = fan(&client, &cotton(), json!({}));    for other in whole["tiles"].as_array().unwrap().iter().filter(|tile| tile["key"] != "cinemas") {        assert!(other.get("tile").is_none(), "{} answers as it did", other["key"]);    }}/// Two fans asked at once each keep the view stood on, and neither fails (launch-story walk, 22 Nov 2026: after a/// sign-out the shell's refresh and its home asked the fan together; one rename found the other's file gone and the/// person read "That didn't work. Try again.").#[test]fn fans_asked_at_once_each_keep_the_view_without_failing() {    let (_dir, client) = attached();    std::thread::scope(|scope| {        let writers: Vec<_> = (0..8).map(|n| {            let client = &client;            scope.spawn(move || {                (0..40).map(|i| Kept { chosen: json!({"story": format!("view-{n}-{i}")}).as_object().unwrap().clone() }.write(client)).filter(Result::is_err).count()            })        }).collect();        let failed: usize = writers.into_iter().map(|writer| writer.join().unwrap()).sum();        assert_eq!(failed, 0, "every write of the kept view lands");    });    assert!(kept_chosen(&client).get("story").is_some_and(Value::is_string), "the file is whole");}// RULE (owner on Cotton Cinemas 1.0 (4), 7 Nov 2026): a relaunch opens on the view (or list) a person last stood on, kept beside the copy as shell.player keeps its song; a view that no longer exists falls back to the tool's first view. Every app alike, no flavour code.#[test]fn a_relaunch_opens_on_the_view_last_stood_on() {    let (_dir, client) = attached();    keeps_only(&client, &["cinemas"]);    let film = crate::phone::records::call(&client, "records.create", &json!({"table": "film", "data": {"title": "Synthetic film", "kind": "film"}})).unwrap();    let id = film["record"]["id"].as_str().unwrap();    crate::phone::records::call(&client, "groups.create", &json!({"table": "film", "name": "Synthetic nights", "records": [id]})).unwrap();    client.bring_moves_done_for_tests().unwrap();    let cinemas = FanCards { home: false, tools: false, settings: false, opens: Some("cinemas".into()), stream: false };    let first = fan(&client, &cinemas, json!({}));    let first_view = tile(&first, "cinemas")["views"][0]["id"].clone();    assert_eq!(first["opens"]["view"], first_view, "a fresh install opens on the tool's first view");    // The shell stands on Watched; a relaunch asks with no choice of its own.    fan(&client, &cinemas, json!({"chosen": {"cinemas": "watched"}}));    let relaunched = fan(&client, &cinemas, json!({}));    assert_eq!(relaunched["opens"], json!({"tier": "views", "tool": "cinemas", "view": "watched"}));    assert_eq!(relaunched["root"]["raised"], "watched");    assert_eq!(tile(&relaunched, "cinemas")["current"], "watched");    // A list is a view like any other.    let views = tile(&relaunched, "cinemas")["views"].as_array().unwrap().clone();    let list_view = views.iter().find(|view| view["id"].as_str().unwrap().starts_with("group:")).unwrap()["id"].clone();    fan(&client, &cinemas, json!({"chosen": {"cinemas": list_view}}));    assert_eq!(fan(&client, &cinemas, json!({}))["opens"]["view"], list_view, "the list stood on");    // The list goes: the relaunch falls back to the first view, and the kept file forgets it.    crate::phone::records::call(&client, "groups.delete", &json!({"id": list_view.as_str().unwrap().trim_start_matches("group:")})).unwrap();    client.bring_moves_done_for_tests().unwrap();    let gone = fan(&client, &cinemas, json!({}));    assert_eq!(gone["opens"]["view"], first_view, "a list since deleted falls back to the first view");    let kept: Value = serde_json::from_slice(&std::fs::read(client.layout().client_dir().join(KEPT_FILE)).unwrap()).unwrap();    assert!(kept[""].get("cinemas").is_none(), "the gone list leaves the file: {kept}");    // Cotton's fan keeps the same file: the tool's page stands on its kept view; the fan still opens on its tools at Home.    fan(&client, &cinemas, json!({"chosen": {"cinemas": "all"}}));    let cotton = fan(&client, &cotton(), json!({"tool": "cinemas"}));    assert_eq!(tile(&cotton, "cinemas")["current"], "all");    assert_eq!(cotton["root"]["raised"], HOME);    // Books, with no code of its own, opens on its own kept view.    let (_dir, client) = attached();    keeps_only(&client, &["books"]);    fan(&client, &books(), json!({"chosen": {"books": "finished"}}));    assert_eq!(fan(&client, &books(), json!({}))["opens"]["view"], "finished");}/// RULE (owner, 11 Nov 2026): the fan opens as it did, on its first view in the centre, and the cards a person reaches for less often stand to its LEFT as the app's kit names them: Account first, its tile saying how this phone's sign-in and sync stand. It is dealt before the first view and never raised; an app that keeps to no kit (Cotton) deals none.#[test]fn a_kits_fan_deals_account_left_of_its_first_view() {    let (_dir, client) = attached();    keeps_only(&client, &["todos"]);    let todos = FanCards { home: false, tools: false, settings: false, opens: Some("todos".into()), stream: false };    let plain = fan(&client, &todos, json!({}));    assert!(tile(&plain, "todos")["views"].as_array().unwrap().iter().all(|view| view["id"] != "account"), "no kit, no Account card");    cotton_core::kit::AppKit::keep(cotton_core::kit::AppKit::named("todos").as_ref(), client.layout().root()).expect("kept");    let answer = fan(&client, &todos, json!({}));    let views = tile(&answer, "todos")["views"].as_array().unwrap();    assert_eq!((views[0]["id"].as_str(), views[0]["label"].as_str(), views[0]["aside"].as_bool()), (Some("account"), Some("Account"), Some(true)), "{}", views[0]);    assert!(views[0]["line"].as_str().is_some_and(|line| !line.is_empty()), "its tile says how it stands: {}", views[0]);    assert_eq!(views[1]["default"], true, "the first view follows it");    assert_eq!(answer["root"]["cards"][0], "account");    assert_eq!(answer["root"]["raised"], views[1]["id"], "the fan still opens on its first view");    assert_eq!(answer["opens"]["view"], views[1]["id"]);    // Chosen, it is not kept as a view to open on: a relaunch opens on the first view.    let chosen = fan(&client, &todos, json!({"chosen": {"todos": "account"}}));    assert_eq!(chosen["root"]["raised"], views[1]["id"]);}// RULE (Developer Dev, 12 Nov 2026: a fresh install's fan was unreadable, "View made names no table"): one view naming a table the copy does not hold never blanks the fan: the fan drops that view and draws the tool's others.#[test]fn a_view_over_a_table_the_copy_does_not_hold_leaves_the_fan_without_it() {    let (_dir, client) = attached();    keeps_only(&client, &["memories", "agents"]);    cotton_core::kit::AppKit::keep(cotton_core::kit::AppKit::named("developer").as_ref(), client.layout().root()).expect("kept");    seed(&client, "DELETE FROM cotton_table_definitions WHERE id = 'session'", &[]);    let developer = FanCards { home: false, tools: false, settings: false, opens: Some("memories".into()), stream: false };    let answer = fan(&client, &developer, json!({}));    let ids: Vec<&str> = tile(&answer, "memories")["views"].as_array().unwrap().iter().map(|view| view["id"].as_str().unwrap()).collect();    assert_eq!(ids, ["account", "all", "archived"], "Agents is dropped, the rest drawn: {answer}");}// RULE (owner, 11 Nov 2026: "the fan menu is just views, and a view can be of a specific tool"): a Cotton app of several tools (Keys and Passwords; Money was the example until TABLE DROP 1) has no tools tier. Its fan is one tier: Account first, then every view of every tool its kit lists, in kit order; it opens on its first tool's first view, and a tool that declares no view is one tile under its own name.#[test]fn a_kit_of_several_tools_fans_one_tier_of_views() {    let (_dir, client) = attached();    keeps_only(&client, &["keys", "passwords"]);    cotton_core::kit::AppKit::keep(cotton_core::kit::AppKit::named("keys").as_ref(), client.layout().root()).expect("kept");    let keys_app = FanCards { home: false, tools: false, settings: false, opens: Some("keys".into()), stream: false };    let answer = fan(&client, &keys_app, json!({}));    assert_eq!(answer["opens"], json!({"tier": "views", "tool": "keys", "view": "all"}), "no tools tier");    assert_eq!(keys(&answer), ["keys"], "Passwords is no tile of its own");    let cards: Vec<&str> = answer["root"]["cards"].as_array().unwrap().iter().filter_map(Value::as_str).collect();    assert_eq!(cards, ["account", "all", "recent", "by_site", "devices", "passwords__all", "favourites", "codes", "logins", "cards", "notes", "ids", "wifi", "addresses", "api_keys", "documents", "health"]);    assert_eq!(answer["root"]["raised"], "all");    let views = tile(&answer, "keys")["views"].as_array().unwrap();    let passwords = views.iter().find(|view| view["id"] == "passwords__all").expect("Passwords' first view");    assert_eq!(passwords["read"]["table"].as_str(), Some("secret"), "{passwords}");}