//! Cotton is the calendar and Google the wire to other people (owner, 11 Oct//! 2026): `create_event` and `update_event` carry the owner's On Google switch,//! and `create_event`'s guests are what make an event Google's to carry — the//! serving Mac's first insert of it is the invitation (`gcal_sync`, guarded in//! cotton-server's `gcal_accounts`). Driven through the dispatcher.//!//! Every value is invented ([nothing-real-ever-goes-in-cotton-s-public-tree]).mod support;use rusqlite::types::ValueasSqlValue;use serde_json::{json, Value};use support::harness::{synthetic_uuid, Harness};use support::mcp::call_tool_as_owner;const PHONE: &str = "device:phone";fn owner(h: &Harness, tool: &str, args: Value) -> Value {let answer = call_tool_as_owner(h, PHONE, tool, args); assert!(!answer.is_error, "{tool} refused: {}", answer.text); answer.json()}fn calendared() -> Harness {let h = Harness::new(); h.run("INSERT INTO cotton_collections (id, workspace_id, kind, name, is_default, created_at) \ VALUES (?, ?, 'calendar', 'Personal', 1, '2026-10-01T09:00:00.000Z')", &[SqlValue::Text(synthetic_uuid("calendar")), SqlValue::Text(h.workspace_id.clone())], ); h}fn on_google(h: &Harness, id: &str) -> Option<i64> { h.one("SELECT on_google FROM cotton_events WHERE id = ?", &[SqlValue::Text(id.to_string())]) .and_then(|row| row.get("on_google").and_then(Value::as_i64))}// RULE: create_event leaves a solo event off Google unless onGoogle says so, and update_event's onGoogle alone is a whole change that throws the switch either way.#[test]fn on_google_is_the_owners_switch_on_create_and_update() {let h = calendared();let solo = owner(&h, "create_event", json!({ "title": "Dentist", "startsAt": "2026-10-15T09:30:00.000Z" }));let solo = solo["id"].as_str().expect("an id").to_string(); assert_eq!(on_google(&h, &solo), Some(0), "a solo event stays in Cotton");let shared = owner( &h,"create_event", json!({ "title": "Kite festival", "startsAt": "2026-10-16T09:30:00.000Z", "onGoogle": true }), ); assert_eq!(shared["onGoogle"], json!(true)); assert_eq!(on_google(&h, shared["id"].as_str().expect("an id")), Some(1));let switched = owner(&h, "update_event", json!({ "id": solo, "onGoogle": true })); assert_eq!(switched["onGoogle"], json!(true)); assert_eq!(on_google(&h, &solo), Some(1)); owner(&h, "update_event", json!({ "id": solo, "title": "Dentist, moved", "onGoogle": false })); assert_eq!(on_google(&h, &solo), Some(0));let title = h.one("SELECT title FROM cotton_events WHERE id = ?", &[SqlValue::Text(solo.clone())]).expect("the row"); assert_eq!(title["title"], json!("Dentist, moved"));}// RULE: create_event with attendees keeps them as the event's guests — which is what sends the event to Google, whose first insert invites them — and the switch stays the owner's.#[test]fn create_event_with_attendees_keeps_its_guests() {let h = calendared();let made = owner( &h,"create_event", json!({"title": "Lunch","startsAt": "2026-10-15T12:30:00.000Z","attendees": [{ "email": "ada@example.org", "displayName": "Ada Example" }], }), );let id = made["id"].as_str().expect("an id").to_string();let guests = h.all("SELECT email FROM cotton_event_attendees WHERE event_id = ?", &[SqlValue::Text(id.clone())]); assert_eq!(guests.len(), 1); assert_eq!(guests[0]["email"], json!("ada@example.org")); assert_eq!(on_google(&h, &id), Some(0), "guests send it to Google; the switch is untouched");}// RULE (Days, 22 Nov 2026): an event's alert of -1 is No alert, which never reminds, and an empty one is the ten minutes// before; an assistant writing events is told so by the event table's instructions and by update_event, so it never// writes -1 meaning a minute, nor clears an alert meaning none.#[test]fn an_assistant_is_told_that_an_alert_of_minus_one_is_no_alert() {let said = "-1 is no alert at all, and empty is the ten minutes before";let kit: Value = serde_json::from_slice(cotton_core::kit::table_file("event").expect("the event table")).expect("json");let instructions = kit["instructions"].as_str().expect("instructions"); assert!(instructions.contains(said), "{instructions}");let update = cotton_tools::mcp::catalogue::TOOLS.iter().find(|tool| tool.name == "update_event").expect("update_event"); assert!(update.description.contains(said), "{}", update.description);}