//! Cinemas' streaming home (CONTRACT-2.md, 26 Nov 2026): the rows, his groups in his order, the kind he corrects,//! search, a title, and a season's episodes. Invented titles only.use serde_json::{json, Map, Value};usecrate::handle::CottonHandle;fn cinemas() -> (tempfile::TempDir, CottonHandle) {let dir = tempfile::tempdir().expect("a temp container");let manifest = json!({"genesis": "personal", "flavour": "cinemas", "name": "Cotton Cinemas", "ground": "velvet","databases": "single", "database": "personal", "fan": {"home": false, "tools": false, "opens": "cinemas"}, "kit": "cinemas", });let handle = CottonHandle::open(crate::handle::OpenConfig { mode: crate::handle::OpenMode::Phone { container_path: dir.path().to_string_lossy().to_string(), previous_container_path: None }, app_version: None, time_zone: Some("Asia/Kolkata".to_string()), device_secret: Some(crate::fixture::paired_secret()), vault_secret: None, flavor: cotton_core::flavor::Flavor::Real, manifest: Some(manifest), }) .expect("an open core");crate::methods::dispatch(&handle, "workspace.startLocal", &json!({"deviceName": "An invented phone"})).expect("started"); (dir, handle)}fn ask(handle: &CottonHandle, method: &str, request: Value) -> Value {crate::methods::dispatch(handle, method, &request).unwrap_or_else(|refusal| panic!("{method}: {refusal:?}"))}/// A film row with these columns; answers its id.fn made(handle: &CottonHandle, table: &str, data: Value) -> String {let data: Map<String, Value> = data.as_object().expect("an object").clone();let table = table.to_string();let answer = handle .client() .write_rows("test.cinemas", &mut |ctx| Ok(json!({ "id": super::super::songs::made(ctx, &table, data.clone())? }))) .expect("made");crate::authoring::own_answer(answer)["id"].as_str().expect("an id").to_string()}fn film(handle: &CottonHandle, title: &str, extra: Value) -> String {letmut data = json!({ "title": title, "kind": "film", "status": "want_to_watch", "minutes": 100 });for (key, value) in extra.as_object().expect("an object") { data[key] = value.clone(); } made(handle, "film", data)}fn row<'a>(home: &'a Value, id: &str) -> Option<&'a Value> { home["rows"].as_array().expect("rows").iter().find(|row| row["id"] == id)}fn titles(row: &Value) -> Vec<String> { row["items"].as_array().expect("items").iter().map(|item| item["title"].as_str().unwrap_or_default().to_string()).collect()}fn night_id(home: &Value) -> String { home["featured"]["item"]["id"].as_str().expect("a featured id").to_string()}fn row_ids(home: &Value) -> Vec<String> { home["rows"].as_array().expect("rows").iter().map(|row| row["id"].as_str().unwrap_or_default().to_string()).collect()}// RULE: a library with nothing in it answers the empty state, no rows.#[test]fn an_empty_library_says_so_and_offers_add() {let (_dir, handle) = cinemas();let home = ask(&handle, "cinemas.home", json!({})); assert!(home["rows"].as_array().unwrap().is_empty(), "{home}"); assert_eq!(home["empty"]["add"], "Add films");}// RULE (owner, 26 Nov 2026): the rows are Carry on, Recently added, the kinds, then his groups; no genres; an empty// automatic row is left out; the featured title is what he was watching.#[test]fn home_answers_carry_on_recent_kinds_and_leaves_out_empty_rows() {let (_dir, handle) = cinemas(); film(&handle, "Night Ferry", json!({ "position": 1800, "position_at": "2026-11-25T20:00:00Z", "added_on": "2026-11-01" })); film(&handle, "The Salt Road", json!({ "added_on": "2026-11-20" })); made(&handle, "film", json!({ "title": "Lowmarsh", "kind": "series", "status": "watching" })); made(&handle, "film", json!({ "title": "Kite Season (a channel's video)", "kind": "clip", "status": "want_to_watch", "source_url": "https://video.example/watch?v=invented" }));let home = ask(&handle, "cinemas.home", json!({})); assert_eq!(row_ids(&home), ["carry_on", "recent", "films", "series", "videos"], "{home}"); assert_eq!(titles(row(&home, "carry_on").unwrap()), ["Night Ferry"]); assert_eq!(titles(row(&home, "films").unwrap()), ["Night Ferry", "The Salt Road"]); assert_eq!(home["featured"]["item"]["title"], "Night Ferry"); assert_eq!(home["featured"]["play"], "Resume"); assert_eq!(home["featured"]["line"], "30:00 of 1:40:00");let page = ask(&handle, "cinemas.title", json!({ "table": "film", "id": night_id(&home) })); assert_eq!(page["play"]["label"], "Resume from 30:00", "a place under the hour is minutes and seconds: {page}");let night = &row(&home, "carry_on").unwrap()["items"][0]; assert_eq!(night["progress"], json!(0.3)); assert!(!home.to_string().to_lowercase().contains("genre"));}// RULE: a title the Mac is still converting says so: in its own row, marked preparing, and not playable as featured.#[test]fn a_title_still_on_the_mac_is_marked_preparing() {let (_dir, handle) = cinemas(); film(&handle, "Glass Harbour", json!({ "needs_mac": true, "added_on": "2026-11-24" }));let home = ask(&handle, "cinemas.home", json!({}));let ready = row(&home, "getting_ready").expect("its row"); assert_eq!(ready["items"][0]["preparing"], true); assert_eq!(home["featured"]["playable"], false); assert_eq!(home["featured"]["line"], "Your Mac is getting it ready");}// RULE (owner, 26 Nov 2026): his groups are rows after the automatic ones, in the order he sets; any title can be in// any number of groups; an empty group still stands.#[test]fn his_groups_are_rows_in_his_order() {let (_dir, handle) = cinemas();let ferry = film(&handle, "Night Ferry", json!({}));let salt = film(&handle, "The Salt Road", json!({}));let telugu = ask(&handle, "groups.create", json!({ "table": "film", "name": "Telugu", "records": [ferry] }));let telugu = telugu.pointer("/group/id").or_else(|| telugu.get("id")).and_then(Value::as_str).expect("a group id").to_string();let rainy = ask(&handle, "groups.create", json!({ "table": "film", "name": "Rainy Sundays", "records": [ferry, salt] }));let rainy = rainy.pointer("/group/id").or_else(|| rainy.get("id")).and_then(Value::as_str).expect("a group id").to_string();let empty = ask(&handle, "groups.create", json!({ "table": "film", "name": "Concerts" }));let empty = empty.pointer("/group/id").or_else(|| empty.get("id")).and_then(Value::as_str).expect("a group id").to_string();let home = ask(&handle, "cinemas.home", json!({}));let groups: Vec<String> = row_ids(&home).into_iter().filter(|id| id.starts_with("group:")).collect(); assert_eq!(groups, [format!("group:{telugu}"), format!("group:{rainy}"), format!("group:{empty}")]); assert_eq!(titles(row(&home, &format!("group:{rainy}")).unwrap()), ["Night Ferry", "The Salt Road"]); assert_eq!(row(&home, &format!("group:{empty}")).unwrap()["count"], 0);// He drags Rainy Sundays to the top: that is the rows' order on home.// Android asks it as CONTRACT-2 names it, groups.order; cinemas.groupsOrder is the same call. ask(&handle, "groups.order", json!({ "table": "film", "order": [rainy, empty] }));let home = ask(&handle, "cinemas.home", json!({}));let groups: Vec<String> = row_ids(&home).into_iter().filter(|id| id.starts_with("group:")).collect(); assert_eq!(groups, [format!("group:{rainy}"), format!("group:{empty}"), format!("group:{telugu}")]);let listed = ask(&handle, "cinemas.groups", json!({})); assert_eq!(listed["groups"][0]["name"], "Rainy Sundays"); assert_eq!(listed["groups"][0]["count"], 2);// A title's page ticks the groups it is in.let page = ask(&handle, "cinemas.title", json!({ "table": "film", "id": salt }));let ticked: Vec<&str> = page["groups"].as_array().unwrap().iter().filter(|g| g["in"] == true).map(|g| g["name"].as_str().unwrap()).collect(); assert_eq!(ticked, ["Rainy Sundays"]);// A stranger's id is refused, and nothing moves. assert!(crate::methods::dispatch(&handle, "cinemas.groupsOrder", &json!({ "order": ["no-such-group"] })).is_err());}// RULE: he corrects a title's kind in one act, and it stays where he put it.#[test]fn a_kind_he_corrects_moves_the_title_and_stays() {let (_dir, handle) = cinemas();let clip = film(&handle, "Harbour Lights Live", json!({}));let moved = ask(&handle, "cinemas.kind", json!({ "id": clip, "to": "clip" })); assert_eq!(moved["said"], "Moved to Videos");let home = ask(&handle, "cinemas.home", json!({})); assert_eq!(titles(row(&home, "videos").expect("videos")), ["Harbour Lights Live"]); assert!(row(&home, "films").is_none(), "nothing left in Films: {home}"); assert!(crate::methods::dispatch(&handle, "cinemas.kind", &json!({ "id": clip, "to": "genre" })).is_err());}// RULE: search finds a title by the start of its name first, then a word of it, and his groups by name.#[test]fn search_finds_titles_and_groups() {let (_dir, handle) = cinemas(); film(&handle, "Night Ferry", json!({})); film(&handle, "The Last Ferry Home", json!({})); film(&handle, "Salt Road", json!({})); ask(&handle, "groups.create", json!({ "table": "film", "name": "Ferry nights" }));let found = ask(&handle, "cinemas.search", json!({ "q": "ferry" }));let names: Vec<&str> = found["items"].as_array().unwrap().iter().map(|i| i["title"].as_str().unwrap()).collect(); assert_eq!(names, ["Night Ferry", "The Last Ferry Home"]); assert_eq!(found["groups"][0]["name"], "Ferry nights"); assert_eq!(ask(&handle, "cinemas.search", json!({ "q": " " }))["items"], json!([]));}// RULE (cinemas-3.html 2 and 5): a row opened answers its chips, one on, and narrows or orders by it; a video's page// lists more from its channel.#[test]fn a_row_filters_by_its_chips_and_a_video_lists_more_from_its_channel() {let (_dir, handle) = cinemas(); film(&handle, "Night Ferry", json!({ "status": "watched", "added_on": "2026-11-01" })); film(&handle, "Salt Road", json!({ "added_on": "2026-11-03" })); film(&handle, "Alder Lane", json!({ "added_on": "2026-11-02" }));let home = ask(&handle, "cinemas.home", json!({}));let films = row(&home, "films").expect("films").clone();let id = films["id"].as_str().unwrap();let names = |answer: &Value| answer["items"].as_array().unwrap().iter().map(|i| i["title"].as_str().unwrap().to_string()).collect::<Vec<_>>();let all = ask(&handle, "cinemas.row", json!({ "id": id }));let chips: Vec<(&str, &str, bool)> = all["chips"].as_array().unwrap().iter().map(|c| (c["id"].as_str().unwrap(), c["label"].as_str().unwrap(), c["on"].as_bool().unwrap())).collect(); assert_eq!(chips, [("all", "All", true), ("unwatched", "Not watched", false), ("on_phone", "On this phone", false), ("az", "A–Z", false), ("newest", "Newest", false)]); assert_eq!(names(&ask(&handle, "cinemas.row", json!({ "id": id, "filter": "az" }))), ["Alder Lane", "Night Ferry", "Salt Road"]); assert_eq!(names(&ask(&handle, "cinemas.row", json!({ "id": id, "filter": "newest" }))), ["Salt Road", "Alder Lane", "Night Ferry"]);let unwatched = ask(&handle, "cinemas.row", json!({ "id": id, "filter": "unwatched" })); assert_eq!((unwatched["count"].as_f64(), unwatched["filter"].as_str()), (Some(2.0), Some("unwatched")), "{unwatched}"); assert!(!names(&unwatched).contains(&"Night Ferry".to_string())); assert_eq!(ask(&handle, "cinemas.row", json!({ "id": id, "filter": "on_phone" }))["count"].as_f64(), Some(0.0));let one = film(&handle, "Tide Tables", json!({ "kind": "clip", "uploader": "Bench & Light", "source_url": "https://example.invalid/a", "added_on": "2026-11-04" })); film(&handle, "Rope Work", json!({ "kind": "clip", "uploader": "Bench & Light", "added_on": "2026-11-05" })); film(&handle, "Elsewhere", json!({ "kind": "clip", "uploader": "Other Channel" }));let page = ask(&handle, "cinemas.title", json!({ "table": "film", "id": one })); assert_eq!(page["more_from"]["title"], "More from Bench & Light", "{page}"); assert_eq!(names(&page["more_from"]), ["Rope Work"]); assert!(ask(&handle, "cinemas.title", json!({ "table": "film", "id": all["items"][0]["id"] }))["more_from"].is_null(), "a film with no channel has none");}// RULE (Cinemas lead, his real library on build 19): a library brought in on one day lists, within that day, what came// in last first, not the alphabet; and the featured title is one that plays, one with a picture first.#[test]fn a_library_brought_in_on_one_day_features_a_title_that_plays() {let (_dir, handle) = cinemas(); film(&handle, "Zebra Crossing", json!({ "added_on": "2026-11-20", "poster": "films/z/poster.jpg" })); std::thread::sleep(std::time::Duration::from_millis(5)); film(&handle, "Alder Lane", json!({ "added_on": "2026-11-20" })); std::thread::sleep(std::time::Duration::from_millis(5)); film(&handle, "Mkv Still Converting", json!({ "added_on": "2026-11-20", "needs_mac": true, "poster": "films/m/poster.jpg" }));let home = ask(&handle, "cinemas.home", json!({})); assert_eq!(titles(row(&home, "recent").unwrap()), ["Mkv Still Converting", "Alder Lane", "Zebra Crossing"], "the last in first: {home}"); assert_eq!(home["featured"]["item"]["title"], "Zebra Crossing", "not the one on the Mac, and one with a picture: {home}"); assert_eq!(home["featured"]["playable"], true); assert_eq!(home["featured"]["line"], Value::Null, "no year, nothing watched: no empty line");}// RULE (Cinemas lead, his real library on build 19): an importer's series names every season and episode, with or// without a number or a title, and its Play passes over an episode still on the Mac.#[test]fn an_importers_series_names_every_season_and_episode_and_plays_one_that_plays() {let (_dir, handle) = cinemas();let series = made(&handle, "film", json!({ "title": "Lowmarsh", "kind": "series", "status": "watching" }));// Titles are required of a season and an episode; the importer writes "Season 1" and "Episode 1" itself.let one = made(&handle, "film_season", json!({ "film": series, "number": 1, "title": "Season 1" }));let loose = made(&handle, "film_season", json!({ "film": series, "number": 0, "title": "Specials" })); made(&handle, "film_episode", json!({ "season": one, "series": series, "number": 1, "title": "Episode 1", "needs_mac": true })); made(&handle, "film_episode", json!({ "season": one, "series": series, "number": 2, "title": "Reeds", "file": "films/e2/master.m3u8" })); made(&handle, "film_episode", json!({ "season": loose, "series": series, "number": 1, "title": "A Night Walk", "file": "films/e3/master.m3u8" }));let page = ask(&handle, "cinemas.title", json!({ "table": "film", "id": series }));let names: Vec<&str> = page["seasons"].as_array().unwrap().iter().map(|s| s["title"].as_str().unwrap()).collect(); assert_eq!(names, ["Season 1", "Specials"], "specials (season 0) come after the seasons: {page}");let labels: Vec<String> = ask(&handle, "cinemas.season", json!({ "id": one }))["episodes"].as_array().unwrap().iter().map(|e| e["label"].as_str().unwrap().to_string()).collect(); assert_eq!(labels, ["1. Episode 1", "2. Reeds"]); assert_eq!(ask(&handle, "cinemas.season", json!({ "id": loose }))["episodes"][0]["label"], "1. A Night Walk");// A series starts at its first season, not its specials, passing over the episode still on the Mac. assert_eq!(page["play"]["label"], "Play S1 E2", "{page}");let first = ask(&handle, "cinemas.season", json!({ "id": one }))["episodes"][0].clone();let refused = crate::methods::dispatch(&handle, "shell.player", &json!({ "op": "play", "table": "film_episode", "id": first["id"] }));let said = format!("{refused:?}").to_lowercase(); assert!(said.contains("convert") || said.contains("mac"), "the episode on the Mac says so: {first} → {refused:?}");let played = ask(&handle, "shell.player", json!({ "op": "play", "table": "film", "id": series })); assert_eq!(played["now"]["caption"], "S1 E2 · Reeds", "{played}");}// RULE (cinemas-3.html 12, Android builder's ask, 26 Nov): You answers Cinemas' sections, each row with what it holds// and its act; a watching setting turned there is the one the player reads.#[test]fn you_answers_its_sections_and_a_setting_turns_where_the_player_reads_it() {let (_dir, handle) = cinemas(); film(&handle, "Night Ferry", json!({ "needs_mac": true })); ask(&handle, "groups.create", json!({ "table": "film", "name": "Rainy Sundays" }));let you = ask(&handle, "cinemas.you", json!({}));let sections: Vec<&str> = you["sections"].as_array().unwrap().iter().map(|s| s["id"].as_str().unwrap()).collect(); assert_eq!(sections, ["watching", "on_phone", "subtitles", "more"], "{you}");let row = |answer: &Value, id: &str| answer["sections"].as_array().unwrap().iter().flat_map(|s| s["rows"].as_array().unwrap().iter()).find(|r| r["id"] == id).cloned().unwrap_or_else(|| panic!("{id} in {answer}")); assert_eq!(row(&you, "mac")["value"], "1 waiting"); assert_eq!(row(&you, "groups")["value"], "1"); assert_eq!(row(&you, "subtitles_on")["switch"], true, "subtitles are on until he says otherwise"); assert_eq!(row(&you, "subtitle_language")["value"], "This phone's"); assert_eq!(row(&you, "mobile_data")["switch"], false);for row in you["sections"].as_array().unwrap().iter().flat_map(|s| s["rows"].as_array().unwrap().iter()) { assert!(row["label"].as_str().is_some_and(|l| !l.is_empty()) && row["act"].is_object(), "every row is worded and has its act: {row}"); }let act = row(&you, "subtitles_on")["act"].clone();let turned = ask(&handle, act["method"].as_str().unwrap(), act["request"].clone()); assert_eq!(row(&turned, "subtitles_on")["switch"], false, "{turned}");let turned = ask(&handle, "cinemas.setting", json!({ "key": "subtitle_language", "value": "te" })); assert_eq!(row(&turned, "subtitle_language")["value"], "Telugu"); assert_eq!(row(&turned, "subtitles_on")["switch"], false, "one setting kept beside the other"); assert_eq!(crate::phone::shell_player::kinds::Cinema::read(&handle.client()).unwrap().subtitle_language.as_deref(), Some("te"), "the player reads it");// Set back to the phone's own: null kept, on the one row (Android builder, 26 Nov: it still said the old one).let back = ask(&handle, "cinemas.setting", json!({ "key": "subtitle_language", "value": null })); assert_eq!(row(&back, "subtitle_language")["value"], "This phone's", "{back}"); assert_eq!(crate::phone::shell_player::kinds::Cinema::read(&handle.client()).unwrap().subtitle_language, None);let rows = ask(&handle, "records.list", json!({ "table": "face_settings", "where": { "table": "cinema" } })); assert_eq!(rows["records"].as_array().unwrap().len(), 1, "one settings row, changed in place: {rows}"); assert!(crate::methods::dispatch(&handle, "cinemas.setting", &json!({ "key": "speed", "value": 2 })).is_err());}// RULE (cinemas-3.html 6, Android builder's ask, 26 Nov): the top result says what it is, its year and what is left;// people (a director) and channels (an uploader) are found by name with their titles.#[test]fn search_says_the_top_result_and_finds_people_and_channels() {let (_dir, handle) = cinemas(); film(&handle, "Night Ferry", json!({ "year": "2021", "minutes": 90, "position": 1080, "position_at": "2026-11-20T20:00:00Z", "director": "Ada Marsh" })); film(&handle, "Salt Road", json!({ "year": "2019", "director": "Ada Marsh" }));let clip = film(&handle, "Tide Tables", json!({ "kind": "clip", "uploader": "Marshland Walks" }));let found = ask(&handle, "cinemas.search", json!({ "q": "night" })); assert_eq!(found["top_line"], "Film · 2021 · 1h 12m left", "{found}");let found = ask(&handle, "cinemas.search", json!({ "q": "marsh" }));let people: Vec<(&str, &str, &str)> = found["people"].as_array().unwrap().iter().map(|p| (p["name"].as_str().unwrap(), p["kind"].as_str().unwrap(), p["line"].as_str().unwrap())).collect(); assert_eq!(people, [("Ada Marsh", "person", "2 titles"), ("Marshland Walks", "channel", "1 title")], "{found}"); assert_eq!(found["people"][1]["ids"], json!([clip])); assert_eq!(found["items"].as_array().unwrap().len(), 3, "a title is found by who made it too: {found}"); assert_eq!(ask(&handle, "cinemas.search", json!({ "q": "tide" }))["top_line"], "Video", "no year, nothing watched");}// RULE: a season answers its episodes in order with their captions; a series' page lists its seasons.#[test]fn a_series_lists_its_seasons_and_a_season_its_episodes() {let (_dir, handle) = cinemas();let series = made(&handle, "film", json!({ "title": "Lowmarsh", "kind": "series", "status": "watching" }));let season = made(&handle, "film_season", json!({ "film": series, "number": 1, "title": "Season 1" }));for (number, title) in [(2, "Low Water"), (1, "Reeds")] { made(&handle, "film_episode", json!({ "season": season, "number": number, "title": title, "minutes": 50 })); }let page = ask(&handle, "cinemas.title", json!({ "table": "film", "id": series })); assert_eq!(page["seasons"][0]["title"], "Season 1", "{page}"); assert_eq!(page["play"]["label"], "Play S1 E1", "a series says the episode it plays: {page}");let answer = ask(&handle, "cinemas.season", json!({ "id": season }));let episodes: Vec<&str> = answer["episodes"].as_array().unwrap().iter().map(|e| e["episode_title"].as_str().unwrap()).collect(); assert_eq!(episodes, ["Reeds", "Low Water"]); assert_eq!(answer["episodes"][0]["caption"], "S1 E1 · Reeds", "{answer}");}// RULE (CONTRACT-2): a film that is really an episode moves under a new series, keeping its file and where he stopped.#[test]fn a_film_that_is_an_episode_moves_under_a_new_series() {let (_dir, handle) = cinemas();let id = film(&handle, "Reeds", json!({ "position": 600, "position_at": "2026-11-20T20:00:00Z", "minutes": 50, "added_on": "2026-11-01" }));let moved = ask(&handle, "cinemas.toEpisode", json!({ "id": id, "series": { "new": "Lowmarsh" }, "season": 2, "episode": 3 })); assert_eq!(moved["table"], "film_episode", "{moved}");let home = ask(&handle, "cinemas.home", json!({})); assert_eq!(titles(row(&home, "series").expect("a series row")), ["Lowmarsh"], "{home}"); assert!(row(&home, "films").is_none(), "the film row is gone: {home}");let carrying = row(&home, "carry_on").expect("still part-watched"); assert_eq!(carrying["items"][0]["caption"], "S2 E3 · Reeds", "{home}"); assert_eq!(carrying["items"][0]["minutes"].as_f64(), Some(50.0), "{home}");let page = ask(&handle, "cinemas.title", json!({ "table": "film", "id": moved["series"] })); assert_eq!(page["seasons"][0]["number"].as_f64(), Some(2.0), "{page}");}// RULE (CONTRACT-2): a film brought in by intake, kept on this phone with its key, moves under a series intake made// (the Android builder's walk on emulator-5610: it was refused there).#[test]fn an_imported_film_moves_under_an_imported_series() {let (dir, handle) = cinemas();let invented = |name: &str, bytes: &[u8]| {let path = dir.path().join(name.replace('/', "_")); std::fs::write(&path, bytes).expect("the file"); json!({ "path": path.to_string_lossy(), "sourcePath": name, "minutes": 1.0, "video": "avc1", "audio": "mp4a", "height": 720, "bitrate": 900 }) };let films = [ invented("Lowmarsh/Season 1/Lowmarsh.S01E01.mp4", b"invented episode one"), invented("Lowmarsh/Season 2/Lowmarsh.S02E01.mp4", b"invented episode two"), invented("Marshwatchers.mp4", b"invented film bytes"), ];let answer = ask(&handle, "films.capture", json!({ "films": films, "onlyFilms": false }));let id = answer["films"][2]["id"].as_str().unwrap_or_else(|| panic!("the film: {answer}")).to_string();let series = answer["films"][0]["series"].as_str().unwrap_or_else(|| panic!("the series: {answer}")).to_string();let moved = crate::methods::dispatch(&handle, "cinemas.toEpisode", &json!({ "id": id, "series": series, "season": 3, "episode": 1 }));let moved = moved.unwrap_or_else(|refusal| panic!("moved: {refusal:?}")); assert_eq!(moved["series"], series.as_str(), "{moved}");let page = ask(&handle, "cinemas.title", json!({ "table": "film", "id": series }));let numbers: Vec<f64> = page["seasons"].as_array().unwrap().iter().filter_map(|s| s["number"].as_f64()).collect(); assert_eq!(numbers, [1.0, 2.0, 3.0], "{page}");// The film row is gone from the file, Bin and all: the episode is that film now.letmut binned: Option<Map<String, Value>> = None; handle .client() .read_rows("test.binned", &mut |ctx| {// The Bin's rows too: rows_where reads only live ones.let made = cotton_tools::mcp::handlers::tables::made_table("film");let found = ctx .db() .all(&format!("SELECT deleted_at, file, source_file, original FROM {made} WHERE id = ?"), &[rusqlite::types::Value::Text(id.clone())]) .map_err(|error| error.to_string())?; binned = found.first().map(|row| row.columns().iter().map(|(name, value)| (name.to_string(), match value { rusqlite::types::Value::Null => Value::Null, rusqlite::types::Value::Text(text) => Value::from(text.clone()), other => Value::from(format!("{other:?}")), })).collect::<Map<String, Value>>());Ok(Value::Null) }) .expect("read"); assert_eq!(binned, None, "the film row ends for good, never in the Bin, so nothing can put a fileless copy back");let bin = ask(&handle, "cinemas.bin", json!({})); assert!(!bin.to_string().contains(&id), "the Bin does not list a film that became an episode: {bin}");}// RULE (CONTRACT-2): a second episode joins the series and season already there, by id; a series is never an episode.#[test]fn a_second_episode_joins_the_series_already_there() {let (_dir, handle) = cinemas();let first = film(&handle, "Reeds", json!({}));let second = film(&handle, "Low Water", json!({}));let moved = ask(&handle, "cinemas.toEpisode", json!({ "id": first, "series": { "new": "Lowmarsh" }, "season": 1, "episode": 1 }));let again = ask(&handle, "cinemas.toEpisode", json!({ "id": second, "series": moved["series"], "season": 1, "episode": 2 })); assert_eq!(again["season"], moved["season"], "{again}");let named = ask(&handle, "cinemas.toEpisode", json!({ "id": film(&handle, "Mud", json!({})), "series": { "new": "lowmarsh " }, "season": 1, "episode": 3 })); assert_eq!(named["series"], moved["series"], "found by its name: {named}");let season = ask(&handle, "cinemas.season", json!({ "id": moved["season"] }));let episodes: Vec<&str> = season["episodes"].as_array().unwrap().iter().map(|e| e["episode_title"].as_str().unwrap()).collect(); assert_eq!(episodes, ["Reeds", "Low Water", "Mud"]);let series_id = moved["series"].as_str().unwrap(); assert!(crate::methods::dispatch(&handle, "cinemas.toEpisode", &json!({ "id": series_id, "series": { "new": "Other" }, "season": 1, "episode": 1 })).is_err()); assert!(crate::methods::dispatch(&handle, "cinemas.toEpisode", &json!({ "id": film(&handle, "Fen", json!({})), "series": series_id, "season": 0, "episode": 1 })).is_err());}// RULE (CONTRACT-2): home at 400 titles and 10 groups answers fast enough to draw at once.#[test]fn home_at_four_hundred_titles_is_fast() {let (_dir, handle) = cinemas();letmut ids = Vec::new(); handle .client() .write_rows("test.many", &mut |ctx| {for n in0..400 {letmut data = Map::new(); data.insert("title".into(), json!(format!("Invented Film {n:03}"))); data.insert("kind".into(), json!(if n % 10 == 0 { "series" } else { "film" })); data.insert("status".into(), json!("want_to_watch")); data.insert("minutes".into(), json!(95)); data.insert("added_on".into(), json!(format!("2026-{:02}-{:02}", 1 + n % 11, 1 + n % 28)));if n % 7 == 0 { data.insert("position".into(), json!(600)); data.insert("position_at".into(), json!(format!("2026-11-{:02}T20:00:00Z", 1 + n % 25))); } ids.push(super::super::songs::made(ctx, "film", data)?); }Ok(Value::Null) }) .expect("made");for g in0..10 {let members: Vec<&String> = ids.iter().skip(g * 20).take(30).collect(); ask(&handle, "groups.create", json!({ "table": "film", "name": format!("Group {g}"), "records": members })); }let started = std::time::Instant::now();let home = ask(&handle, "cinemas.home", json!({}));let took = started.elapsed(); assert_eq!(row(&home, "films").unwrap()["count"], 360); assert_eq!(row(&home, "films").unwrap()["items"].as_array().unwrap().len(), 20); assert_eq!(row_ids(&home).iter().filter(|id| id.starts_with("group:")).count(), 10);// Paged as both phones keep the place: `next` is text, and `after` is taken as text or a number (his library on// build 19: a row past 60 failed to open on the iPhone and repeated its first page on Android).let first = ask(&handle, "cinemas.row", json!({ "id": "films" })); assert_eq!(first["next"], "60");let page = ask(&handle, "cinemas.row", json!({ "id": "films", "after": first["next"] })); assert_eq!(page["items"].as_array().unwrap().len(), 60); assert_eq!(page["next"], "120"); assert_ne!(page["items"][0]["id"], first["items"][0]["id"], "the second page, not the first again"); assert_eq!(ask(&handle, "cinemas.row", json!({ "id": "films", "after": 60 }))["items"][0]["id"], page["items"][0]["id"]); assert_eq!(ask(&handle, "cinemas.row", json!({ "id": "films", "after": "300" }))["next"], Value::Null, "the last page has none");// A debug build on a shared box: generous; the phone's release build is far quicker. assert!(took < std::time::Duration::from_millis(1500), "home took {took:?}");}// RULE (coordinator, 26 Nov 2026): Home at his library's far size, 2,000 titles (films, videos, series with their// seasons and 300 episodes, part-watched among them) and 40 groups, stays one read and fast. Making 2,000 sealed rows// takes minutes in a debug build, so it runs by name (as post_at_his_size does):// `cargo test -p cotton-ffi --lib home_at_two_thousand -- --ignored --nocapture`.#[test]#[ignore]fn home_at_two_thousand_titles_and_forty_groups_is_one_fast_read() {let (_dir, handle) = cinemas();letmut ids = Vec::new(); handle .client() .write_rows("test.many", &mut |ctx| {for n in0..1700 {letmut data = Map::new(); data.insert("title".into(), json!(format!("Invented Film {n:04}"))); data.insert("kind".into(), json!(if n % 9 == 0 { "clip" } else { "film" })); data.insert("status".into(), json!("want_to_watch")); data.insert("minutes".into(), json!(60 + n % 90)); data.insert("file".into(), json!(format!("films/{n}/master.m3u8"))); data.insert("added_on".into(), json!(format!("2026-{:02}-{:02}", 1 + n % 11, 1 + n % 28)));if n % 11 == 0 { data.insert("position".into(), json!(600 + n)); data.insert("position_at".into(), json!(format!("2026-11-{:02}T20:{:02}:00Z", 1 + n % 25, n % 60))); } ids.push(super::super::songs::made(ctx, "film", data)?); }for s in0..30 {letmut series = Map::new(); series.insert("title".into(), json!(format!("Invented Series {s:02}"))); series.insert("kind".into(), json!("series")); series.insert("status".into(), json!("watching"));let series = super::super::songs::made(ctx, "film", series)?; ids.push(series.clone());for season in1..=2 {letmut row = Map::new(); row.insert("film".into(), json!(series)); row.insert("number".into(), json!(season)); row.insert("title".into(), json!(format!("Season {season}")));let season_id = super::super::songs::made(ctx, "film_season", row)?;for e in1..=5 {letmut episode = Map::new(); episode.insert("season".into(), json!(season_id)); episode.insert("series".into(), json!(series)); episode.insert("number".into(), json!(e)); episode.insert("title".into(), json!(format!("Episode {e}"))); episode.insert("minutes".into(), json!(50)); episode.insert("file".into(), json!(format!("films/s{s}/{season}/{e}/master.m3u8")));if e == 3 { episode.insert("position".into(), json!(900)); episode.insert("position_at".into(), json!("2026-11-24T21:00:00Z")); }super::super::songs::made(ctx, "film_episode", episode)?; } } }Ok(Value::Null) }) .expect("made");for g in0..40 {let members: Vec<&String> = ids.iter().skip((g * 43) % (ids.len() - 60)).take(60).collect(); ask(&handle, "groups.create", json!({ "table": "film", "name": format!("Group {g:02}"), "records": members })); }let started = std::time::Instant::now();let home = ask(&handle, "cinemas.home", json!({}));let took = started.elapsed(); eprintln!("cinemas.home at 1,730 films and series, 300 episodes, 40 groups: {took:?}"); assert_eq!(row(&home, "films").unwrap()["count"], 1700 - 189, "{}", row(&home, "films").unwrap()["count"]); assert_eq!(row(&home, "series").unwrap()["count"], 30); assert_eq!(row(&home, "videos").unwrap()["count"], 189); assert_eq!(row_ids(&home).iter().filter(|id| id.starts_with("group:")).count(), 40); assert!(row(&home, "carry_on").unwrap()["count"].as_u64().unwrap() >= 150, "part-watched films and episodes");let ordered: Vec<String> = row_ids(&home).into_iter().filter(|id| id.starts_with("group:")).collect(); assert_eq!(ordered.len(), 40);let search_started = std::time::Instant::now();let found = ask(&handle, "cinemas.search", json!({ "q": "series 1" })); eprintln!("cinemas.search at that size: {:?}", search_started.elapsed()); assert!(!found["items"].as_array().unwrap().is_empty());// A debug build on a shared box: generous; the phone's release build is several times quicker. assert!(took < std::time::Duration::from_millis(5000), "home took {took:?}");}fn act_ids(title: &Value) -> Vec<String> { title["acts"].as_array().expect("acts").iter().map(|act| act["id"].as_str().unwrap_or_default().to_string()).collect()}// RULE (CONTRACT-2, a title's acts): the page lists Keep (only for a file the phone can keep, never while the Mac is// getting it ready), Add to a group, What it is (a film row), Mark watched or unwatched as it stands, and the Bin, each// labelled in the core's words.#[test]fn a_title_lists_its_acts_as_it_stands() {let (_dir, handle) = cinemas();let night = film(&handle, "Night Ferry", json!({ "file": "films/night-ferry/master.m3u8" }));let title = ask(&handle, "cinemas.title", json!({ "table": "film", "id": night })); assert_eq!(act_ids(&title), ["keep", "group", "send", "subtitles", "kind", "mark_watched", "bin"]); assert_eq!(title["acts"][0]["label"], "Keep on this phone"); assert_eq!(title["acts"][0]["short"], "Keep on phone", "the row of four reads the short words");let places: Vec<&str> = title["acts"].as_array().unwrap().iter().map(|a| a["place"].as_str().unwrap()).collect(); assert_eq!(places, ["row", "row", "row", "row", "more", "more", "more"], "the row of four, then More (cinemas-3.html 3)");let subs = json!([{ "language": "en", "name": "English", "source": "generated" }]).to_string();let kite = film(&handle, "Kite Season", json!({ "file": "films/kite/master.m3u8", "subtitles": subs, "minutes": 141, "position": 1680, "position_at": "2026-11-25T20:00:00Z" }));let page = ask(&handle, "cinemas.title", json!({ "table": "film", "id": kite }));let subtitles = page["acts"].as_array().unwrap().iter().find(|a| a["id"] == "subtitles").cloned().unwrap(); assert_eq!(subtitles["second"], "English", "{page}"); assert_eq!(page["watched_line"], "28 min watched · 1h 53m left", "{page}");let video = film(&handle, "How a Lens Is Ground", json!({ "kind": "clip", "file": "films/lens/whole.mp4", "source_url": "https://video.example/watch?v=invented", "uploader": "Bench & Light" }));let clip = ask(&handle, "cinemas.title", json!({ "table": "film", "id": video })); assert_eq!(&act_ids(&clip)[..3], ["keep", "open_page", "group"], "a video's row: {clip}"); assert_eq!(title["acts"][6]["short"], "Move to the Bin", "an act with no short words reads its label"); ask(&handle, "films.mark", json!({ "table": "film", "id": night, "watched": true }));let watched = ask(&handle, "cinemas.title", json!({ "table": "film", "id": night })); assert!(act_ids(&watched).contains(&"mark_unwatched".to_string()), "watched now: {watched}");let glass = film(&handle, "Glass Harbour", json!({ "file": "films/glass/master.m3u8", "needs_mac": true }));let preparing = ask(&handle, "cinemas.title", json!({ "table": "film", "id": glass })); assert!(!act_ids(&preparing).contains(&"keep".to_string()), "nothing to keep while the Mac works: {preparing}");}// RULE (cinemas-3.html 3, a title's Subtitles): the tracks the Mac laid, each with where it came from, the one he chose// as the act's line, and Find, Make and Give while the Mac is not already at work; at work, its own line and no acts// but Give's absence too.#[test]fn a_titles_subtitles_say_its_tracks_and_what_the_mac_is_doing() {let (_dir, handle) = cinemas();let tracks = json!([ { "language": "en", "name": "English", "source": "generated" }, { "language": "te", "name": "Telugu", "source": "embedded" }, ]) .to_string();let id = film(&handle, "Kite Season", json!({ "file": "films/kite/master.m3u8", "subtitles": tracks, "subtitle_work": "ready", "subtitle_choice": "{\"language\":\"te\",\"name\":\"Telugu\"}" }));let page = ask(&handle, "cinemas.subtitles", json!({ "table": "film", "id": id })); assert_eq!(page["line"], "Telugu", "{page}"); assert_eq!(page["tracks"][0]["from"], "made by your Mac"); assert_eq!(page["tracks"][1]["from"], "in the file"); assert_eq!(page["tracks"][1]["chosen"], true);let acts: Vec<&str> = page["acts"].as_array().unwrap().iter().map(|a| a["id"].as_str().unwrap()).collect(); assert_eq!(acts, ["find", "make", "give"]); assert_eq!(page["working"], Value::Null);let bare = film(&handle, "Quiet Engines", json!({ "file": "films/quiet/master.m3u8", "subtitle_work": "generating" }));let busy = ask(&handle, "cinemas.subtitles", json!({ "table": "film", "id": bare })); assert_eq!((busy["line"].as_str(), busy["working"].as_str()), (Some("None yet"), Some("Your Mac is making subtitles")), "{busy}"); assert!(busy["acts"].as_array().unwrap().is_empty(), "nothing to ask while the Mac works: {busy}");}// RULE (cinemas-3.html 10, keeping for a flight): what is wholly here, its length and whether it all has subtitles,// each kept title with its own line, and a title still coming down said as keeping, never counted for the flight.#[test]fn on_this_phone_says_what_is_ready_for_a_flight() {let (_dir, handle) = cinemas(); assert_eq!(ask(&handle, "cinemas.onPhone", json!({}))["items"], json!([]));let subs = json!([{ "language": "en", "name": "English", "source": "sidecar" }]).to_string(); film(&handle, "The Salt Orchard", json!({ "file": "films/salt/master.m3u8", "minutes": 120, "subtitles": subs }));let series = made(&handle, "film", json!({ "title": "Lowmarsh", "kind": "series", "status": "watching" }));let season = made(&handle, "film_season", json!({ "film": series, "number": 2, "title": "Season 2" })); made(&handle, "film_episode", json!({ "season": season, "number": 6, "title": "High Water", "minutes": 50, "file": "films/low/s2e6/master.m3u8" })); film(&handle, "Kite Season", json!({ "file": "films/kite/master.m3u8", "minutes": 141 }));let client = handle.client();for (key, state) in [("films/salt/master.m3u8", "kept"), ("films/low/s2e6/master.m3u8", "kept"), ("films/kite/master.m3u8", "keeping")] {crate::phone::films::write(&client, &json!({ "key": key, "state": state, "bookmark": "Ym9va21hcms=" })).expect("kept"); }let page = ask(&handle, "cinemas.onPhone", json!({ "free_bytes": 48_000_000_000u64 })); assert_eq!(page["flight"]["line"], "Ready for a flight: 2h 50m", "kept, not keeping: {page}"); assert_eq!(page["flight"]["what"], "1 film and 1 episode. They play with no internet.", "High Water has no subtitles: {page}");let lines: Vec<(&str, &str)> = page["items"].as_array().unwrap().iter().map(|i| (i["item"]["title"].as_str().unwrap(), i["line"].as_str().unwrap())).collect(); assert_eq!(lines, [("Kite Season", "Keeping on this phone"), ("Lowmarsh", "On this phone"), ("The Salt Orchard", "On this phone · subtitles")]); assert!(page["space"].as_str().unwrap().ends_with("48.0 GB free"), "{page}");}// RULE (cinemas-3.html 11, still being prepared): the Mac's steps as they stand, what waits ahead of it, and no minutes// it cannot know.#[test]fn a_title_the_mac_is_preparing_lists_its_steps_and_its_place() {let (_dir, handle) = cinemas(); film(&handle, "Paper Comets", json!({ "needs_mac": true })); std::thread::sleep(std::time::Duration::from_millis(20));let glass = film(&handle, "Glass Harbour", json!({ "needs_mac": true, "subtitle_work": "generate" }));let page = ask(&handle, "cinemas.preparing", json!({ "table": "film", "id": glass }));let steps: Vec<(&str, &str)> = page["steps"].as_array().unwrap().iter().map(|s| (s["label"].as_str().unwrap(), s["state"].as_str().unwrap())).collect(); assert_eq!(steps, [("Received from the phone", "done"), ("Making a copy the TV and phone can play", "now"), ("Making subtitles", "next")], "{page}"); assert_eq!(page["queue"], "1 ahead of it"); assert_eq!(page["head"], "Your Mac at home is preparing this film"); assert!(!page.to_string().contains(" min"), "no minutes it cannot know: {page}");}// RULE (cinemas-3.html, every `.po`; coordinator 26 Nov): a title's drawn picture is the core's, two of the design's// colours and one of its nine shapes from its id, the same every time; an episode wears its series'. An episode row// says watched or what is left; a flight of files that said no length says none.#[test]fn every_title_carries_its_drawn_picture_and_an_episode_its_state() {let (_dir, handle) = cinemas();let series = made(&handle, "film", json!({ "title": "Lowmarsh", "kind": "series", "status": "watching" }));let season = made(&handle, "film_season", json!({ "film": series, "number": 2, "title": "Season 2" })); made(&handle, "film_episode", json!({ "season": season, "series": series, "number": 4, "title": "Peat Fire", "minutes": 48, "status": "watched" })); made(&handle, "film_episode", json!({ "season": season, "series": series, "number": 5, "title": "The Wardens", "minutes": 51, "position": 1680, "position_at": "2026-11-25T20:00:00Z", "file": "films/low/5/master.m3u8" })); film(&handle, "Night Ferry", json!({}));let home = ask(&handle, "cinemas.home", json!({}));let series_art = row(&home, "series").unwrap()["items"][0]["art"].clone(); assert!(series_art["a"].as_str().unwrap().starts_with('#') && !series_art["shape"].as_str().unwrap().is_empty(), "{series_art}"); assert_eq!(ask(&handle, "cinemas.home", json!({}))["rows"], home["rows"], "the same every time");let carrying = row(&home, "carry_on").unwrap()["items"][0].clone(); assert_eq!(carrying["art"], series_art, "an episode wears its series' picture: {carrying}");let answer = ask(&handle, "cinemas.season", json!({ "id": season }));let states: Vec<Value> = answer["episodes"].as_array().unwrap().iter().map(|e| e["state_line"].clone()).collect(); assert_eq!(states, [json!("watched"), json!("23 min left")], "{answer}"); film(&handle, "Six Seconds", json!({ "file": "films/six/master.m3u8", "minutes": 0 }));crate::phone::films::write(&handle.client(), &json!({ "key": "films/six/master.m3u8", "state": "kept", "bookmark": "Ym9va21hcms=" })).expect("kept"); assert_eq!(ask(&handle, "cinemas.onPhone", json!({}))["flight"]["line"], "Ready for a flight", "never 0 min");}// RULE (Android builder's ask, 26 Nov): a film moved to the Bin is listed there, newest first, with the day it went// in, and comes back as it was, files and all; the Bin empty says so.#[test]fn the_bin_lists_a_binned_film_and_restores_it() {let (_dir, handle) = cinemas(); assert!(ask(&handle, "cinemas.bin", json!({}))["empty"].is_string());let id = film(&handle, "Night Ferry", json!({ "file": "films/night/master.m3u8" })); ask(&handle, "records.delete", json!({ "table": "film", "id": id })); assert!(row(&ask(&handle, "cinemas.home", json!({})), "films").is_none(), "gone from Home");let bin = ask(&handle, "cinemas.bin", json!({})); assert_eq!(bin["items"][0]["item"]["title"], "Night Ferry", "{bin}"); assert!(bin["items"][0]["line"].as_str().unwrap().starts_with("Moved to the Bin 20"), "{bin}");let back = ask(&handle, "cinemas.restore", json!({ "id": id })); assert_eq!(back["said"], "Back in Cinemas", "{back}");let home = ask(&handle, "cinemas.home", json!({})); assert_eq!(titles(row(&home, "films").unwrap()), ["Night Ferry"]);let page = ask(&handle, "cinemas.title", json!({ "table": "film", "id": id })); assert_eq!(page["playable"], true, "its file came back with it: {page}"); assert!(ask(&handle, "cinemas.bin", json!({}))["items"].as_array().unwrap().is_empty());}// RULE (CINEMAS DEV PROOF, 26 Nov): the Bin is emptied, or one title in it erased, for good; a live title never is.#[test]fn the_bin_empties_for_good_and_never_takes_a_live_film() {let (_dir, handle) = cinemas();let kept = film(&handle, "Iron Kettle", json!({ "file": "films/kettle/master.m3u8" }));let one = film(&handle, "Night Ferry", json!({ "file": "films/night/master.m3u8" }));let two = film(&handle, "Paper Moons", json!({ "file": "films/moons/master.m3u8" }));for id in [&one, &two] { ask(&handle, "records.delete", json!({ "table": "film", "id": id })); }let refused = crate::methods::dispatch(&handle, "cinemas.erase", &json!({ "id": kept })).expect_err("a live film is not erased from the Bin"); assert_eq!(refused.code, "refused"); assert_eq!(ask(&handle, "cinemas.erase", json!({ "id": one }))["erased"].as_f64(), Some(1.0)); assert_eq!(ask(&handle, "cinemas.bin", json!({}))["items"].as_array().unwrap().len(), 1, "one left in the Bin"); assert_eq!(ask(&handle, "cinemas.erase", json!({}))["erased"].as_f64(), Some(1.0)); assert!(ask(&handle, "cinemas.bin", json!({}))["empty"].is_string()); assert!(crate::methods::dispatch(&handle, "cinemas.restore", &json!({ "id": two })).is_err(), "erased, nothing to put back"); assert_eq!(titles(row(&ask(&handle, "cinemas.home", json!({})), "films").unwrap()), ["Iron Kettle"]);}// RULE (cinemas-3.html 8, the remote): the TV it plays on, the episode named under its series, where it stands and what// is left, and the next episode that has a file.#[test]fn the_remote_names_the_tv_the_episode_and_the_next() {let (_dir, handle) = cinemas();let series = made(&handle, "film", json!({ "title": "Lowmarsh", "kind": "series", "status": "watching" }));let season = made(&handle, "film_season", json!({ "film": series, "number": 2, "title": "Season 2" }));let five = made(&handle, "film_episode", json!({ "season": season, "series": series, "number": 5, "title": "The Wardens", "minutes": 51, "file": "films/low/s2e5/master.m3u8" }));let six = made(&handle, "film_episode", json!({ "season": season, "series": series, "number": 6, "title": "High Water", "minutes": 49, "file": "films/low/s2e6/master.m3u8" }));let remote = ask(&handle, "cinemas.remote", json!({ "table": "film_episode", "id": five, "at_s": 1390, "device": "Living room TV" })); assert_eq!(remote["playing"], "Playing on Living room TV", "{remote}"); assert_eq!((remote["title"].as_str(), remote["caption"].as_str()), (Some("The Wardens"), Some("Lowmarsh · Season 2, Episode 5"))); assert_eq!((remote["at"].as_str(), remote["left"].as_str()), (Some("23:10"), Some("−27:50"))); assert_eq!(remote["next"]["id"], six.as_str());let last = ask(&handle, "cinemas.remote", json!({ "table": "film_episode", "id": six, "at_s": 0 })); assert_eq!((last["playing"].as_str(), &last["next"]), (Some("Playing on your TV"), &Value::Null));}/// Every title id any listed answer names, anywhere in it.fn ids_in(answer: &Value, out: &mutVec<String>) {match answer {Value::Object(map) => {ifletSome(id) = map.get("id").and_then(Value::as_str) { out.push(id.to_string()); } map.values().for_each(|v| ids_in(v, out)); }Value::Array(list) => list.iter().for_each(|v| ids_in(v, out)), _ => {} }}// RULE (HIDDEN, owner 26 Nov 2026; CONTRACT-2.md; review of a8580dbc38): a title in ANY hidden category is hidden,// and so is every episode of a hidden series. Outside Hidden no answer names it, nor the hidden category's name: not// Home, rows, search, the picker, On this phone, Getting ready, You, the Bin, the shared list of lists, nor Keep// everything's plan. Inside (`hidden: true`, open only by the core's unlock after the phone's lock) they are all there;// Stop hiding brings them back everywhere; a hidden category is not deleted from under its titles.#[test]fn a_hidden_category_hides_its_titles_everywhere_but_hidden() {let (_dir, handle) = cinemas();let edit = film(&handle, "Edit Reel Four", json!({ "position": 300, "position_at": "2026-11-25T20:00:00Z", "added_on": "2026-11-25" }));let both = film(&handle, "Ferry Cut", json!({ "added_on": "2026-11-24", "file": "films/both/master.m3u8" }));let open = film(&handle, "Night Ferry", json!({ "added_on": "2026-11-20", "file": "films/open/master.m3u8" }));let series = made(&handle, "film", json!({ "title": "Harbour Diaries", "kind": "series", "status": "want_to_watch" }));let season = made(&handle, "film_season", json!({ "film": series, "number": 1, "title": "Season 1" }));let episode = made(&handle, "film_episode", json!({ "season": season, "series": series, "number": 1, "title": "Reeds", "position": 60, "position_at": "2026-11-25T21:00:00Z" }));let made_group = |name: &str, records: Vec<&String>| {let g = ask(&handle, "groups.create", json!({ "table": "film", "name": name, "records": records })); g.pointer("/group/id").or_else(|| g.get("id")).and_then(Value::as_str).expect("a group id").to_string() };// A hidden title kept on this phone, one the Mac is preparing, and one in the Bin (review A4: real, not empty).let kept = film(&handle, "Edit Reel Kept", json!({ "file": "films/kept/master.m3u8", "minutes": 20 }));let making = film(&handle, "Edit Reel Making", json!({ "needs_mac": true }));let binned = film(&handle, "Edit Reel Binned", json!({}));crate::phone::films::write(&handle.client(), &json!({ "key": "films/kept/master.m3u8", "state": "kept", "bookmark": "Ym9va21hcms=" })).expect("kept");let edits = made_group("My edit videos", vec![&edit, &both, &series, &kept, &making, &binned]);let shelf = made_group("Ferries", vec![&both, &open]); ask(&handle, "records.delete", json!({ "table": "film", "id": binned }));let on_phone = ask(&handle, "cinemas.onPhone", json!({})); assert!(on_phone.to_string().contains("Edit Reel Kept"), "before hiding, On this phone lists it: {on_phone}");let hid = ask(&handle, "cinemas.hide", json!({ "id": edits, "hidden": true })); assert_eq!(hid["line"], "My edit videos is hidden"); assert_eq!(hid["undo"]["args"]["hidden"], false);// Undo on Home's "… is hidden" runs as handed back, outside Hidden, once (re-review item 1).let undo = hid["undo"].clone();let undone = ask(&handle, undo["method"].as_str().unwrap(), undo["args"].clone()); assert_eq!(undone["hidden"], false, "{undone}"); assert!(crate::methods::dispatch(&handle, "cinemas.hide", &undo["args"]).is_err(), "an undo runs once");let hid = ask(&handle, "cinemas.hide", json!({ "id": edits, "hidden": true })); assert!(hid["undo"]["args"]["undo"].as_str().is_some_and(|token| !token.is_empty()));let hidden_ids = [edit.as_str(), both.as_str(), series.as_str(), episode.as_str(), edits.as_str(), kept.as_str(), making.as_str(), binned.as_str()];let outside = [ ("cinemas.home", json!({})), ("cinemas.row", json!({ "id": "films" })), ("cinemas.row", json!({ "id": "recent" })), ("cinemas.row", json!({ "id": "carry_on" })), ("cinemas.row", json!({ "id": format!("group:{shelf}") })), ("cinemas.search", json!({ "q": "ferry" })), ("cinemas.search", json!({ "q": "edit" })), ("cinemas.search", json!({ "q": "reeds" })), ("cinemas.groups", json!({})), ("cinemas.title", json!({ "table": "film", "id": open })), ("cinemas.onPhone", json!({})), ("cinemas.preparing", json!({ "table": "film", "id": making })), ("cinemas.you", json!({})), ("cinemas.bin", json!({})), ("groups.list", json!({ "table": "film" })), ("groups.list", json!({})), ("films.keepPlan", json!({ "everything": true })), ("cinemas.season", json!({ "id": season })), ("records.list", json!({ "table": "film" })), ("records.list", json!({ "table": "film_episode" })), ("records.list", json!({ "table": "record_group" })), ("records.search", json!({ "table": "film", "query": "edit" })), ("films.onPhone", json!({})), ];// Keep everything is on, so its plan names what it would fetch. ask(&handle, "films.keepEverything", json!({ "on": true }));let plan = ask(&handle, "films.keepPlan", json!({ "everything": true })); assert!(plan.to_string().contains("Night Ferry"), "the plan names the open film with a file: {plan}");for (method, request) in &outside {let answer = crate::methods::dispatch(&handle, method, request).unwrap_or(Value::Null);letmut ids = Vec::new(); ids_in(&answer, &mut ids);for hidden in hidden_ids { assert!(!ids.iter().any(|id| id == hidden), "{method} {request} names a hidden id {hidden}: {answer}"); } assert!(!answer.to_string().contains("My edit videos"), "{method} names the hidden category: {answer}"); assert!(!answer.to_string().contains("Edit Reel"), "{method} names a hidden title: {answer}"); }let lists = ask(&handle, "groups.list", json!({ "table": "film" })); assert_eq!(lists["groups"][0]["count"], 1, "Ferries counts its open title alone: {lists}");// A hidden category is not deleted from under its titles; he stops hiding it first.let refused = crate::methods::dispatch(&handle, "groups.delete", &json!({ "id": edits })).expect_err("refused"); assert_eq!(refused.code, "hidden_category");let refused = crate::methods::dispatch(&handle, "records.delete", &json!({ "table": "record_group", "id": edits })).expect_err("refused"); assert_eq!(refused.code, "hidden_category", "nor by the records' own delete"); assert!(crate::methods::dispatch(&handle, "records.get", &json!({ "table": "film", "id": edit })).is_err(), "a hidden title by its id is not found"); assert_eq!(ask(&handle, "films.onPhone", json!({}))["films"], 0, "the hidden kept film is not counted");// Nothing opens Hidden but the core's unlock: no caller's word. assert_eq!(crate::methods::dispatch(&handle, "cinemas.search", &json!({ "q": "ferry", "hidden": true })).expect_err("locked").code, "locked"); assert_eq!(crate::methods::dispatch(&handle, "cinemas.groups", &json!({ "hidden": true })).expect_err("locked").code, "locked"); assert_eq!(ask(&handle, "cinemas.hidden", json!({ "unlocked": true }))["locked"], true, "the caller's unlocked is not the unlock"); assert!(crate::methods::dispatch(&handle, "cinemas.hide", &json!({ "id": edits, "hidden": false })).is_err(), "Stop hiding is done inside");// A hidden film plays from inside Hidden only: by its id outside it is not found, and `hidden: true` is refused// while Hidden is shut (CINEMAS Android, the walk of 26 Nov 2026).let play = |hidden: bool| crate::methods::dispatch(&handle, "shell.player", &json!({ "op": "play", "table": "film", "id": both, "hidden": hidden }));let refused = play(false).expect_err("not found"); assert_eq!(refused.code, "not_found", "{}", refused.message); assert_eq!(play(true).expect_err("locked").code, "locked"); ask(&handle, "cinemas.unlock", json!({}));let played = play(true).expect("plays inside Hidden"); assert_eq!(played.pointer("/now/id").and_then(Value::as_str), Some(both.as_str()), "{played}");// Hidden open on this copy: it plays without the shell's hint too (core 2, the coordinator's review). assert!(play(false).is_ok(), "Hidden open: a hidden title plays with or without hidden: true");crate::methods::dispatch(&handle, "shell.player", &json!({ "op": "clear" })).ok();// The unlock is this account's: another copy (another account) holds none.let (_other_dir, other) = cinemas(); assert_eq!(crate::methods::dispatch(&other, "cinemas.search", &json!({ "q": "x", "hidden": true })).expect_err("locked").code, "locked");// In one hidden and one open category: hidden. The open category's row holds only Night Ferry.let home = ask(&handle, "cinemas.home", json!({})); assert_eq!(titles(row(&home, &format!("group:{shelf}")).unwrap()), ["Night Ferry"]); assert!(home["featured"]["item"]["id"] != edit.as_str(), "a hidden title is never featured");// A hidden title's page is not there outside, and a hidden category's row is refused. assert!(crate::methods::dispatch(&handle, "cinemas.title", &json!({ "table": "film", "id": edit })).is_err());// A row it does not hold answers empty, as any unknown row does: no title, no name.let shut = ask(&handle, "cinemas.row", json!({ "id": format!("group:{edits}") })); assert_eq!((shut["items"].clone(), shut["title"].clone()), (json!([]), json!("")), "{shut}");// Inside Hidden the category's row opens.let open_inside = ask(&handle, "cinemas.row", json!({ "id": format!("group:{edits}"), "hidden": true })); assert_eq!(open_inside["title"], "My edit videos"); assert_eq!(open_inside["count"], 5, "{open_inside}");// Locked, the hidden place says nothing.// Inside: Carry on (the hidden film and the hidden series' episode), then the hidden category.let inside = ask(&handle, "cinemas.hidden", json!({})); assert_eq!(inside["locked"], false);// Its preparing page opens inside. assert!(crate::methods::dispatch(&handle, "cinemas.preparing", &json!({ "table": "film", "id": making })).is_ok()); assert!(crate::methods::dispatch(&handle, "cinemas.season", &json!({ "id": season, "hidden": true })).is_ok(), "a hidden series' season opens inside");let rows: Vec<&str> = inside["rows"].as_array().unwrap().iter().map(|r| r["id"].as_str().unwrap()).collect();// Then the Bin inside Hidden (CORE 4, M2): "Edit Reel Binned" waits there, counted. assert_eq!(rows, ["carry_on".to_string(), format!("group:{edits}"), "bin".to_string()]); assert_eq!(inside["rows"][2]["count"], 1, "{inside}");let carrying: Vec<String> = titles(&inside["rows"][0]); assert!(carrying.contains(&"Edit Reel Four".to_string()), "{inside}"); assert_eq!(inside["rows"][1]["title"], "My edit videos");let found = ask(&handle, "cinemas.search", json!({ "q": "ferry", "hidden": true }));let names: Vec<&str> = found["items"].as_array().unwrap().iter().map(|i| i["title"].as_str().unwrap()).collect(); assert_eq!(names, ["Ferry Cut"], "inside Hidden, search finds the hidden titles alone");let page = ask(&handle, "cinemas.title", json!({ "table": "film", "id": both, "hidden": true }));let ticked: Vec<&str> = page["groups"].as_array().unwrap().iter().filter(|g| g["in"] == true).map(|g| g["name"].as_str().unwrap()).collect(); assert_eq!(ticked.len(), 2, "inside, its page ticks both categories: {ticked:?}");let picker = ask(&handle, "cinemas.groups", json!({ "hidden": true })); assert_eq!(picker["groups"][0]["name"], "My edit videos"); assert_eq!(picker["groups"][0]["hidden"], true);// Stop hiding: back everywhere. ask(&handle, "cinemas.hide", json!({ "id": edits, "hidden": false }));let home = ask(&handle, "cinemas.home", json!({}));letmut ids = Vec::new(); ids_in(&home, &mut ids); assert!(ids.contains(&edit) && ids.contains(&series), "{home}"); assert!(home.to_string().contains("My edit videos")); assert!(ask(&handle, "cinemas.bin", json!({})).to_string().contains("Edit Reel Binned"), "back in the Bin too"); assert!(ask(&handle, "cinemas.onPhone", json!({})).to_string().contains("Edit Reel Kept"), "and On this phone");// Locked again, nothing hidden opens. ask(&handle, "cinemas.hide", json!({ "id": edits, "hidden": true })); ask(&handle, "cinemas.lock", json!({})); assert_eq!(ask(&handle, "cinemas.hidden", json!({}))["locked"], true);// A kind is not a category: refused. assert!(crate::methods::dispatch(&handle, "cinemas.hide", &json!({ "id": "films", "hidden": true })).is_err());}// RULE (HIDDEN, third review, findings 1 to 4, 6, 8, 9): Hide names only an open category and hands back an undo only// when it changed something, and that undo opens nothing else; a season, a play, a list member, a download or a file// that names a hidden title is not found by its id nor listed; an episode that names only its season is hidden with// its series; the unlock lasts two minutes from the phone's lock and no read renews it; the Bin's Empty, restore and// subtitles leave a hidden title alone outside Hidden.#[test]fn nothing_naming_a_hidden_title_opens_by_its_id() {let (_dir, handle) = cinemas();let reel = film(&handle, "Hush Reel", json!({}));let other = film(&handle, "Open Reel", json!({}));let series = made(&handle, "film", json!({ "title": "Hush Series", "kind": "series", "status": "want_to_watch" }));let season = made(&handle, "film_season", json!({ "film": series, "number": 1, "title": "Season 1" }));// An episode that names only its season.let lone = made(&handle, "film_episode", json!({ "season": season, "number": 2, "title": "Hush Lone" }));let play = made(&handle, "watch", json!({ "film": reel, "started_at": "2026-11-26T10:00:00Z", "seconds": 60, "finished": false }));let new_group = |name: &str, records: Vec<&String>| {let g = ask(&handle, "groups.create", json!({ "table": "film", "name": name, "records": records })); g.pointer("/group/id").or_else(|| g.get("id")).and_then(Value::as_str).expect("a group id").to_string() };let hush = new_group("Hush", vec![&reel, &series]);let open = new_group("Open", vec![&other]);let hid = ask(&handle, "cinemas.hide", json!({ "id": hush, "hidden": true }));// Finding 9: the undo opens only its own category.let token = hid["undo"]["args"]["undo"].as_str().unwrap().to_string(); ask(&handle, "cinemas.hide", json!({ "id": open, "hidden": true })); assert!(crate::methods::dispatch(&handle, "cinemas.hide", &json!({ "id": open, "hidden": false, "undo": token })).is_err(), "Hush's undo does not open Open");// Finding 1: a Hide of one already hidden, outside Hidden, is not found and hands back nothing to undo.let again = crate::methods::dispatch(&handle, "cinemas.hide", &json!({ "id": hush, "hidden": true })).expect_err("not found"); assert_eq!(again.code, "not_found"); assert!(!again.message.contains("Hush"));// Findings 2 to 4: by id, and in every list.// (Downloads, which this kit does not hold, are proven on Comms: chat_downloads_tests.)for (table, id) in [("film_season", &season), ("watch", &play), ("film_episode", &lone), ("film", &reel)] { assert!(crate::methods::dispatch(&handle, "records.get", &json!({ "table": table, "id": id })).is_err(), "{table} by its id names a hidden title");// A table no tool draws is refused outright: that names nothing either.let listed = crate::methods::dispatch(&handle, "records.list", &json!({ "table": table })).unwrap_or(Value::Null); assert!(!listed.to_string().contains(id.as_str()), "{table} lists a hidden row: {listed}"); assert!(!listed.to_string().contains("Hush") && !listed.to_string().contains("hush-reel"), "{table} names it: {listed}"); }let members = crate::methods::dispatch(&handle, "records.list", &json!({ "table": "group_member" })).unwrap_or(Value::Null); assert!(!members.to_string().contains(&hush) && !members.to_string().contains(&reel), "a list member names it: {members}");// The Bin: Empty leaves a hidden title; restore and subtitles by its id are refused.// Outside Hidden it cannot be binned by its id (review 4, M3); inside, it can. assert_eq!(crate::methods::dispatch(&handle, "records.delete", &json!({ "table": "film", "id": reel })).expect_err("not found").code, "not_found"); ask(&handle, "cinemas.unlock", json!({})); ask(&handle, "records.delete", json!({ "table": "film", "id": reel })); ask(&handle, "cinemas.lock", json!({})); ask(&handle, "cinemas.erase", json!({})); assert_eq!(crate::methods::dispatch(&handle, "cinemas.restore", &json!({ "id": reel })).expect_err("locked").code, "locked"); assert_eq!(crate::methods::dispatch(&handle, "cinemas.subtitles", &json!({ "table": "film", "id": reel })).expect_err("locked").code, "locked"); assert_eq!(crate::methods::dispatch(&handle, "cinemas.erase", &json!({ "id": reel })).expect_err("locked").code, "locked");// Finding 6: two minutes from the unlock, and no read renews it. ask(&handle, "cinemas.unlock", json!({}));crate::phone::cinemas_home::age_unlock(&handle.client(), std::time::Duration::from_secs(90)); ask(&handle, "cinemas.row", json!({ "id": format!("group:{hush}"), "hidden": true }));crate::phone::cinemas_home::age_unlock(&handle.client(), std::time::Duration::from_secs(40)); assert_eq!(crate::methods::dispatch(&handle, "cinemas.row", &json!({ "id": format!("group:{hush}"), "hidden": true })).expect_err("locked").code, "locked", "the read at 90 s did not renew it");// Inside, the binned hidden title is still there to restore: Empty outside left it. ask(&handle, "cinemas.unlock", json!({})); ask(&handle, "cinemas.restore", json!({ "id": reel })); ask(&handle, "cinemas.lock", json!({}));}fn group_of(answer: &Value) -> String { answer.pointer("/group/id").or_else(|| answer.get("id")).and_then(Value::as_str).expect("a group id").to_string()}// RULE (HIDE FROM THE SCREEN, owner 27 Nov 2026): what is hidden is worked out at read from the categories' flag// alone, never copied onto a row: a hidden category hides its titles and everything under them, an episode added// later (the Mac's importer) included, from the first read. A search across every table and a change by id leave a// hidden title out. Stop hiding shows it all again, with nothing left to clear.#[test]fn a_hidden_category_hides_down_the_chain_at_read() {let (_dir, handle) = cinemas();let series = made(&handle, "film", json!({ "title": "Quiet Series", "kind": "series", "status": "want_to_watch" }));let season = made(&handle, "film_season", json!({ "film": series, "number": 1, "title": "Season 1" }));let open = film(&handle, "Loud Reel", json!({}));let group = group_of(&ask(&handle, "groups.create", json!({ "table": "film", "name": "Quiet", "records": [series] }))); ask(&handle, "cinemas.hide", json!({ "id": group, "hidden": true }));// An episode added after the Hide, naming only the series' season.let new = made(&handle, "film_episode", json!({ "season": season, "number": 2, "title": "Quiet Two" }));for (table, id) in [("film", &series), ("film_season", &season), ("film_episode", &new)] { assert!(crate::methods::dispatch(&handle, "records.get", &json!({ "table": table, "id": id })).is_err(), "{table} under a hidden title is hidden"); } assert!(crate::methods::dispatch(&handle, "records.get", &json!({ "table": "film", "id": open })).is_ok(), "a title in no hidden category is not");let listed = ask(&handle, "records.list", json!({ "table": "film_episode" })); assert!(!listed.to_string().contains("Quiet"), "{listed}"); assert_eq!(crate::methods::dispatch(&handle, "records.update", &json!({ "table": "film_episode", "id": new, "data": { "title": "Renamed" } })).expect_err("not found").code, "not_found");let across = crate::methods::dispatch(&handle, "records.search", &json!({ "query": "Quiet" })).unwrap_or(Value::Null); assert!(!across.to_string().contains("Quiet"), "{across}"); ask(&handle, "cinemas.unlock", json!({})); ask(&handle, "cinemas.hide", json!({ "id": group, "hidden": false })); ask(&handle, "cinemas.lock", json!({}));for (table, id) in [("film", &series), ("film_season", &season), ("film_episode", &new)] { assert!(crate::methods::dispatch(&handle, "records.get", &json!({ "table": table, "id": id })).is_ok(), "{table} open again"); }}// RULE (HIDDEN 6, review 5): a list this copy holds with no version read (pulled before lists were sealed) is found by// the read-only check; one with its version is not.#[test]fn lists_without_a_version_are_found() {let (_dir, handle) = cinemas();let reel = film(&handle, "Versionless Reel", json!({}));let g = ask(&handle, "groups.create", json!({ "table": "film", "name": "Versionless", "records": [reel] }));let group = g.pointer("/group/id").or_else(|| g.get("id")).and_then(Value::as_str).expect("a group id").to_string(); handle .client() .with_writer(|replica| { replica.driver.run("CREATE TABLE IF NOT EXISTS _seal (tbl TEXT NOT NULL, row_id TEXT NOT NULL, sealed INTEGER, dek_enc TEXT, seal_v INTEGER, version INTEGER, PRIMARY KEY (tbl, row_id))", &[]).map_err(|e| e.to_string())?;Ok(()) }) .expect("seal state"); assert_eq!(crate::phone::cinemas_home::lists_without_version(&handle.client()).expect("checked"), 1, "the list with no version"); handle .client() .with_writer(|replica| { replica.driver.run("INSERT INTO _seal (tbl, row_id, sealed, version) VALUES ('record_group', ?, 1, 4)", &[rusqlite::types::Value::Text(group.clone())]).map_err(|e| e.to_string())?;Ok(()) }) .expect("a version"); assert_eq!(crate::phone::cinemas_home::lists_without_version(&handle.client()).expect("checked"), 0);}// RULE (FIRST FILL, CONTRACT-2): the pictures Home draws first, in Home's order: the featured title's backdrop, then// each row's posters, the rows as Home stands them; each key once, at most sixty.#[test]fn homes_first_pictures_come_in_homes_order() {let (_dir, handle) = cinemas();for n in0..40 { film(&handle, &format!("Invented Reel {n:02}"), json!({ "poster": format!("db/photos/poster-{n:02}.jpg"), "backdrop": format!("db/photos/backdrop-{n:02}.jpg"), "added_on": format!("2026-10-{:02}", n % 28 + 1) })); }let home = ask(&handle, "cinemas.home", json!({}));let keys = crate::phone::cinemas_home::first_pictures(&home);// Each as the 256 px thumbnail a tile draws, never the stored picture.let thumb = |key: &str| cotton_core::media::keys::thumb_key_for(key).unwrap_or_else(|| key.to_string());let featured = thumb(home["featured"]["item"]["backdrop"].as_str().expect("a featured backdrop")); assert!(featured.ends_with(".t256.jpg"), "{featured}"); assert_eq!(keys.first(), Some(&featured), "the featured backdrop first");let first_row: Vec<String> = home["rows"][0]["items"].as_array().expect("items").iter().filter_map(|item| item["poster"].as_str()).map(thumb).collect(); assert_eq!(&keys[1..1 + first_row.len()], &first_row[..], "then the first row's posters, in its order");// Low Data Mode never; mobile data only when this phone's films may use it; Wi-Fi yes.let client = handle.client(); assert!(!crate::phone::media_sweep::first_allowed(&client, Some("wifi"), Some(true))); assert!(crate::phone::media_sweep::first_allowed(&client, Some("wifi"), Some(false))); assert!(!crate::phone::media_sweep::first_allowed(&client, Some("cellular"), Some(false)), "films keep to Wi-Fi by default");// A shell that says nothing fetches nothing ahead (HIDDEN 10, L1), even with films allowed mobile data.crate::methods::dispatch(&handle, "films.keeping", &json!({ "cellular": true })).expect("cellular on"); assert!(crate::phone::media_sweep::first_allowed(&client, Some("cellular"), Some(false))); assert!(!crate::phone::media_sweep::first_allowed(&client, None, Some(false)), "no network said"); assert!(!crate::phone::media_sweep::first_allowed(&client, Some("wifi"), None), "Low Data Mode not said"); assert!(!crate::phone::media_sweep::first_allowed(&client, None, None)); assert!(keys.len() <= crate::phone::media_sweep::FIRST_KEYS);let unique: std::collections::BTreeSet<&String> = keys.iter().collect(); assert_eq!(unique.len(), keys.len(), "each once"); assert_eq!(crate::phone::media_sweep::first_chosen(["a".to_string(), " ".to_string(), "a".to_string(), "b".to_string()]), ["a", "b"]); assert_eq!(crate::phone::media_sweep::first_chosen(["db/photos/x.jpg".to_string(), "db/photos/x.t256.jpg".to_string()]), ["db/photos/x.t256.jpg"], "a picture and its thumbnail are one key");}// RULE (WHOLE TITLES ONLY, owner 27 Nov 2026): a season or an episode is hidden exactly when its title is, by a hidden// category holding the title. A leftover `in_hidden` mark on a row (an older build's) hides nothing: it is ignored.#[test]fn a_child_is_hidden_exactly_when_its_title_is() {let (_dir, handle) = cinemas();let series = made(&handle, "film", json!({ "title": "Stray Series", "kind": "series", "status": "watching" }));let season = made(&handle, "film_season", json!({ "film": series, "number": 1, "title": "Season 1" }));let episode = made(&handle, "film_episode", json!({ "season": season, "series": series, "number": 1, "title": "Stray Episode", "minutes": 40 }));let (made_episodes, id) = (cotton_tools::mcp::handlers::tables::made_table("film_episode"), episode.clone()); handle .client() .write_rows("test.mark", &mut |ctx| {letmut patch = Map::new(); patch.insert("in_hidden".into(), json!(true)); cotton_tools::mcp::handlers::common::update_row(ctx, &made_episodes, &id, patch).map_err(|f| f.to_string())?; ctx.commit().map_err(|f| f.to_string())?;Ok(Value::Null) }) .expect("an old mark"); assert!(crate::methods::dispatch(&handle, "records.get", &json!({ "table": "film_episode", "id": episode })).is_ok(), "an old mark hides nothing"); assert!(crate::methods::dispatch(&handle, "cinemas.unhideTitle", &json!({ "id": episode })).is_err(), "no such method any more");let group = group_of(&ask(&handle, "groups.create", json!({ "table": "film", "name": "Strays", "records": [series] }))); ask(&handle, "cinemas.hide", json!({ "id": group, "hidden": true })); assert!(crate::methods::dispatch(&handle, "records.get", &json!({ "table": "film_episode", "id": episode })).is_err(), "the episode hidden with its title"); assert!(crate::methods::dispatch(&handle, "records.get", &json!({ "table": "film_season", "id": season })).is_err(), "the season hidden with its title"); ask(&handle, "cinemas.unlock", json!({}));let place = ask(&handle, "cinemas.hidden", json!({})); assert!(!place.to_string().contains("also_hidden"), "{place}"); ask(&handle, "cinemas.lock", json!({}));}/// The prefixes of the method registry whose every method must be named one by one, as a reader read below or in/// NOT_READERS: his films' own modules and the shared reads that list any table.const FILM_PREFIXES: [&str; 5] = ["cinemas", "films", "records", "groups", "media"];/// Every other module of the method registry, by prefix, with why none of its methods shows a title of his films on/// his screen. A method whose prefix is neither here nor in FILM_PREFIXES, and that is not named one by one, fails/// the test: a new module must say where it stands.const APART: [(&str, &str); 95] = [ ("restore", "putting a database back from its copies: counts and a sentence, never a title"), ("circle", "the people he shares with on Cotton"), ("contacts", "his contacts, their groups and facts"), ("look", "one app's paper, ink and type"), ("passkey", "his passkeys"), ("write", "a write the caller makes; answers what it wrote"), ("chat", "Comms: its chats, mail, calls and files; its downloads list (chat.downloads) is read below"), ("story", "Story: scenes and drafts"), ("mail", "mail accounts and messages"), ("sites", "Sites: pages and books of the web"), ("notes", "Words: notes"), ("repo", "Code: repositories"), ("vault", "the vault's keys"), ("secrets", "Secrets: passwords"), ("data", "the Data app reads the object; it leaves hidden titles out by THE predicate's rule (data_app.rs learn_hidden), tested in data_app_tests"), ("meetings", "Meetings: recordings and notes"), ("shell", "the shell's frame; shell.player, the one that plays films, is read below op by op"), ("calls", "Calling"), ("health", "Health"), ("device", "this device's settings and reports"), ("developer", "developer tools"), ("days", "Days: events"), ("code", "Code's preferences"), ("recovery", "getting back in"), ("sync", "sync's state, counts and stuck changes by kind; no title"), ("personal", "the personal object's account"), ("definitions", "table definitions and boards: columns, not rows"), ("backup", "backups: when and where, no rows"), ("password", "passwords"), ("signin", "signing in"), ("people", "people"), ("databases", "the list of databases"), ("send", "Send's offers and inbox: what friends sent, not yet his (send.inbox is read below)"), ("reader", "Reader: books"), ("music", "Music"), ("ink", "Ink"), ("voice", "voice notes and vocabulary"), ("unlock", "the assistant's unlock windows"), ("tools", "tool definitions"), ("shared", "shared lists of another person"), ("seal", "the seal's keys and status: no rows"), ("keep", "keep rules by table"), ("devices", "his devices"), ("cards", "Days' cards: birthdays, money due"), ("business", "the business apps"), ("assistant", "connected assistants"), ("account", "the account"), ("storage", "Storage: sizes by device and app, no titles"), ("songs", "Music's songs"), ("settings", "settings"), ("books", "Books"), ("terminal", "terminal sessions"), ("message", "messages"), ("diagnostics", "diagnostics: counts and logs by kind"), ("workspace", "workspaces"), ("whatsapp", "WhatsApp"), ("spotify", "Spotify"), ("session", "sessions"), ("package", "packages"), ("money", "Money"), ("google", "Google accounts"), ("domains", "domains"), ("capture", "capture"), ("asks", "asks of you"), ("share", "share links"), ("samples", "samples"), ("reminders", "reminders"), ("pairing", "pairing a device"), ("messages", "messages"), ("members", "members of a shared space"), ("gettingIn", "getting in"), ("filing", "filing"), ("feedback", "feedback"), ("episodes", "podcast episodes"), ("bootstrap", "the first start"), ("usage", "usage counts"), ("routes", "routes"), ("push", "push"), ("project", "projects"), ("phrase", "phrases"), ("page", "pages"), ("object", "the object's state"), ("migrate", "migrations"), ("log", "the log"), ("link", "links"), ("import", "imports"), ("identity", "identity"), ("export", "an export: a file he asks for, never a screen"), ("dictation", "dictation"), ("datadir", "the data folder"), ("count", "word counts"), ("camera", "the camera"), ("build", "the build"), ("read", "the fan's screens, each made of records.* and groups.* answers read below; Find (read.find) is read below"), ("ffi", "the boundary's own calls"),];/// The methods of his films' modules that answer no title of his outside Hidden, each with why.const NOT_READERS: [(&str, &str); 41] = [ ("media.network", "the network the phone is on now (wifi, mobile, constrained); no title"), ("media.uploads", "where each named file is on its way up, by its key; no title"), ("cinemas.shared", "a list someone else shared with him: their titles, never his films"), ("cinemas.shared.leave", "asks to leave a list someone else shared; answers a sentence"), ("records.addToCalendar", "adds one record the caller names to the calendar"), ("records.command", "runs one command on one record the caller names"), ("records.create", "makes a record; answers it"), ("records.delete", "deletes one record the caller names; a hidden one by its id is not found"), ("records.link", "links two records the caller names; a hidden one is not found"), ("records.move", "moves one record the caller names"), ("records.recordAsTransaction", "Money's: makes a transaction from one record"), ("records.reorder", "reorders the records the caller names"), ("records.undo", "undoes the caller's own last change"), ("records.update", "changes one record the caller names; a hidden one by its id is not found"), ("groups.create", "makes a category; answers it"), ("groups.delete", "deletes one category; a hidden one is refused"), ("groups.update", "changes one category the caller names"), ("media.ensure", "fetches one media key the caller names"), ("media.viewed", "notes one media key viewed"), ("media.describe", "describes one picture the caller names"), ("media.share", "shares one media key the caller names"), ("chat.downloads.act", "acts on one download the caller names"), ("chat.downloads.send", "sends one download the caller names"), ("cinemas.unlock", "opens Hidden after the phone's lock; answers whether it is open"), ("cinemas.lock", "shuts Hidden; answers whether it is open"), ("cinemas.kind", "corrects one open title's kind, named by the caller; answers its id and kind"), ("cinemas.toEpisode", "moves one open film under a series, named by the caller"), ("cinemas.hide", "hides or shows one category; answers its own line and undo"), ("cinemas.restore", "puts one binned title back, named by the caller"), ("cinemas.erase", "erases binned titles for good; answers how many"), ("cinemas.setting", "turns one of You's settings"), ("media.stream", "signs one media key the caller names; answers an address"), ("films.here.read", "this phone's state of one key the caller names"), ("films.here.write", "writes this phone's state of one key"), ("films.remove", "removes one kept file from this phone"), ("films.keepEverything", "turns Keep everything on or off"), ("films.capture", "brings in files the phone's picker handed over"), ("films.picked", "reads the picker's answer, files not yet titles"), ("films.subtitleFile", "keeps a subtitle file the phone's picker handed over"), ("films.mark", "writes where a play stands"), ("groups.order", "the same as cinemas.groupsOrder, checked under that name"),];// RULE (HIDE FROM SCREEN 3, coordinator 27 Nov 2026): ONE predicate (`hidden_titles`, worked out at read from the// categories' flag) and every Cinemas reader under it. Each method on the Cinemas lists is either read here, outside// Hidden, with hidden titles of every sort present (a film carried on, kept on this phone, being prepared, binned, a// series with its season and episode) and answers neither their ids nor their names, nor the hidden category's, not// even in a refusal; or named in NOT_READERS with why it answers none. A hidden title played from inside Hidden is// discreet where the phone shows what plays: "Cinemas", no picture, no series, on the player's answer and the remote.#[test]fn every_cinemas_reader_leaves_a_hidden_title_out() {let (_dir, handle) = cinemas();let open = film(&handle, "Open Lantern", json!({ "file": "films/open/master.m3u8", "added_on": "2026-11-20", "position": 600, "position_at": "2026-11-24T20:00:00Z" }));let open_series = made(&handle, "film", json!({ "title": "Open Harbour", "kind": "series", "status": "watching" }));let open_season = made(&handle, "film_season", json!({ "film": open_series, "number": 1, "title": "Season 1" })); made(&handle, "film_episode", json!({ "season": open_season, "series": open_series, "number": 1, "title": "Open Tide", "file": "films/open-tide/master.m3u8" }));let hush = film(&handle, "Hush Lantern", json!({ "file": "films/hush/master.m3u8", "poster": "films/hush/poster.jpg", "added_on": "2026-11-25", "position": 300, "position_at": "2026-11-25T20:00:00Z" }));let series = made(&handle, "film", json!({ "title": "Hush Harbour", "kind": "series", "status": "watching" }));let season = made(&handle, "film_season", json!({ "film": series, "number": 1, "title": "Season 1" }));let episode = made(&handle, "film_episode", json!({ "season": season, "series": series, "number": 1, "title": "Hush Reeds", "file": "films/hush-reeds/master.m3u8", "position": 60, "position_at": "2026-11-25T21:00:00Z" }));let kept = film(&handle, "Hush Kept", json!({ "file": "films/hush-kept/master.m3u8" }));let making = film(&handle, "Hush Making", json!({ "needs_mac": true }));let binned = film(&handle, "Hush Binned", json!({}));crate::phone::films::write(&handle.client(), &json!({ "key": "films/hush-kept/master.m3u8", "state": "kept", "bookmark": "Ym9va21hcms=" })).expect("kept");let group = |name: &str, records: Vec<&String>| group_of(&ask(&handle, "groups.create", json!({ "table": "film", "name": name, "records": records })));let shut = group("Hush Shelf", vec![&hush, &series, &kept, &making, &binned]);let shelf = group("Lanterns", vec![&open, &hush]); ask(&handle, "records.delete", json!({ "table": "film", "id": binned })); ask(&handle, "films.keepEverything", json!({ "on": true })); ask(&handle, "cinemas.hide", json!({ "id": shut, "hidden": true }));let hidden_ids = [hush.as_str(), series.as_str(), season.as_str(), episode.as_str(), kept.as_str(), making.as_str(), binned.as_str(), shut.as_str()];let readers: Vec<(&str, Value)> = vec![ ("cinemas.home", json!({})), ("cinemas.row", json!({ "id": "carry_on" })), ("cinemas.row", json!({ "id": "recent" })), ("cinemas.row", json!({ "id": "films" })), ("cinemas.row", json!({ "id": "series" })), ("cinemas.row", json!({ "id": "on_phone" })), ("cinemas.row", json!({ "id": "getting_ready" })), ("cinemas.row", json!({ "id": format!("group:{shelf}") })), ("cinemas.row", json!({ "id": format!("group:{shut}") })), ("cinemas.season", json!({ "id": open_season })), ("cinemas.season", json!({ "id": season })), ("cinemas.search", json!({ "q": "hush" })), ("cinemas.search", json!({ "q": "lantern" })), ("cinemas.search", json!({ "q": "reeds" })), ("cinemas.groups", json!({})), ("cinemas.groupsOrder", json!({ "order": [shelf] })), ("cinemas.title", json!({ "table": "film", "id": open })), ("cinemas.title", json!({ "table": "film", "id": hush })), ("cinemas.hidden", json!({})), ("cinemas.subtitles", json!({ "table": "film", "id": hush })), ("cinemas.onPhone", json!({})), ("cinemas.preparing", json!({ "table": "film", "id": making })), ("cinemas.remote", json!({ "table": "film", "id": hush, "at_s": 30 })), ("cinemas.remote", json!({ "table": "film_episode", "id": episode, "at_s": 30 })), ("cinemas.bin", json!({})), ("cinemas.you", json!({})), ("films.keeping", json!({})), ("films.onPhone", json!({})), ("films.keepPlan", json!({ "everything": true })), ("shell.player", json!({})),// The shared reads of any table, his films' among them. ("records.list", json!({ "table": "film" })), ("records.list", json!({ "table": "film_episode" })), ("records.list", json!({ "table": "film_season" })), ("records.list", json!({ "table": "record_group" })), ("records.list", json!({ "table": "bin" })), ("records.page", json!({ "table": "film" })), ("records.search", json!({ "table": "film", "query": "hush" })), ("records.search", json!({ "query": "hush" })), ("records.get", json!({ "table": "film", "id": hush })), ("records.get", json!({ "table": "film_season", "id": season })), ("records.head", json!({ "table": "film", "id": hush })), ("records.live", json!({ "table": "film" })), ("records.resolve", json!({ "table": "film", "id": hush })), ("records.spoken", json!({ "table": "film", "id": hush })), ("records.summarize", json!({ "table": "film" })), ("records.summarize", json!({ "table": "film_episode" })), ("groups.list", json!({ "table": "film" })), ("groups.list", json!({})), ("chat.downloads", json!({})), ("send.inbox", json!({})), ("read.find", json!({ "q": "hush" })), ];// Every method of the registry (every module) is classified: read here, named in NOT_READERS, or of a module// APART says shows none of his films. A module of his films (FILM_PREFIXES) is named method by method.let read: std::collections::BTreeSet<&str> = readers.iter().map(|(method, _)| *method).collect();let exempt: std::collections::BTreeSet<&str> = NOT_READERS.iter().map(|(method, _)| *method).collect();letmut registry: std::collections::BTreeSet<String> = crate::methods::ALL_METHODS.iter().map(|m| m.to_string()).collect(); registry.extend(crate::phone::reads::method_names());let (mut unnamed, mut new_modules) = (Vec::new(), std::collections::BTreeSet::new());for method in ®istry {let method = method.as_str();let prefix = method.split('.').next().unwrap_or(method); assert!(!(read.contains(method) && exempt.contains(method)), "{method} is both read and named in NOT_READERS");if read.contains(method) || exempt.contains(method) {continue; }if FILM_PREFIXES.contains(&prefix) { unnamed.push(method); } elseif !APART.iter().any(|(apart, _)| *apart == prefix) { new_modules.insert(prefix); } } assert!(unnamed.is_empty(), "methods of his films' modules: read each in this test, or name it in NOT_READERS with why it answers no title: {unnamed:?}"); assert!(new_modules.is_empty(), "new modules: say in APART why each shows none of his films, or read its methods here: {new_modules:?}");for method in read.iter().chain(exempt.iter()) { assert!(registry.contains(*method), "{method} is no method any more: take it out of this test"); }let check = |method: &str, request: &Value| {let said = matchcrate::methods::dispatch(&handle, method, request) {Ok(answer) => answer,Err(refusal) => json!({ "refused": refusal.code, "message": refusal.message }), };letmut ids = Vec::new(); ids_in(&said, &mut ids);let text = said.to_string();// An id the caller named may come back as asked (an unknown row answers empty under its own id): it says nothing.for hidden in hidden_ids.iter().copied().filter(|hidden| !request.to_string().contains(hidden)) { assert!(!ids.iter().any(|id| id == hidden) && !text.contains(hidden), "{method} {request} names a hidden id {hidden}: {said}"); } assert!(!text.contains("Hush"), "{method} {request} names a hidden title or category: {said}"); said };for (method, request) in &readers { check(method, request); }// Reordered outside Hidden, where only the open categories are seen: the hidden one keeps its place (first, as it// was made first); the open ones take the others in the order sent.let embers = group("Embers", vec![&open]);let answered = check("cinemas.groupsOrder", &json!({ "order": [embers, shelf] })); assert_eq!(answered["groups"], json!([embers, shelf]), "{answered}");letmut stored = Vec::new(); handle .client() .read_rows("test.order", &mut |ctx| { stored = cotton_tools::mcp::handlers::tables::groups::list_order(ctx, "film").map_err(|f| f.to_string())?;Ok(Value::Null) }) .expect("the order"); assert_eq!(stored, vec![shut.clone(), embers.clone(), shelf.clone()], "the hidden category keeps its place");// The open titles are still there: the readers are not simply empty. assert!(check("cinemas.home", &json!({})).to_string().contains("Open Lantern")); assert!(check("films.keepPlan", &json!({ "everything": true })).to_string().contains("Open Lantern"));// Played while Hidden is open on this copy (the core's own unlock), with no hint from the shell; then Hidden shut:// what plays is discreet everywhere the phone shows it, every op of the player that answers what plays.let shut_play = crate::methods::dispatch(&handle, "shell.player", &json!({ "op": "play", "table": "film", "id": hush })); assert_eq!(shut_play.expect_err("Hidden shut: not found").code, "not_found"); ask(&handle, "cinemas.unlock", json!({}));let played = ask(&handle, "shell.player", json!({ "op": "play", "table": "film", "id": hush })); assert_eq!(played.pointer("/now/title").and_then(Value::as_str), Some("Cinemas"), "{played}"); assert_eq!(played.pointer("/now/discreet"), Some(&Value::Bool(true)), "{played}"); assert!(played["now"].get("cover").is_none() && played["now"].get("caption").is_none(), "{played}"); ask(&handle, "cinemas.lock", json!({}));// The player's answer carries the id of what plays (its own handle on it, for where it stands), never a name.for op in [json!({}), json!({ "op": "cast" }), json!({ "op": "route", "to": "failed" }), json!({ "op": "refresh_link" }), json!({ "op": "seek", "at_s": 40 }), json!({ "op": "rate", "rate": 1.0 })] {let said = matchcrate::methods::dispatch(&handle, "shell.player", &op) {Ok(answer) => answer,Err(refusal) => json!({ "refused": refusal.code, "message": refusal.message }), };let text = said.to_string(); assert!(!text.contains("Hush") && hidden_ids.iter().filter(|id| **id != hush.as_str()).all(|id| !text.contains(id)), "shell.player {op} names a hidden title: {said}"); }let now = ask(&handle, "shell.player", json!({})); assert!(!now.to_string().contains("Hush"), "{now}");let remote = check("cinemas.remote", &json!({ "table": "film", "id": hush, "at_s": 30 })); assert_eq!(remote["title"], "Cinemas", "{remote}");let episode_remote = check("cinemas.remote", &json!({ "table": "film_episode", "id": episode, "at_s": 30 })); assert_eq!((episode_remote["title"].as_str(), &episode_remote["caption"]), (Some("Cinemas"), &Value::Null), "{episode_remote}");crate::methods::dispatch(&handle, "shell.player", &json!({ "op": "clear" })).ok();// An open title plays named, as ever.let open_play = ask(&handle, "shell.player", json!({ "op": "play", "table": "film", "id": open })); assert_eq!(open_play.pointer("/now/title").and_then(Value::as_str), Some("Open Lantern"), "{open_play}"); assert!(open_play["now"].get("discreet").is_none(), "{open_play}");crate::methods::dispatch(&handle, "shell.player", &json!({ "op": "clear" })).ok();// Hidden mid-film: an open title plays named; its category hidden while it plays (here, or synced from another// phone), the next answer is discreet, the cast and the route too; shown again, named again.let quiet = film(&handle, "Quiet Lantern", json!({ "file": "films/quiet/master.m3u8", "poster": "films/quiet/poster.jpg" }));let quiet_shelf = group("Quiet Shelf", vec![&quiet]);let playing = ask(&handle, "shell.player", json!({ "op": "play", "table": "film", "id": quiet })); assert_eq!(playing.pointer("/now/title").and_then(Value::as_str), Some("Quiet Lantern"), "{playing}"); ask(&handle, "cinemas.hide", json!({ "id": quiet_shelf, "hidden": true }));for op in [json!({}), json!({ "op": "cast" }), json!({ "op": "route", "to": "failed" }), json!({ "op": "seek", "at_s": 10 })] {let said = matchcrate::methods::dispatch(&handle, "shell.player", &op) {Ok(answer) => answer,Err(refusal) => json!({ "refused": refusal.code, "message": refusal.message }), }; assert!(!said.to_string().contains("Quiet"), "hidden mid-film, {op} still names it: {said}"); } assert_eq!(ask(&handle, "shell.player", json!({})).pointer("/now/title").and_then(Value::as_str), Some("Cinemas")); ask(&handle, "cinemas.unlock", json!({})); ask(&handle, "cinemas.hide", json!({ "id": quiet_shelf, "hidden": false })); ask(&handle, "cinemas.lock", json!({})); assert_eq!(ask(&handle, "shell.player", json!({})).pointer("/now/title").and_then(Value::as_str), Some("Quiet Lantern"), "shown again, named again");crate::methods::dispatch(&handle, "shell.player", &json!({ "op": "clear" })).ok();// A hidden category in the Bin still hides its titles: binned by a write that is not his phone's own delete (an// assistant's, the Mac's, another build's, an undo of its making). Only erased for good, or shown, does it stop.let (groups_table, shut_id) = (cotton_tools::mcp::handlers::tables::groups::GROUPS.to_string(), shut.clone()); handle .client() .write_rows("test.bin_category", &mut |ctx| {letmut patch = Map::new(); patch.insert("deleted_at".into(), json!("2026-11-27T10:00:00Z")); cotton_tools::mcp::handlers::common::update_row(ctx, &groups_table, &shut_id, patch).map_err(|f| f.to_string())?; ctx.commit().map_err(|f| f.to_string())?;Ok(Value::Null) }) .expect("the category binned");for (method, request) in [("cinemas.home", json!({})), ("cinemas.search", json!({ "q": "hush" })), ("records.list", json!({ "table": "film" })), ("records.list", json!({ "table": "bin" })), ("films.keepPlan", json!({ "everything": true }))] { check(method, &request); }// Core 3, M1: the binned hidden category is not stuck. Outside Hidden it is not restored by its id; inside, Hidden// lists it, said to be in the Bin, with Restore, and its titles open there; Empty from the Bin outside Hidden, even// while Hidden is open, leaves its binned title (that Bin never showed it), which the Bin inside Hidden lists. assert_eq!(crate::methods::dispatch(&handle, "cinemas.restore", &json!({ "id": shut })).expect_err("locked").code, "locked"); ask(&handle, "cinemas.unlock", json!({}));let place = ask(&handle, "cinemas.hidden", json!({}));let row = place["rows"].as_array().unwrap().iter().find(|row| row["group"] == shut.as_str()).cloned().unwrap_or_else(|| panic!("the binned hidden category is listed inside Hidden: {place}")); assert_eq!((row["binned"].as_str(), row.pointer("/restore/method").and_then(Value::as_str)), (Some("In the Bin"), Some("cinemas.restore")), "{row}");let inside = ask(&handle, "cinemas.row", json!({ "id": format!("group:{shut}"), "hidden": true })); assert!(inside.to_string().contains("Hush Lantern"), "its titles open inside Hidden: {inside}"); ask(&handle, "cinemas.erase", json!({})); assert!(ask(&handle, "cinemas.bin", json!({ "hidden": true })).to_string().contains("Hush Binned"), "Empty outside Hidden left the hidden binned title"); assert!(!ask(&handle, "cinemas.bin", json!({})).to_string().contains("Hush"), "the Bin outside Hidden names none");// Restore: the category is live again, still hidden. ask(&handle, "cinemas.restore", json!({ "id": shut }));let place = ask(&handle, "cinemas.hidden", json!({}));let row = place["rows"].as_array().unwrap().iter().find(|row| row["group"] == shut.as_str()).cloned().expect("still hidden"); assert!(row.get("binned").is_none(), "{row}"); ask(&handle, "cinemas.lock", json!({})); check("cinemas.home", &json!({}));// Show works on a binned hidden category too: in the Bin again, shown, its titles are back on Home.let (groups_table, shut_id) = (cotton_tools::mcp::handlers::tables::groups::GROUPS.to_string(), shut.clone()); handle .client() .write_rows("test.bin_category_again", &mut |ctx| {letmut patch = Map::new(); patch.insert("deleted_at".into(), json!("2026-11-27T11:00:00Z")); cotton_tools::mcp::handlers::common::update_row(ctx, &groups_table, &shut_id, patch).map_err(|f| f.to_string())?; ctx.commit().map_err(|f| f.to_string())?;Ok(Value::Null) }) .expect("binned again"); ask(&handle, "cinemas.unlock", json!({})); ask(&handle, "cinemas.hide", json!({ "id": shut, "hidden": false })); ask(&handle, "cinemas.lock", json!({})); assert!(ask(&handle, "cinemas.home", json!({})).to_string().contains("Hush Lantern"), "shown, its titles are back");}// RULE (CORE 4, review 4 M1/M2/L1 and the Android additions): hidden rows are left out where rows are READ. Find makes// no hit, snippet or total of a hidden title's plays; a list of plays counts and pages none; the shared Bin counts,// lists and erases none (by any road, records.command's Delete forever included); the Bin inside Hidden lists them,// counted, with Restore and Delete forever.#[test]fn hidden_rows_are_left_out_where_they_are_read() {let (_dir, handle) = cinemas();let shut_film = film(&handle, "Edit Reel Four", json!({ "file": "films/edit/master.m3u8" }));let open_film = film(&handle, "Night Ferry", json!({ "file": "films/open/master.m3u8" }));let binned_hidden = film(&handle, "Edit Reel Binned", json!({}));let binned_open = film(&handle, "Paper Moons", json!({}));letmut plays = Vec::new();for (n, of) in [&shut_film, &shut_film, &shut_film, &open_film, &open_film].into_iter().enumerate() { plays.push(made(&handle, "watch", json!({ "film": of, "started_at": format!("2026-11-2{n}T20:00:00Z"), "seconds": 600, "device": "Synthetic Telly" }))); }let g = ask(&handle, "groups.create", json!({ "table": "film", "name": "My edit videos", "records": [&shut_film, &binned_hidden] }));let edits = g.pointer("/group/id").or_else(|| g.get("id")).and_then(Value::as_str).expect("a group id").to_string(); ask(&handle, "records.delete", json!({ "table": "film", "id": binned_hidden })); ask(&handle, "records.delete", json!({ "table": "film", "id": binned_open })); ask(&handle, "cinemas.hide", json!({ "id": edits, "hidden": true }));let hidden_ids: Vec<&String> = vec![&shut_film, &binned_hidden, &plays[0], &plays[1], &plays[2]];let names_none = |what: &str, answer: &Value| {let text = answer.to_string(); assert!(!text.contains("Edit Reel"), "{what} names a hidden title: {text}");for id in &hidden_ids { assert!(!text.contains(id.as_str()), "{what} carries a hidden row {id}: {text}"); } };// Find: the plays of the hidden film make no hit, and every section's total is its hits (the whole set).for query in ["Telly", "Edit", "Ferry"] {let found = ask(&handle, "read.find", json!({ "query": query })); names_none(&format!("Find {query}"), &found);for (table, section) in found["defined"].as_object().into_iter().flatten() {let hits = section["hits"].as_array().map_or(0, Vec::len) as u64; assert_eq!(section["total"].as_u64(), Some(hits), "Find {query}: {table}'s total counts what it lists: {section}"); }if query == "Telly" { assert_eq!(found.pointer("/defined/watch/total").and_then(Value::as_u64), Some(2), "the open film's two plays: {found}"); } }// One table's section paged alone (an expanded Watches).let watches = ask(&handle, "read.find", json!({ "query": "Telly", "table": "watch", "limit": 1 })); names_none("Find's Watches page", &watches); assert_eq!(watches.pointer("/defined/watch/total").and_then(Value::as_u64), Some(2), "{watches}");// CORE 5 M1: the search across every table (records.search, no table) counts and limits without them too.for query in ["Telly", "Edit"] {let found = ask(&handle, "records.search", json!({ "query": query })); names_none(&format!("records.search {query}"), &found);for (table, total) in found["totals"].as_object().into_iter().flatten() {let listed = found["records"].as_array().into_iter().flatten().filter(|hit| hit["table"] == table.as_str()).count() as u64; assert_eq!(total.as_u64(), Some(listed), "records.search {query}: {table}'s total counts what it lists: {found}"); }if query == "Telly" { assert_eq!(found.pointer("/totals/watch").and_then(Value::as_u64), Some(2), "{found}"); } }// CORE 5 L3: a Home figure over his films' tables counts no hidden title or play.let counted = handle .client() .read_rows("test.figure", &mut |ctx| {letmut out = Map::new();for table in ["watch", "film"] {let definition = cotton_tools::mcp::handlers::tables::definition(ctx, table).map_err(|f| f.to_string())?;let summary: cotton_core::definitions::FigureSummary = serde_json::from_value(json!({ "table": table, "op": "count" })).map_err(|e| e.to_string())?;let total = cotton_tools::mcp::handlers::tables::figure_total(&ctx.read, &definition, &summary, chrono::Utc::now().date_naive()).map_err(|f| f.to_string())?; out.insert(table.to_string(), json!(total.total)); }Ok(Value::Object(out)) }) .expect("figures"); assert_eq!((counted["watch"].as_i64(), counted["film"].as_i64()), (Some(2), Some(1)), "the open film and its two plays: {counted}");// A list of plays: its total and its pages are made without the hidden ones.let listed = ask(&handle, "records.list", json!({ "table": "watch" })); names_none("records.list watch", &listed); assert_eq!((listed["records"].as_array().map(Vec::len), listed["total"].as_u64()), (Some(2), Some(2)), "{listed}");let first = ask(&handle, "records.list", json!({ "table": "watch", "limit": 1 })); assert_eq!((first["records"].as_array().map(Vec::len), first["total"].as_u64()), (Some(1), Some(2)), "{first}");let films = ask(&handle, "records.list", json!({ "table": "film" })); names_none("records.list film", &films); assert_eq!(films["total"].as_u64(), films["records"].as_array().map(|r| r.len() as u64), "{films}");// The shared Bin: counted after the hidden are left out, everywhere it is counted.let bin = ask(&handle, "records.list", json!({ "table": "bin" })); names_none("the shared Bin", &bin);let in_bin = bin["records"].as_array().map_or(0, Vec::len) as u64; assert!(bin.to_string().contains("Paper Moons"), "{bin}"); assert_eq!(bin["total"].as_u64(), Some(in_bin), "the Bin's total is what it lists: {bin}");let counted = ask(&handle, "records.list", json!({ "table": "bin", "count_only": true })); assert_eq!(counted["total"].as_u64(), Some(in_bin), "{counted}");let films_bin = ask(&handle, "records.list", json!({ "table": "bin", "where": { "table": "film" } })); assert_eq!((films_bin["total"].as_u64(), films_bin["records"].as_array().map(Vec::len)), (Some(1), Some(1)), "a table's Deleted · n: {films_bin}");// shell.list's Bin: its rows, its count and "Empty the bin? … all N" are made of the gated rows.let shell = ask(&handle, "shell.list", json!({ "table": "bin" })); names_none("shell.list bin", &shell); assert!(shell.to_string().contains("Paper Moons"), "{shell}");ifletSome(count) = shell.get("count").and_then(Value::as_u64) { assert_eq!(count, in_bin, "the shell's Bin counts what it lists: {shell}"); }let clear = format!("{} {}", shell.pointer("/clear/question").and_then(Value::as_str).unwrap_or_default(), shell.pointer("/clear/message").and_then(Value::as_str).unwrap_or_default()); assert!(clear.contains(&in_bin.to_string()), "Empty the bin counts what it shows ({in_bin}): {}", shell["clear"]);let cinemas_bin = ask(&handle, "cinemas.bin", json!({})); names_none("cinemas.bin", &cinemas_bin); assert_eq!(cinemas_bin["count"].as_u64(), Some(1), "{cinemas_bin}");let you = ask(&handle, "cinemas.you", json!({})); names_none("cinemas.you", &you);// Delete forever by id, every road: refused, and the hidden title waits in the Bin inside Hidden.for (method, request) in [ ("records.command", json!({ "table": "bin", "id": binned_hidden, "command": "delete" })), ("records.delete", json!({ "table": "bin", "id": binned_hidden })), ("records.update", json!({ "table": "bin", "id": binned_hidden, "data": { "state": "restored" } })), ("cinemas.erase", json!({ "id": binned_hidden })), ("cinemas.restore", json!({ "id": binned_hidden })), ] { assert!(crate::methods::dispatch(&handle, method, &request).is_err(), "{method} reached a hidden binned title"); }// Empty the shared Bin, both ways it is emptied (`erase_binned`, what `empty_bin` runs; Cinemas' own Empty): the// open binned film goes for good, the hidden one stays.let emptied = handle .client() .write_rows("test.empty_bin", &mut |ctx| Ok(json!(cotton_tools::mcp::handlers::tables::erase_binned(ctx, None).map_err(|f| f.to_string())?))) .expect("emptied"); assert_eq!(crate::authoring::own_answer(emptied).as_i64(), Some(1), "the shared Empty erased the open binned film alone"); assert_eq!(ask(&handle, "cinemas.erase", json!({}))["erased"].as_f64(), Some(0.0));// Inside Hidden: a Bin row, counted, opening the Bin of the hidden titles with Restore and Delete forever. ask(&handle, "cinemas.unlock", json!({}));let place = ask(&handle, "cinemas.hidden", json!({}));let row = place["rows"].as_array().unwrap().iter().find(|row| row["id"] == "bin").cloned().unwrap_or_else(|| panic!("a Bin row: {place}")); assert_eq!((row["count"].as_u64(), row.pointer("/act/method").and_then(Value::as_str), row.pointer("/act/request/hidden")), (Some(1), Some("cinemas.bin"), Some(&json!(true))), "{row}");let inside = ask(&handle, "cinemas.bin", json!({ "hidden": true })); assert_eq!(inside["count"].as_u64(), Some(1), "{inside}"); assert!(inside.to_string().contains("Edit Reel Binned") && !inside.to_string().contains("Paper Moons"), "{inside}"); assert_eq!((inside.pointer("/erase/label").and_then(Value::as_str), inside.pointer("/erase/args/hidden")), (Some("Delete forever"), Some(&json!(true))), "{inside}"); assert_eq!((inside.pointer("/restore/label").and_then(Value::as_str), inside.pointer("/restore/method").and_then(Value::as_str)), (Some("Restore"), Some("cinemas.restore")), "{inside}");// Restore inside Hidden brings it back as a hidden title; binned again, Delete forever erases it. ask(&handle, "cinemas.restore", json!({ "id": binned_hidden })); assert!(ask(&handle, "cinemas.hidden", json!({}))["rows"].as_array().unwrap().iter().all(|row| row["id"] != "bin"), "the Bin row leaves when it is empty"); ask(&handle, "records.delete", json!({ "table": "film", "id": binned_hidden })); assert_eq!(ask(&handle, "cinemas.erase", json!({ "id": binned_hidden, "hidden": true }))["erased"].as_f64(), Some(1.0)); assert!(ask(&handle, "cinemas.bin", json!({ "hidden": true }))["empty"].is_string()); ask(&handle, "cinemas.lock", json!({}));}