//! A tool's own acts: which stand on the fan by the object's status of each //! act's family (Google's, Spotify's), and what running one asks of the object. use std::sync::Arc; use cotton_client::transport::object::ObjectAddress; use cotton_client::transport::scripted::{Reply, ScriptedExchange}; use serde_json::json; use super::*; const CREDENTIAL: &str = "ctd_11111111-1111-4111-8111-111111111111_test-credential"; fn door(replies: impl IntoIterator) -> (ObjectDoor, Arc) { let exchange = ScriptedExchange::new(replies); let door = ObjectDoor { address: ObjectAddress::open("https://cottondb.example.test").expect("an address"), exchange: exchange.clone(), credential: CREDENTIAL.to_string(), }; (door, exchange) } /// The shipped Calendar tool, as the kit says it. fn calendar() -> ToolDefinition { serde_json::from_str(include_str!("../../../cotton-core/kits/personal/tools/calendar/manifest.json")).expect("the Calendar manifest reads") } /// Google's status alone, as the object answered it. fn google(status: Value) -> Statuses { Statuses::from([("google.status", status)]) } fn said(fan: &[Value]) -> Vec<(&str, &str)> { fan.iter().map(|act| (act["id"].as_str().unwrap(), act["label"].as_str().unwrap())).collect() } // RULE: with no Google account connected the Calendar's fan offers Connect Google Calendar, which asks nothing first. #[test] fn no_account_offers_connect() { let tool = calendar(); let fan = offered(&[&tool], &google(json!({"available": true, "accounts": []})), None); assert_eq!(said(&fan), [(GOOGLE_CONNECT, "Connect Google Calendar")]); assert_eq!((fan[0]["kind"].as_str(), fan[0]["tool"].as_str(), fan[0]["asks"].as_bool()), (Some("tool"), Some("calendar"), Some(false))); } // RULE: with an account connected the fan offers its Disconnect, saying the account and how its calendar stands, and asks first. #[test] fn an_account_offers_its_disconnect_saying_how_it_stands() { let tool = calendar(); let status = json!({"available": true, "accounts": [{"googleEmail": "owner@example.test", "calendar": {"phase": "synced"}}]}); let fan = offered(&[&tool], &google(status), None); assert_eq!(said(&fan), [(GOOGLE_DISCONNECT, "Disconnect Google (owner@example.test, synced)")]); assert_eq!((fan[0]["account"].as_str(), fan[0]["asks"].as_bool()), (Some("owner@example.test"), Some(true))); } // RULE: nothing stands while the object cannot connect Google or its status cannot be read. #[test] fn nothing_stands_on_an_unreadable_status_or_a_worker_without_google() { let tool = calendar(); assert!(offered(&[&tool], &Statuses::new(), None).is_empty()); assert!(offered(&[&tool], &google(json!({"available": false, "accounts": []})), None).is_empty()); } // RULE: Connect asks the object for Google's consent page and answers it to open; nothing else is called. #[test] fn connect_dispatches_to_google_connect_and_answers_the_page_to_open() { let (door, exchange) = door([Reply::ok(r#"{"authorizeUrl":"https://accounts.google.com/o/oauth2/v2/auth?state=s","state":"s"}"#)]); let answer = run(&door, GOOGLE_CONNECT, None).expect("an answer"); assert_eq!(answer, json!({"opens": "https://accounts.google.com/o/oauth2/v2/auth?state=s"})); let sent = exchange.only(); assert_eq!((sent.method.as_str(), sent.path.as_str()), ("GET", "/v1/google/connect")); } // RULE: Disconnect names the account the fan offered it for. #[test] fn disconnect_names_its_account() { let (door, exchange) = door([Reply::ok(r#"{"ok":true,"account":"owner@example.test"}"#)]); let answer = run(&door, GOOGLE_DISCONNECT, Some("owner@example.test")).expect("an answer"); assert_eq!(answer["account"], "owner@example.test"); let sent = exchange.only(); assert_eq!((sent.method.as_str(), sent.path.as_str()), ("POST", "/v1/google/disconnect")); assert_eq!(serde_json::from_slice::(&sent.body).expect("json"), json!({"account": "owner@example.test"})); } // RULE: an act this build does not run sends nothing. #[test] fn an_unknown_act_sends_nothing() { let (door, exchange) = door([]); assert_eq!(run(&door, "google_nonesuch", None).expect_err("a refusal").code, "bad_request"); assert_eq!(exchange.calls(), 0); } // RULE: the Calendar tool owns the event table, so every event card's fan carries its acts. #[test] fn the_calendar_owns_the_event_table() { let tools = [calendar()]; let event: TableDefinition = serde_json::from_str(include_str!("../../../cotton-core/kits/personal/tables/event.json")).expect("event reads"); assert_eq!(owning(&event, &tools).iter().map(|tool| tool.id.as_str()).collect::>(), ["calendar"]); } #[test] fn running_an_act_is_a_method_and_never_a_read() { assert!(crate::methods::ALL_METHODS.contains(&"tools.act")); assert!(!crate::methods::read_only("tools.act")); } fn table(json: &str) -> TableDefinition { serde_json::from_str(json).expect("the table reads") } fn todos() -> ToolDefinition { serde_json::from_str(include_str!("../../../cotton-core/kits/personal/tools/todos/manifest.json")).expect("the Todos manifest reads") } // RULE: an empty Calendar deck (`tools.acts {table: event}`) offers Connect Google Calendar while no account is connected, as an event card's fan does. #[test] fn an_empty_calendar_deck_offers_connect_while_no_account_is_held() { let tools = [calendar(), todos()]; let event = table(include_str!("../../../cotton-core/kits/personal/tables/event.json")); let fan = for_table(&event, &tools, None, |_| Some(json!({"available": true, "accounts": []}))); assert_eq!(said(&fan), [(GOOGLE_CONNECT, "Connect Google Calendar")]); assert_eq!((fan[0]["kind"].as_str(), fan[0]["tool"].as_str()), (Some("tool"), Some("calendar"))); } // RULE: an empty Calendar deck offers one Disconnect per account it holds, each naming its account and asking first. #[test] fn an_empty_calendar_deck_offers_one_disconnect_per_account() { let tools = [calendar()]; let event = table(include_str!("../../../cotton-core/kits/personal/tables/event.json")); let status = json!({"available": true, "accounts": [ {"googleEmail": "owner@example.test", "calendar": {"phase": "synced"}}, {"googleEmail": "second@example.test", "calendar": {"phase": "syncing"}}, ]}); let fan = for_table(&event, &tools, None, |_| Some(status.clone())); assert_eq!( said(&fan), [ (GOOGLE_DISCONNECT, "Disconnect Google (owner@example.test, synced)"), (GOOGLE_DISCONNECT, "Disconnect Google (second@example.test, syncing)"), ] ); assert_eq!(fan.iter().map(|act| act["account"].as_str().unwrap()).collect::>(), ["owner@example.test", "second@example.test"]); assert!(fan.iter().all(|act| act["asks"] == json!(true))); } // RULE: a deck whose tool offers no act answers none, and the object's status is never asked for it. #[test] fn a_tool_with_no_acts_answers_none_unasked() { let tools = [calendar(), todos()]; let todo = table(include_str!("../../../cotton-core/kits/personal/tables/todo.json")); let fan = for_table(&todo, &tools, None, |_| panic!("the status is asked for a table no acting tool owns")); assert!(fan.is_empty()); } // RULE: `tools.acts` is a read the phone asks with the deck's table, answering a held card's tool acts' shape. #[test] fn an_empty_decks_acts_are_a_read_of_its_table() { use crate::shell::client::phone_tests::attached; assert!(crate::methods::ALL_METHODS.contains(&"tools.acts")); assert!(crate::methods::CLIENT_METHODS.contains(&"tools.acts")); assert!(crate::methods::read_only("tools.acts")); let (_dir, client) = attached(); assert_eq!(acts(&client, &json!({})).expect_err("a refusal").code, "bad_request"); assert_eq!(acts(&client, &json!({"table": "todo"})).expect("an answer"), json!({"actions": []})); } /// The shipped Music tool, as the kit says it. fn music() -> ToolDefinition { serde_json::from_str(include_str!("../../../cotton-core/kits/personal/tools/music/manifest.json")).expect("the Music manifest reads") } fn song() -> TableDefinition { table(include_str!("../../../cotton-core/kits/personal/tables/song.json")) } /// A tool over songs offering Spotify's two acts. No shipped tool does since /// Music went to the owner's own files (4 Nov 2026), and Podcasts has not /// taken them yet; the family's rules stand, and this is how they are held. fn spotify_tool() -> ToolDefinition { let mut tool: Value = serde_json::from_str(include_str!("../../../cotton-core/kits/personal/tools/music/manifest.json")).expect("the Music manifest reads"); tool["id"] = json!("listening"); tool["views"] = json!([{"id": "songs", "label": "Songs", "visibility": "owner", "is_default": true, "read": {"table": "song"}, "sort": {"column": "title", "descending": false}}]); tool["acts"] = json!([{"id": SPOTIFY_CONNECT, "label": "Connect Spotify"}, {"id": SPOTIFY_DISCONNECT, "label": "Disconnect Spotify", "asks": true}]); serde_json::from_value(tool).expect("a tool") } /// Spotify's status alone, as the object answered it. fn spotify(status: Value) -> Statuses { Statuses::from([("spotify.status", status)]) } fn connected(display_name: Value) -> Value { json!({"available": true, "account": {"userId": "synthetic-user", "displayName": display_name, "phase": "synced", "syncing": false}}) } // RULE: each act belongs to the family whose status decides it; an act this build does not run has none. #[test] fn each_act_is_decided_by_its_familys_status() { assert_eq!(family(GOOGLE_CONNECT), Some("google.status")); assert_eq!(family(GOOGLE_DISCONNECT), Some("google.status")); assert_eq!(family(SPOTIFY_CONNECT), Some("spotify.status")); assert_eq!(family(SPOTIFY_DISCONNECT), Some("spotify.status")); assert_eq!(family("spotify_nonesuch"), None); } // RULE: with no Spotify account connected Music's fan offers Connect Spotify, which asks nothing first. #[test] fn no_spotify_account_offers_connect_spotify() { let tool = spotify_tool(); let fan = offered(&[&tool], &spotify(json!({"available": true, "account": null})), None); assert_eq!(said(&fan), [(SPOTIFY_CONNECT, "Connect Spotify")]); assert_eq!((fan[0]["kind"].as_str(), fan[0]["tool"].as_str(), fan[0]["asks"].as_bool()), (Some("tool"), Some("listening"), Some(false))); } // RULE: with a Spotify account connected the fan offers Disconnect Spotify, saying who is connected and how the pull stands, and asks first. #[test] fn a_spotify_account_offers_its_disconnect_saying_who_is_connected() { let tool = spotify_tool(); let fan = offered(&[&tool], &spotify(connected(json!("Sam Example"))), None); assert_eq!(said(&fan), [(SPOTIFY_DISCONNECT, "Disconnect Spotify (Sam Example, synced)")]); assert_eq!(fan[0]["asks"].as_bool(), Some(true)); } // RULE: a Spotify account with no display name (Spotify gives none for some) is named by its Spotify id. #[test] fn a_spotify_account_with_no_display_name_is_named_by_its_id() { let tool = spotify_tool(); for nameless in [json!(null), json!("")] { let fan = offered(&[&tool], &spotify(connected(nameless)), None); assert_eq!(said(&fan), [(SPOTIFY_DISCONNECT, "Disconnect Spotify (synthetic-user, synced)")]); } } // RULE: nothing of Spotify stands while the object cannot connect Spotify or its status cannot be read. #[test] fn nothing_of_spotify_stands_on_an_unreadable_status_or_a_worker_without_spotify() { let tool = spotify_tool(); assert!(offered(&[&tool], &Statuses::new(), None).is_empty()); assert!(offered(&[&tool], &spotify(json!({"available": false, "account": null})), None).is_empty()); } // RULE: one family's status unread leaves only that family's acts out: Google's stand by Google's status while Spotify's cannot be read. #[test] fn an_unread_family_leaves_only_its_own_acts_out() { let (calendar, music) = (calendar(), spotify_tool()); let fan = offered(&[&calendar, &music], &google(json!({"available": true, "accounts": []})), None); assert_eq!(said(&fan), [(GOOGLE_CONNECT, "Connect Google Calendar")]); let fan = offered(&[&calendar, &music], &spotify(json!({"available": true, "account": null})), None); assert_eq!(said(&fan), [(SPOTIFY_CONNECT, "Connect Spotify")]); } // RULE: Connect Spotify asks the object for Spotify's consent page and answers it to open; nothing else is called. #[test] fn connect_spotify_dispatches_to_spotify_connect_and_answers_the_page_to_open() { let (door, exchange) = door([Reply::ok(r#"{"authorizeUrl":"https://accounts.spotify.com/authorize?state=s","state":"s"}"#)]); let answer = run(&door, SPOTIFY_CONNECT, None).expect("an answer"); assert_eq!(answer, json!({"opens": "https://accounts.spotify.com/authorize?state=s"})); let sent = exchange.only(); assert_eq!((sent.method.as_str(), sent.path.as_str()), ("GET", "/v1/spotify/connect")); } // RULE: a connect whose page is not https opens nothing: the object's answer is refused as unreadable. #[test] fn a_connect_page_that_is_not_https_opens_nothing() { for answer in [r#"{"authorizeUrl":"http://accounts.spotify.com/authorize","state":"s"}"#, r#"{"state":"s"}"#] { let (door, _exchange) = door([Reply::ok(answer)]); assert_eq!(run(&door, SPOTIFY_CONNECT, None).expect_err("a refusal").code, "unreadable"); } } // RULE: Disconnect Spotify posts the object's disconnect with an empty body: it holds the one account. #[test] fn disconnect_spotify_posts_the_objects_disconnect() { let (door, exchange) = door([Reply::ok(r#"{"ok":true,"account":"synthetic-user"}"#)]); let answer = run(&door, SPOTIFY_DISCONNECT, None).expect("an answer"); assert_eq!(answer, json!({"ok": true, "account": "synthetic-user"})); let sent = exchange.only(); assert_eq!((sent.method.as_str(), sent.path.as_str()), ("POST", "/v1/spotify/disconnect")); assert_eq!(serde_json::from_slice::(&sent.body).expect("json"), json!({})); } // RULE: the Music tool owns the song table, so every song's fan carries its acts. #[test] fn music_owns_the_song_table() { let tools = [calendar(), music()]; assert_eq!(owning(&song(), &tools).iter().map(|tool| tool.id.as_str()).collect::>(), ["music"]); } // RULE (Music definition, 4 Nov 2026; one way in, 5 Nov 2026): a Music deck offers no act of its own beyond On this phone's Keep everything, which says how this phone keeps; songs come in through the deck's doors (`create.doors`), never an act. #[test] fn a_music_deck_offers_on_this_phone_keep_everything_and_no_pickers() { let tools = [calendar(), music(), todos()]; let mut asked = Vec::new(); let fan = for_table(&song(), &tools, Some("music/songs"), |status| { asked.push(status); match status { MUSIC_STATUS => Some(json!({"keep_everything": false})), _ => None, } }); assert!(said(&fan).is_empty(), "the deck's doors bring songs in, no act duplicates them: {fan:?}"); assert!(asked.is_empty(), "no Music act stands on Songs, so no status is asked: {asked:?}"); let on_phone = for_table(&song(), &tools, Some("music/on_phone"), |status| match status { MUSIC_STATUS => Some(json!({"keep_everything": true})), _ => None, }); let kept = on_phone.iter().find(|entry| entry["id"] == MUSIC_KEEP_EVERYTHING).expect("Keep everything stands on On this phone"); assert_eq!((kept["label"].as_str(), kept["on"].as_bool()), (Some("Keep everything: on"), Some(true))); } // RULE: Music's Keep everything is this phone's to turn over, never a call to the object; turned on, the phone fetches what is not here. #[test] fn musics_keep_everything_turns_over_here() { use crate::shell::client::phone_tests::attached; let (_dir, client) = attached(); let on = super::music_keep_everything(&client).expect("Keep everything turns on"); assert_eq!((on["on"].clone(), on["platform_action"].clone()), (json!(true), json!("keep_songs")), "turned on, the phone fetches what is not here"); assert_eq!(super::music_status(&client).expect("a status"), json!({"keep_everything": true})); let off = super::music_keep_everything(&client).expect("and off"); assert_eq!((off["on"].clone(), off.get("platform_action")), (json!(false), None)); } // RULE: an empty deck of a tool offering Spotify's acts offers Connect Spotify while no account is held, asking Spotify's status alone. #[test] fn an_empty_spotify_deck_offers_connect_spotify_asking_spotify_alone() { let tools = [calendar(), spotify_tool(), todos()]; let mut asked = Vec::new(); let fan = for_table(&song(), &tools, None, |status| { asked.push(status); Some(json!({"available": true, "account": null})) }); assert_eq!(said(&fan), [(SPOTIFY_CONNECT, "Connect Spotify")]); assert_eq!(asked, ["spotify.status"], "a table only it owns never asks Google's status"); } // RULE: an empty deck of a tool offering Spotify's acts, with an account connected, offers Disconnect Spotify saying who is connected. #[test] fn an_empty_spotify_deck_offers_disconnect_while_an_account_is_held() { let tools = [spotify_tool()]; let fan = for_table(&song(), &tools, None, |_| Some(connected(json!("Sam Example")))); assert_eq!(said(&fan), [(SPOTIFY_DISCONNECT, "Disconnect Spotify (Sam Example, synced)")]); } // RULE: an empty Calendar deck asks Google's status alone, never Spotify's. #[test] fn an_empty_calendar_deck_asks_google_alone() { let tools = [calendar(), music()]; let event = table(include_str!("../../../cotton-core/kits/personal/tables/event.json")); let mut asked = Vec::new(); for_table(&event, &tools, None, |status| { asked.push(status); Some(json!({"available": true, "accounts": []})) }); assert_eq!(asked, ["google.status"]); } /// The Books tool with this phone's account acts on its On this phone view /// (owner, 4 Nov 2026), as the kit says it with them folded in. fn books_with_account() -> ToolDefinition { let mut tool: Value = serde_json::from_str(include_str!("../../../cotton-core/kits/personal/tools/books/manifest.json")).expect("the Books manifest reads"); tool["acts"] = json!([ {"id": ACCOUNT_SIGN_IN, "label": "Sign in"}, {"id": ACCOUNT_BACK_UP, "label": "Sync now"}, {"id": ACCOUNT_SIGN_OUT, "label": "Sign out"}, ]); for view in tool["views"].as_array_mut().unwrap() { if view["id"] == "on_phone" { view["acts"] = json!([ACCOUNT_SIGN_IN, ACCOUNT_BACK_UP, ACCOUNT_SIGN_OUT]); } } let tool: ToolDefinition = serde_json::from_value(tool).expect("the Books tool reads"); tool.validate().expect("its views name its own acts"); tool } fn book() -> TableDefinition { table(include_str!("../../../cotton-core/kits/personal/tables/book.json")) } fn phone_account(backs_up: bool, signed_in: bool) -> impl FnMut(&'static str) -> Option { move |status| { assert_eq!(status, ACCOUNT_STATUS, "only the phone's own status is asked"); Some(json!({"backs_up": backs_up, "signed_in": signed_in})) } } // RULE (owner, 4 Nov 2026; the Account card, 11 Nov 2026): Books' Account card offers Sign in while this phone is not signed in, and Back up now and Sign out while it is; never Erase. #[test] fn the_account_card_offers_sign_in_or_back_up_and_sign_out() { let tools = [books_with_account()]; let out = for_table(&book(), &tools, Some("books/account"), phone_account(true, false)); assert_eq!(said(&out), [(ACCOUNT_SIGN_IN, "Sign in")]); let signed_in = for_table(&book(), &tools, Some("books/account"), phone_account(true, true)); assert_eq!(said(&signed_in), [(ACCOUNT_BACK_UP, "Sync now"), (ACCOUNT_SIGN_OUT, "Sign out")]); assert!(signed_in.iter().all(|act| act["kind"] == "tool" && act["tool"] == "books")); } // RULE: an act a view names stands on that view's deck alone — Reading, another tool's view of the same id, or no view at all offers none of it — and nothing stands where the app backs up to no object (Rigby). #[test] fn a_views_acts_stand_on_its_deck_alone() { let tools = [books_with_account()]; for view in [None, Some("books/reading"), Some("cinemas/on_phone"), Some("on_phone")] { assert!(for_table(&book(), &tools, view, |_| panic!("no act stands, so no status is asked ({view:?})")).is_empty(), "{view:?}"); } assert!(for_table(&book(), &tools, Some("books/on_phone"), phone_account(false, false)).is_empty(), "an app that never backs up offers no account"); } // RULE: a view names only acts its tool declares, each once; a table's own tool block declares none, so its views name none. #[test] fn a_view_names_only_its_tools_acts() { let mut tool = serde_json::to_value(books_with_account()).unwrap(); tool["views"][0]["acts"] = json!(["google_connect"]); assert!(serde_json::from_value::(tool.clone()).unwrap().validate().is_err()); tool["views"][0]["acts"] = json!([ACCOUNT_SIGN_IN, ACCOUNT_SIGN_IN]); assert!(serde_json::from_value::(tool).unwrap().validate().is_err()); } // RULE: this phone's account is answered from its own state: a joined phone of an app that backs up is signed in, so Sign out runs this device's own Sign out flow and Back up now asks a pass and says so, while Sign in, which does not stand, is refused. #[test] fn the_account_is_this_phones_own_and_runs_its_device_rows_flows() { use crate::shell::client::phone_tests::attached; let (_dir, client) = attached(); assert_eq!(account_status(&client), json!({"backs_up": true, "signed_in": true, "backing_up": false})); let answer = account(&client, ACCOUNT_SIGN_OUT).expect("Sign out stands"); assert_eq!(answer["platform_action"], "open_flow"); assert_eq!(answer["flow"], "signOut"); assert_eq!(answer["origin"]["table"], "device"); assert_eq!(answer["origin"]["id"].as_str(), client.self_device_id().as_deref()); assert_eq!(account(&client, ACCOUNT_BACK_UP).expect("Sync now stands")["said"], "Syncing…"); let refused = account(&client, ACCOUNT_SIGN_IN).expect_err("Sign in does not stand while signed in"); assert_eq!(refused.code, "act_not_standing"); } // RULE (Cinemas gaps, 5 Nov 2026): no blank tile on the fan: every act On this phone and the Account card offer in Cinemas carries the picture its tool paints it with (`object`, said as `icon`, one of the shell's act objects). #[test] fn every_cinemas_act_on_this_phone_carries_its_picture() { let cinemas: ToolDefinition = serde_json::from_str(include_str!("../../../cotton-core/kits/personal/tools/cinemas/manifest.json")).expect("the Cinemas manifest reads"); let mut statuses = Statuses::new(); statuses.insert(CINEMAS_STATUS, json!({"keep_everything": false, "cellular": false, "budget_gb": 64})); for signed_in in [false, true] { statuses.insert(ACCOUNT_STATUS, json!({"backs_up": true, "signed_in": signed_in})); let mut fan = offered(&[&cinemas], &statuses, Some("cinemas/on_phone")); fan.extend(offered(&[&cinemas], &statuses, Some("cinemas/account"))); assert!(fan.len() >= 4, "{fan:?}"); for act in &fan { let icon = act["icon"].as_str().unwrap_or_else(|| panic!("{} has no picture", act["id"])); let object = icon.strip_prefix("act-").expect("an act picture"); assert!(cotton_core::definitions::ACT_OBJECTS.contains(&object), "{icon}"); } } } fn money() -> ToolDefinition { serde_json::from_str(include_str!("../../../cotton-core/kits/personal/tools/money/manifest.json")).expect("the Money manifest reads") } fn transaction() -> TableDefinition { table(include_str!("../../../cotton-core/kits/personal/tables/transaction.json")) } // RULE (Cotton Money, 6 Nov 2026; the Account card, 11 Nov 2026): Money names no account act, so Cotton draws its Money as it always has; Cotton Money's kit lays Sign in, Back up now and Sign out over it, each with its picture, and they stand on the Account card alone, on no deck. #[test] fn cotton_moneys_kit_lays_the_account_on_its_card_and_cotton_keeps_money_as_it_is() { let plain = [money()]; for view in [Some("money/past"), Some("money/future"), None] { assert!(for_table(&transaction(), &plain, view, |_| panic!("Money in Cotton offers no act")).is_empty(), "{view:?}"); } let kit = cotton_core::kit::AppKit::named("money").expect("the money kit ships"); let mut laid = vec![money()]; kit.lay_acts(&mut laid); laid[0].validate().expect("the laid tool names only its own acts"); let out = for_table(&transaction(), &laid, Some("money/account"), phone_account(true, false)); assert_eq!(said(&out), [(ACCOUNT_SIGN_IN, "Sign in")]); let signed_in = for_table(&transaction(), &laid, Some("money/account"), phone_account(true, true)); assert_eq!(said(&signed_in), [(ACCOUNT_BACK_UP, "Sync now"), (ACCOUNT_SIGN_OUT, "Sign out")]); assert!(signed_in.iter().chain(&out).all(|act| act["tool"] == "money" && act["icon"].as_str().is_some_and(|icon| icon.starts_with("act-")))); for view in ["money/past", "money/future", "money/banks", "money/owed"] { assert!(for_table(&transaction(), &laid, Some(view), |_| panic!("nothing stands on {view}")).is_empty(), "{view}"); } } // RULE (signin-sticks, 11 Nov 2026): while a sign-in's rows are going up the phone is not signed out: Sign in is not offered over it, Back up now says where it stands and Sign out stops it. #[test] fn a_backup_on_its_way_offers_no_sign_in() { let going_up = json!({"backs_up": true, "signed_in": false, "backing_up": true}); assert!(!offered_account(ACCOUNT_SIGN_IN, &going_up)); assert!(offered_account(ACCOUNT_BACK_UP, &going_up) && offered_account(ACCOUNT_SIGN_OUT, &going_up)); let signed_out = json!({"backs_up": true, "signed_in": false, "backing_up": false}); assert!(offered_account(ACCOUNT_SIGN_IN, &signed_out) && !offered_account(ACCOUNT_SIGN_OUT, &signed_out)); } // RULE (owner, 11 Nov 2026): the phone reads its tools' acts through the kit its app keeps, and in every Cotton app the account acts stand on the Account card alone: a phone not signed in finds Sign in there (`/account`) and on no deck, the view the app opens on included; the same database read as Cotton's finds none anywhere. #[test] fn every_cotton_apps_account_acts_stand_on_its_account_card_alone() { use crate::shell::client::phone_tests::attached_on_a_clock_in; for (kit, table, opens_on) in [ // Money, Music and Journal are retired (TABLE DROP 1, 27 Nov 2026) and are no app's kit to keep here. ("keys", "passkey", "keys/all"), ("notes", "note", "notebook/all"), ("messages", "thread", "messages/all"), ("calendar", "event", "calendar/today"), ("todos", "todo", "todos/today"), ("books", "book", "books/on_phone"), ("cinemas", "film", "cinemas/on_phone"), ("people", "person", "people/all"), ("photos", "media", "photos/all"), ("health", "health_day", "health/today"), ] { let (_dir, local, _) = attached_on_a_clock_in("local"); let root = local.layout().root().to_path_buf(); let card = format!("{}/account", opens_on.split('/').next().unwrap()); let account = |view: &str| -> Vec { let answer = acts(&local, &json!({"table": table, "view": view})).unwrap_or_else(|refused| panic!("{kit} {view}: {}", refused.message)); answer["actions"].as_array().unwrap().iter().filter_map(|act| act["id"].as_str()).filter(|id| cotton_core::kit::ACCOUNT_ACTS.contains(id)).map(str::to_string).collect() }; assert!(account(opens_on).is_empty(), "{kit}: Cotton's own deck offers no account act"); cotton_core::kit::AppKit::keep(cotton_core::kit::AppKit::named(kit).as_ref(), &root).expect("kept"); assert_eq!(account(&card), [ACCOUNT_SIGN_IN], "{kit}: Sign in stands on the Account card"); assert!(account(opens_on).is_empty(), "{kit}: and on no deck, the one it opens on included"); } } /// The shipped tool `id`, as the kit says it. fn shipped(id: &str) -> ToolDefinition { let json = match id { "books" => include_str!("../../../cotton-core/kits/personal/tools/books/manifest.json"), "music" => include_str!("../../../cotton-core/kits/personal/tools/music/manifest.json"), "cinemas" => include_str!("../../../cotton-core/kits/personal/tools/cinemas/manifest.json"), other => panic!("no shipped tool {other}"), }; let tool: ToolDefinition = serde_json::from_str(json).expect("the manifest reads"); tool.validate().expect("its views name its own acts"); tool } // RULE (export-open-swift, 7 Nov 2026): Books, Music and Cinemas each offer Export library, with its picture, on the view that holds this phone's acts — On this phone — answered by the phone alone, signed in or not; and on no other view. #[test] fn each_library_offers_export_library_on_its_phones_view() { let export = |status: &'static str| match status { EXPORT_STATUS => Some(json!({})), ACCOUNT_STATUS => Some(json!({"backs_up": false, "signed_in": false})), _ => None, }; for (tool, table, view, other) in [ ("books", book(), "books/on_phone", "books/all"), ("music", song(), "music/on_phone", "music/songs"), ("cinemas", table(include_str!("../../../cotton-core/kits/personal/tables/film.json")), "cinemas/on_phone", "cinemas/films"), ] { let tools = [shipped(tool)]; let fan = for_table(&table, &tools, Some(view), export); let act = fan.iter().find(|act| act["id"] == EXPORT_LIBRARY).unwrap_or_else(|| panic!("{view} offers Export library: {fan:?}")); assert_eq!((act["label"].as_str(), act["tool"].as_str(), act["icon"].as_str()), (Some("Export library"), Some(tool), Some("act-parcel"))); assert!(!for_table(&table, &tools, Some(other), export).iter().any(|act| act["id"] == EXPORT_LIBRARY), "{other} offers no Export library"); } } // RULE: Export library runs on the phone: `tools.act` answers the open bundle's kit as `package.exportOpen` names it (Cinemas' is films) and the tool's name, for the phone to lay, zip and share. #[test] fn export_library_answers_the_bundle_the_phone_lays() { for (tool, kit, name) in [("books", "books", "Books"), ("music", "music", "Music"), ("cinemas", "films", "Films")] { assert_eq!(family(EXPORT_LIBRARY), Some(EXPORT_STATUS)); let answer = super::export_library(&shipped(tool)).expect("it runs"); assert_eq!(answer, json!({"platform_action": "export_open", "kit": kit, "name": name}), "{tool}"); } assert_eq!(super::export_library(&todos()).expect_err("Todos has no open bundle").code, "bad_request"); } // RULE (owner, 11 Nov 2026, the fan's one tier): an act always runs on the tool of the view in view, never the app's first tool by the act's id. Books and Cinemas each define `export_library` and name it on a view both call `on_phone` (Music was the pair until TABLE DROP 1); in an app whose kit lists both, Cinemas' view on the one tier offers Cinemas' act and runs it as Cinemas', and Books' offers and runs Books'. #[test] fn two_tools_sharing_an_act_id_each_run_their_own_on_the_one_tier() { use crate::shell::client::phone_tests::attached_on_a_clock_in; let (_dir, local, _) = attached_on_a_clock_in("local"); let mut kit = cotton_core::kit::AppKit::named("books").expect("the books kit ships"); kit.tools.push("cinemas".into()); kit.tables.extend(cotton_core::kit::AppKit::named("cinemas").expect("the cinemas kit ships").tables); cotton_core::kit::AppKit::keep(Some(&kit), local.layout().root()).expect("kept"); // On the one tier Cinemas' On this phone stands under its own id (`cinemas__on_phone`, `AppKit::fold`). let export = |table: &str, view: &str| -> Value { let answer = acts(&local, &json!({"table": table, "view": view})).unwrap_or_else(|refused| panic!("{view}: {}", refused.message)); answer["actions"].as_array().unwrap().iter().find(|act| act["id"] == EXPORT_LIBRARY).cloned().unwrap_or_else(|| panic!("{view} offers no export: {answer}")) }; let films = export("film", "books/cinemas__on_phone"); assert_eq!(films["tool"], "cinemas", "the act is Cinemas' on Cinemas' view: {films}"); let books = export("book", "books/on_phone"); assert_eq!(books["tool"], "books", "{books}"); let ran = call(&local, &json!({"tool": films["tool"], "act": EXPORT_LIBRARY})).expect("Cinemas' export runs"); assert_eq!((ran["kit"].as_str(), ran["name"].as_str()), (Some("films"), Some("Films")), "it runs as Cinemas', never Books' by the id: {ran}"); let ran = call(&local, &json!({"tool": books["tool"], "act": EXPORT_LIBRARY})).expect("Books' export runs"); assert_eq!((ran["kit"].as_str(), ran["name"].as_str()), (Some("books"), Some("Books")), "{ran}"); } fn keys_tool() -> ToolDefinition { serde_json::from_str(include_str!("../../../cotton-core/kits/personal/tools/keys/manifest.json")).expect("the Keys manifest reads") } // RULE (keys-android-autofill, 17 Nov 2026): Turn on Cotton Keys stands on the Passkeys decks only where this build ships Android's autofill service and credential provider (the Keys app on Android), and opens the system's provider settings; anywhere else it neither stands nor runs. #[test] fn turn_on_cotton_keys_stands_where_the_phone_ships_the_providers() { let passkey = table(include_str!("../../../cotton-core/kits/personal/tables/passkey.json")); let tools = [keys_tool()]; let standing = |provides: bool| for_table(&passkey, &tools, Some("keys/all"), |status| (status == KEYS_STATUS).then(|| json!({"provider_settings": provides}))); assert_eq!(said(&standing(true)), [(KEYS_TURN_ON, "Turn on Cotton Vault")]); assert!(standing(false).is_empty()); assert!(for_table(&passkey, &tools, Some("keys/all"), |_| None).is_empty(), "unread, it does not stand"); use crate::shell::client::phone_tests::attached; let (_dir, client) = attached(); assert_eq!(super::keys_status(&client), json!({"provider_settings": false}), "no app kit, and no Android"); assert_eq!(super::keys_turn_on(&client).unwrap_err().code, "act_not_standing"); } // RULE (launch-ios walk, 22 Nov 2026): a person not signed in who taps Connect Google Calendar in Days is taken to Sign in (this device's own Sign in flow), never told "That didn't work". #[test] fn connect_while_signed_out_opens_sign_in() { let dir = tempfile::tempdir().expect("a temp container"); let handle = crate::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(serde_json::from_str(include_str!("../../../../apps/cotton/App/Flavours/days/flavour.json")).expect("Days' manifest")), }) .expect("an open core"); crate::methods::dispatch(&handle, "workspace.startLocal", &json!({"deviceName": "An invented phone"})).expect("started"); let answer = crate::methods::dispatch(&handle, "tools.act", &json!({"tool": "calendar", "act": GOOGLE_CONNECT})).expect("Connect answers, signed out"); assert_eq!(answer["platform_action"], "open_flow", "{answer}"); assert_eq!(answer["flow"], "signIn", "{answer}"); }