//! Cotton Days, round three (the owner's second use, 21 Nov 2026), over//! invented days, signed out: nobody here is real.use serde_json::{json, Value};use tempfile::TempDir;usesuper::tests::{ask, lines, phone, refused, span, sql, todo_in, zone, TODAY, ZONE};usecrate::handle::CottonHandle;const SERIES: &str = "00000000-0000-4000-8000-0000000000a1";fn said(value: &rusqlite::types::Value) -> String {match value { rusqlite::types::Value::Text(text) => text.clone(), rusqlite::types::Value::Integer(n) => n.to_string(), rusqlite::types::Value::Null => "·".to_string(), other => format!("{other:?}"), }}fn one(handle: &CottonHandle, statement: &str) -> Option<String> { handle .client() .with_writer(|replica| {Ok::<_, String>( replica .driver .get(&statement.replace("$WS", replica.workspace_id), &[]) .map_err(|e| e.to_string())? .and_then(|row| row.columns().first().map(|(_, v)| said(v))), ) }) .unwrap()}fn all(handle: &CottonHandle, statement: &str) -> Vec<String> { handle .client() .with_writer(|replica| {Ok::<_, String>( replica .driver .all(&statement.replace("$WS", replica.workspace_id), &[]) .map_err(|e| e.to_string())? .iter() .map(|row| row.columns().iter().map(|(_, v)| said(v)).collect::<Vec<_>>().join(" ")) .collect(), ) }) .unwrap()}/// A daily walk at 8:00 whose live copy is from Wednesday, so it is late.fn late_walk(handle: &CottonHandle) { sql(handle, &format!("INSERT INTO cotton_todo_recurrences (id, workspace_id, title, priority, rrule, dtstart, paused, materialized_until, created_at, updated_at) VALUES ('{SERIES}', '$WS', 'Walk', 0, 'FREQ=DAILY', '2026-11-17T08:00:00.000Z', 0, '2026-11-18T08:00:00.000Z', '2026-11-01T00:00:00.000Z', '2026-11-01T00:00:00.000Z')")); sql(handle, &format!("INSERT INTO cotton_todos (id, workspace_id, title, status, due_at, recurrence_id, occurrence_at, created_at, updated_at) VALUES ('00000000-0000-4000-8000-000000000018', '$WS', 'Walk', 'open', '2026-11-18T08:00:00.000Z', '{SERIES}', '2026-11-18T08:00:00.000Z', '2026-11-18T00:00:00.000Z', '2026-11-18T00:00:00.000Z')"));}fn change(handle: &CottonHandle, id: &str, fields: Value) {letmut request = json!({ "table": "todo", "id": id, "timezone": ZONE, "today": TODAY });for (key, value) in fields.as_object().unwrap() { request[key] = value.clone(); } ask(handle, "days.change", request);}/// RULE (DECISIONS.md, a move sticks, 21 Nov 2026): a to-do brought onto today from an earlier day ("from 25 Oct") moved to a later day is on that day and no longer late, however it is read again; moved back to today it is today's own. A to-do with a time keeps it when only its day changes, and `time: null` clears it.#[test]fn a_carried_todo_moved_to_another_day_stays_there_and_is_no_longer_late() {let dir = TempDir::new().unwrap();let handle = phone(&dir); zone(&handle);// Midnight in London on 25 Oct (still summer time) is 23:00 the day before in UTC: a day with no time. todo_in(&handle, "00000000-0000-4000-8000-0000000000f1", "Renew the forms", Some("2026-10-24T23:00:00.000Z")); todo_in(&handle, "00000000-0000-4000-8000-0000000000f4", "Call the plumber", Some("2026-11-12T09:30:00.000Z"));// Late, both are on today "from" their day, the oldest first (a late one shows no time). assert_eq!(lines(&span(&handle, TODAY, TODAY)), ["2026-11-20: ○ Renew the forms from 25 Oct | ○ Call the plumber from 12 Nov"]); change(&handle, "00000000-0000-4000-8000-0000000000f1", json!({ "day": "2026-11-23" })); change(&handle, "00000000-0000-4000-8000-0000000000f4", json!({ "day": "2026-11-24" }));for _ in0..2 { assert_eq!( lines(&span(&handle, TODAY, "2026-11-24")), ["2026-11-20: ", "21 – 22 · two quiet days", "2026-11-23: ○ Renew the forms", "2026-11-24: 9:30 ○ Call the plumber"], ); }let item = ask(&handle, "days.item", json!({ "table": "todo", "id": "00000000-0000-4000-8000-0000000000f4", "timezone": ZONE, "today": TODAY })); assert_eq!((item["day"].as_str(), item["time"].as_str()), (Some("2026-11-24"), Some("9:30")));// Today, by the quick choice: today's own, with no "from". change(&handle, "00000000-0000-4000-8000-0000000000f1", json!({ "day": TODAY })); change(&handle, "00000000-0000-4000-8000-0000000000f4", json!({ "day": "2026-11-24", "time": null })); assert_eq!(lines(&span(&handle, TODAY, TODAY)), ["2026-11-20: ○ Renew the forms"]);let item = ask(&handle, "days.item", json!({ "table": "todo", "id": "00000000-0000-4000-8000-0000000000f4", "timezone": ZONE, "today": TODAY })); assert_eq!(item["time"], Value::Null);}/// RULE (DECISIONS.md, a move sticks, 21 Nov 2026): moving one copy of a repeating to-do moves that copy only: the late walk moved to Monday is on Monday and not on today, the series makes no other copy beside it when it is next passed over, and done there, its next comes from the rhythm.#[test]fn moving_one_copy_of_a_repeating_todo_moves_that_copy_only() {let dir = TempDir::new().unwrap();let handle = phone(&dir); zone(&handle); late_walk(&handle); assert_eq!(lines(&span(&handle, TODAY, TODAY)), ["2026-11-20: ○ Walk from Wed"]); change(&handle, "00000000-0000-4000-8000-000000000018", json!({ "day": "2026-11-23" }));// The phone's foreground pass over the series (the materializer) leaves it be. handle.client().write_rows("test", &mut |ctx| {super::advance_series(ctx, SERIES, ZONE).map_err(|e| e.message)?;Ok(Value::Null) }).unwrap(); assert_eq!(lines(&span(&handle, TODAY, "2026-11-23")), ["2026-11-20: ", "21 – 22 · two quiet days", "2026-11-23: 8:00 ○ Walk"]); assert_eq!(all(&handle, &format!("SELECT status FROM cotton_todos WHERE recurrence_id = '{SERIES}' AND trashed_at IS NULL")), ["open"]);// The copy keeps its moment in the series; only its day moved. assert_eq!(one(&handle, "SELECT occurrence_at FROM cotton_todos WHERE id = '00000000-0000-4000-8000-000000000018'").as_deref(), Some("2026-11-18T08:00:00.000Z"));}fn span_with(handle: &CottonHandle, from: &str, to: &str, extra: Value) -> Value {letmut request = json!({ "timezone": ZONE, "today": TODAY, "from": from, "to": to });for (key, value) in extra.as_object().unwrap() { request[key] = value.clone(); } ask(handle, "days.span", request)}/// RULE (DECISIONS.md, nothing moves at the moment a person acts, 21 Nov 2026): a to-do ticked done stays exactly where it stood, struck through, while the phone keeps it (a late one on today, a future one on its own day, a repeating one with no next copy beside it), and unticked there it is open where it stood; let go, a done one is on the day it was done and the repeating one's next stands. Unticking a repeating one puts back the untouched next copy its tick made, so there is one live copy.#[test]fn a_tick_leaves_the_row_where_it_stood_until_the_list_is_opened_again() {let dir = TempDir::new().unwrap();let handle = phone(&dir); zone(&handle); late_walk(&handle); todo_in(&handle, "00000000-0000-4000-8000-0000000000f1", "Renew the forms", Some("2026-10-25T00:00:00.000Z")); todo_in(&handle, "00000000-0000-4000-8000-0000000000f2", "Order the cake", Some("2026-11-24T00:00:00.000Z")); todo_in(&handle, "00000000-0000-4000-8000-0000000000f3", "Learn the guitar", None);let before = lines(&span(&handle, TODAY, "2026-11-24")); assert_eq!(before, ["2026-11-20: ○ Renew the forms from 25 Oct | ○ Walk from Wed", "21 – 23 · three quiet days", "2026-11-24: ○ Order the cake"]);for id in ["00000000-0000-4000-8000-0000000000f1", "00000000-0000-4000-8000-000000000018", "00000000-0000-4000-8000-0000000000f2", "00000000-0000-4000-8000-0000000000f3"] { ask(&handle, "days.done", json!({ "id": id, "timezone": ZONE })); }let keep = json!({ "keep": [ { "id": "00000000-0000-4000-8000-0000000000f1", "day": TODAY }, { "id": "00000000-0000-4000-8000-000000000018", "day": TODAY }, { "id": "00000000-0000-4000-8000-0000000000f2", "day": "2026-11-24" }, { "id": "00000000-0000-4000-8000-0000000000f3", "day": null }, ] });let held = lines(&span_with(&handle, TODAY, "2026-11-24", keep.clone())); assert_eq!(held, ["2026-11-20: ✓ Renew the forms from 25 Oct | ✓ Walk from Wed", "21 – 23 · three quiet days", "2026-11-24: ✓ Order the cake"]);letmut sometime = json!({ "timezone": ZONE, "today": TODAY }); sometime["keep"] = keep["keep"].clone();let groups = ask(&handle, "days.sometime", sometime); assert_eq!(groups["groups"][0]["rows"][0]["done"], json!(true), "{groups}");// Unticked where it stood. ask(&handle, "days.undone", json!({ "id": "00000000-0000-4000-8000-0000000000f2" })); ask(&handle, "days.undone", json!({ "id": "00000000-0000-4000-8000-000000000018" }));let held = lines(&span_with(&handle, TODAY, "2026-11-24", keep)); assert_eq!(held, ["2026-11-20: ✓ Renew the forms from 25 Oct | ○ Walk from Wed", "21 – 23 · three quiet days", "2026-11-24: ○ Order the cake"]); assert_eq!(all(&handle, &format!("SELECT status FROM cotton_todos WHERE recurrence_id = '{SERIES}' AND trashed_at IS NULL")), ["open"]);// Let go: a done to-do is on the day it was done (today, by the clock of this run).let after = span(&handle, TODAY, "2026-11-24"); assert!(!lines(&after).iter().any(|line| line.contains("✓ Renew the forms from")), "{after}");let sometime = ask(&handle, "days.sometime", json!({ "timezone": ZONE, "today": TODAY })); assert_eq!(sometime["groups"], json!([]), "{sometime}");}/// RULE (DECISIONS.md, never two folds in a row and the list ends, 21 Nov 2026): a fold at either end of a span is the whole quiet run, past the asked days, so pieces read one after another never show two folds in a row; when nothing lies ahead the answer ends on the last day with a row with "Nothing else planned.", and with a group "Nothing else in <name>." (owner, 21 Nov 2026); when nothing lies before, it begins on the first.#[test]fn a_quiet_run_is_one_fold_and_the_list_ends_after_its_last_item() {let dir = TempDir::new().unwrap();let handle = phone(&dir); zone(&handle); todo_in(&handle, "00000000-0000-4000-8000-0000000000d1", "Post the letter", Some("2026-11-22T00:00:00.000Z")); todo_in(&handle, "td-b", "Pay the rent", Some("2027-02-01T00:00:00.000Z"));// Midnight in London in June is 23:00 the day before in UTC: a day with no time. todo_in(&handle, "td-c", "Book the dentist", Some("2028-05-31T23:00:00.000Z")); sql(&handle, "INSERT INTO cotton_todos (id, workspace_id, title, status, due_at, completed_at, created_at, updated_at) VALUES ('td-old', '$WS', 'Wrote the plan', 'done', NULL, '2026-09-01T10:00:00.000Z', '2026-09-01T00:00:00.000Z', '2026-09-01T00:00:00.000Z')");// Read in pieces of 62 days, as the iPhone does: the quiet run from 23 Nov to 31 Jan is one fold in each piece.let first = span(&handle, TODAY, "2026-12-20");let second = span(&handle, "2026-12-21", "2027-02-20");let a = lines(&first);let b = lines(&second); assert_eq!(a.last().map(String::as_str), Some("23 Nov 2026 – 31 Jan 2027 · 70 quiet days"), "{first}"); assert_eq!(b.first().map(String::as_str), Some("23 Nov 2026 – 31 Jan 2027 · 70 quiet days"), "{second}"); assert_eq!(first["days"].as_array().unwrap().last().unwrap()["fold"]["to"], json!("2027-01-31"));// From 2 Feb 2027 to the dentist in June 2028: one fold, however far. assert_eq!(b.last().map(String::as_str), Some("2 Feb 2027 – 31 May 2028 · 485 quiet days"), "{second}"); assert_eq!(second["days"].as_array().unwrap().last().unwrap()["fold"]["to"], json!("2028-05-31"), "{second}"); assert!(second.get("end").is_none());// After the dentist, the list ends.let last = span(&handle, "2028-05-01", "2028-07-01"); assert_eq!(lines(&last).last().map(String::as_str), Some("2028-06-01: ○ Book the dentist"), "{last}"); assert_eq!(last["end"], json!({ "after": "2028-06-01", "words": "Nothing else planned." }));let beyond = span(&handle, "2028-07-02", "2028-09-01"); assert_eq!(beyond["days"], json!([])); assert_eq!(beyond["end"]["after"], json!("2028-06-01"));// Before the first thing ever, the list begins.let past = span(&handle, "2026-08-01", "2026-09-30"); assert_eq!(past["begins"], json!("2026-09-01"), "{past}"); assert_eq!(lines(&past).first().map(String::as_str), Some("2026-09-01: ✓ Wrote the plan"));// A group with nothing after today. ask(&handle, "days.change", json!({ "table": "todo", "id": "00000000-0000-4000-8000-0000000000d1", "day": TODAY, "timezone": ZONE }));let made = ask(&handle, "groups.create", json!({ "table": "todo", "name": "Home", "records": ["00000000-0000-4000-8000-0000000000d1"] }));let home_id = made["id"].as_str().or_else(|| made["group"]["id"].as_str()).expect("a group id").to_string();let home = span_with(&handle, TODAY, "2026-12-20", json!({ "group": home_id })); assert_eq!(lines(&home), ["2026-11-20: ○ Post the letter"], "{home}"); assert_eq!(home["end"]["words"], json!("Nothing else in Home."));}/// RULE (DECISIONS.md, the sheet carries everything, 21 Nov 2026): the sheet's quick day row is Today, Tomorrow, Next week (Monday) and, for a to-do, Sometime; Drop keeps a to-do under Dropped (a repeating one's series stops) and Bring back opens it again; Delete puts it in the bin (a repeating one's series with it); a Google event cannot be deleted here.#[test]fn the_sheet_moves_drops_brings_back_and_deletes() {let dir = TempDir::new().unwrap();let handle = phone(&dir); zone(&handle); late_walk(&handle); todo_in(&handle, "00000000-0000-4000-8000-0000000000f1", "Renew the forms", Some("2026-11-21T00:00:00.000Z"));let item = ask(&handle, "days.item", json!({ "table": "todo", "id": "00000000-0000-4000-8000-0000000000f1", "timezone": ZONE, "today": TODAY })); assert_eq!( item["choices"], json!([{ "key": "today", "day": "2026-11-20" }, { "key": "tomorrow", "day": "2026-11-21" }, { "key": "next_week", "day": "2026-11-23" }, { "key": "sometime", "day": null }]) ); ask(&handle, "days.drop", json!({ "id": "00000000-0000-4000-8000-0000000000f1" })); ask(&handle, "days.drop", json!({ "id": "00000000-0000-4000-8000-000000000018" })); assert_eq!(lines(&span(&handle, TODAY, TODAY)), ["2026-11-20: "]);let show = ask(&handle, "days.show", json!({ "view": "dropped", "timezone": ZONE, "today": TODAY }));let titles: Vec<&str> = show["rows"].as_array().unwrap().iter().map(|r| r["words"].as_str().unwrap()).collect(); assert_eq!(titles.len(), 2, "{show}"); assert!(show["rows"].as_array().unwrap().iter().all(|r| r["dropped"] == json!(true))); assert_eq!(one(&handle, &format!("SELECT paused FROM cotton_todo_recurrences WHERE id = '{SERIES}'")).as_deref(), Some("1")); ask(&handle, "days.bring_back", json!({ "id": "00000000-0000-4000-8000-000000000018" })); assert_eq!(lines(&span(&handle, TODAY, TODAY)), ["2026-11-20: ○ Walk from Wed"]); assert_eq!(one(&handle, &format!("SELECT paused FROM cotton_todo_recurrences WHERE id = '{SERIES}'")).as_deref(), Some("0")); ask(&handle, "days.delete", json!({ "table": "todo", "id": "00000000-0000-4000-8000-000000000018" })); assert_eq!(lines(&span(&handle, TODAY, TODAY)), ["2026-11-20: "]); assert_eq!(all(&handle, &format!("SELECT id FROM cotton_todos WHERE recurrence_id = '{SERIES}' AND trashed_at IS NULL")), Vec::<String>::new()); sql(&handle, "INSERT INTO cotton_events (id, title, starts_at, ends_at, all_day, gcal_id, created_at, updated_at) VALUES ('00000000-0000-4000-8000-0000000000e1', 'Team call', '2026-11-20T10:00:00.000Z', '2026-11-20T11:00:00.000Z', 0, 'g-1', '2026-11-01T00:00:00.000Z', '2026-11-01T00:00:00.000Z')");// A Google event with no Google calendar connected cannot be deleted here (CONTRACT.md section 16).crate::phone::days_people::Heard::google(&handle.client(), &json!({ "available": true, "accounts": [] }));let (code, _) = refused(&handle, "days.delete", json!({ "table": "event", "id": "00000000-0000-4000-8000-0000000000e1" })); assert_eq!(code, "google_read_only");}/// RULE (DECISIONS.md, Show, 21 Nov 2026): Late is every open to-do from before today, oldest first, each with its day; Repeating is each repeating item once with its rhythm in words and its next day; Done is newest first, a page at a time; each view says its own line when empty.#[test]fn the_four_views_answer_late_repeating_dropped_and_done() {let dir = TempDir::new().unwrap();let handle = phone(&dir); zone(&handle);let show = |view: &str, extra: Value| {letmut request = json!({ "view": view, "timezone": ZONE, "today": TODAY });for (k, v) in extra.as_object().unwrap() { request[k] = v.clone(); } ask(&handle, "days.show", request) };for view in ["late", "repeating", "dropped", "done"] { assert_eq!(show(view, json!({}))["rows"], json!([])); } assert_eq!(show("late", json!({}))["empty"], json!("Nothing late.")); assert_eq!(show("done", json!({}))["empty"], json!("Nothing done yet.")); late_walk(&handle); todo_in(&handle, "00000000-0000-4000-8000-0000000000f1", "Renew the forms", Some("2025-10-25T00:00:00.000Z")); todo_in(&handle, "00000000-0000-4000-8000-0000000000f5", "Order printer ink", Some("2026-11-19T00:00:00.000Z")); todo_in(&handle, "00000000-0000-4000-8000-0000000000f2", "Order the cake", Some("2026-11-24T00:00:00.000Z"));let late = show("late", json!({}));let said: Vec<String> = late["rows"].as_array().unwrap().iter().map(|r| format!("{} {}", r["dayWords"].as_str().unwrap(), r["words"].as_str().unwrap())).collect(); assert_eq!(said, ["25 Oct 2025 Renew the forms", "Wed 18 Nov Walk", "Thu 19 Nov Order printer ink"], "{late}"); sql(&handle, "INSERT INTO cotton_events (id, title, starts_at, ends_at, all_day, rrule, created_at, updated_at) VALUES ('00000000-0000-4000-8000-0000000000e2', 'Choir', '2026-11-02T19:00:00.000Z', '2026-11-02T21:00:00.000Z', 0, 'FREQ=WEEKLY;BYDAY=MO', '2026-11-01T00:00:00.000Z', '2026-11-01T00:00:00.000Z')");let repeating = show("repeating", json!({}));let said: Vec<String> = repeating["rows"].as_array().unwrap().iter().map(|r| format!("{} · {} · {}", r["words"].as_str().unwrap(), r["rhythm"].as_str().unwrap(), r["dayWords"].as_str().unwrap())).collect(); assert_eq!(said, ["Walk · Every day · Wed 18 Nov", "Choir · Every Monday · Mon 23 Nov"], "{repeating}");for n in0..5 { sql(&handle, &format!("INSERT INTO cotton_todos (id, workspace_id, title, status, completed_at, created_at, updated_at) VALUES ('td-done-{n}', '$WS', 'Done thing {n}', 'done', '2026-11-1{n}T10:00:00.000Z', '2026-11-01T00:00:00.000Z', '2026-11-01T00:00:00.000Z')")); }let page = show("done", json!({ "limit": 3 }));let titles: Vec<&str> = page["rows"].as_array().unwrap().iter().map(|r| r["words"].as_str().unwrap()).collect(); assert_eq!(titles, ["Done thing 4", "Done thing 3", "Done thing 2"]);let rest = show("done", json!({ "limit": 3, "after": page["next"] }));let titles: Vec<&str> = rest["rows"].as_array().unwrap().iter().map(|r| r["words"].as_str().unwrap()).collect(); assert_eq!(titles, ["Done thing 1", "Done thing 0"]); assert_eq!(rest["next"], Value::Null);}/// RULE (DECISIONS.md, search, 21 Nov 2026): days.find answers everything whose title or note holds every typed word, any script, case and accents aside: Coming (today on, soonest first, then Sometime) and Before (newest first), done ones struck, dropped ones marked and landing under Dropped; nothing found says so with the words.#[test]fn search_finds_titles_and_notes_coming_and_before() {let dir = TempDir::new().unwrap();let handle = phone(&dir); zone(&handle); todo_in(&handle, "td-1", "Call the Dentist", Some("2026-11-25T00:00:00.000Z")); todo_in(&handle, "td-2", "Pay the bill", None); sql(&handle, "UPDATE cotton_todos SET notes = 'ask the dentist about it' WHERE id = 'td-2'"); sql(&handle, "INSERT INTO cotton_todos (id, workspace_id, title, status, due_at, completed_at, created_at, updated_at) VALUES ('td-3', '$WS', 'Dentist forms', 'done', '2026-11-10T00:00:00.000Z', '2026-11-12T10:00:00.000Z', '2026-11-01T00:00:00.000Z', '2026-11-01T00:00:00.000Z'), ('td-4', '$WS', 'Dentist, the second', 'dropped', '2026-11-05T00:00:00.000Z', NULL, '2026-11-01T00:00:00.000Z', '2026-11-01T00:00:00.000Z'), ('td-5', '$WS', 'दाँत का डॉक्टर', 'open', '2026-11-21T00:00:00.000Z', NULL, '2026-11-01T00:00:00.000Z', '2026-11-01T00:00:00.000Z'), ('td-6', '$WS', 'Café with Rose', 'open', '2026-11-22T00:00:00.000Z', NULL, '2026-11-01T00:00:00.000Z', '2026-11-01T00:00:00.000Z')"); sql(&handle, "INSERT INTO cotton_events (id, title, starts_at, ends_at, all_day, created_at, updated_at) VALUES ('00000000-0000-4000-8000-0000000000e3', 'Dentist', '2026-11-03T09:00:00.000Z', '2026-11-03T09:30:00.000Z', 0, '2026-11-01T00:00:00.000Z', '2026-11-01T00:00:00.000Z')");let find = |words: &str| ask(&handle, "days.find", json!({ "words": words, "timezone": ZONE, "today": TODAY }));let found = find("DENTIST");let said = |part: &Value| -> Vec<String> { part.as_array().unwrap().iter().map(|r| format!("{} {}{}", r["dayWords"].as_str().unwrap(), r["words"].as_str().unwrap(), if r["done"] == json!(true) { " ✓" } elseif r.get("dropped").is_some() { " (dropped)" } else { "" })).collect() }; assert_eq!(said(&found["coming"]), ["Wed 25 Nov Call the Dentist", "Sometime Pay the bill"], "{found}"); assert_eq!(said(&found["before"]), ["Thu 12 Nov Dentist forms ✓", "Thu 5 Nov Dentist, the second (dropped)", "Tue 3 Nov Dentist"], "{found}"); assert_eq!(found["before"][1]["lands"], json!({ "place": "show", "view": "dropped" })); assert_eq!(found["coming"][1]["lands"], json!({ "place": "sometime" })); assert_eq!(found["coming"][0]["lands"], json!({ "place": "days", "day": "2026-11-25" })); assert_eq!(said(&find("डॉक्टर")["coming"]), ["Sat 21 Nov दाँत का डॉक्टर"]); assert_eq!(said(&find("cafe rose")["coming"]), ["Sun 22 Nov Café with Rose"]); assert_eq!(find("zebra")["empty"], json!("Nothing found for “zebra”."));}/// RULE (CONTRACT.md section 12): search is fast on the phone's own copy: twenty thousand invented to-dos answer in well under a second in a release build (this debug run allows two).#[test]fn search_is_fast_on_twenty_thousand_items() {let dir = TempDir::new().unwrap();let handle = phone(&dir); zone(&handle); handle .client() .with_writer(|replica| {let ws = replica.workspace_id.to_string(); replica.driver.run("BEGIN", &[]).map_err(|e| e.to_string())?;for n in0..20_000 {let day = 1 + n % 28; replica .driver .run( &format!("INSERT INTO cotton_todos (id, workspace_id, title, status, due_at, created_at, updated_at) VALUES ('td-{n}', '{ws}', 'Invented errand {n} at the shop', 'open', '2027-02-{day:02}T00:00:00.000Z', '2026-11-01T00:00:00.000Z', '2026-11-01T00:00:00.000Z')"), &[], ) .map_err(|e| e.to_string())?; } replica.driver.run("COMMIT", &[]).map_err(|e| e.to_string()) }) .expect("twenty thousand land");let started = std::time::Instant::now();let found = ask(&handle, "days.find", json!({ "words": "errand 1999", "timezone": ZONE, "today": TODAY }));let took = started.elapsed();// "errand" and "1999" are each found: 1999, 11999, and 19990 to 19999. assert_eq!(found["coming"].as_array().unwrap().len(), 12); println!("days.find over twenty thousand to-dos took {took:?}"); assert!(took < std::time::Duration::from_secs(2), "search took {took:?}");}