//! A Home's `list` and `figure` parts as the phone reads them: a list kept to//! a stretch of days by its table's own date (`list_records`' `period`), and//! a figure said in the part's own words (`tool_figures::part_line`). Every//! row here is synthetic.mod support;use serde_json::{json, Value};use support::{ mcp::{call_tool, call_tool_raw, mint_token},Harness,};const TODAY: &str = "2026-10-19";fn create(h: &Harness, token: &str, table: &str, data: Value) -> String { call_tool(h, token, "create_record", json!({"table": table, "data": data}))["record"]["id"].as_str().unwrap().to_string()}fn yoga(h: &mutHarness) -> String {let token = mint_token(h, &["read", "write"], "Business"); assert_eq!(call_tool(h, &token, "add_tool", json!({"tool_id": "yoga"}))["added"], true);let class = create(h, &token, "yoga_class", json!({"name": "Synthetic hatha", "capacity": 10})); create(h, &token, "yoga_session", json!({"name": "Synthetic hatha, today", "class": class, "on": TODAY})); create(h, &token, "yoga_session", json!({"name": "Synthetic hatha, tomorrow", "class": class, "on": "2026-10-20"})); create(h, &token, "yoga_session", json!({"name": "Synthetic hatha, next month", "class": class, "on": "2026-11-20"}));let member = create(h, &token, "yoga_member", json!({"name": "Synthetic Member", "currency": "XTS"})); create(h, &token, "yoga_payment", json!({"name": "Cash", "member": member, "amount": 200000, "currency": "XTS", "method": "cash", "taken_on": TODAY})); create(h, &token, "yoga_payment", json!({"name": "UPI", "member": member, "amount": 90000, "currency": "XTS", "method": "upi", "taken_on": TODAY})); create(h, &token, "yoga_payment", json!({"name": "Cash yesterday", "member": member, "amount": 70000, "currency": "XTS", "method": "cash", "taken_on": "2026-10-18"})); token}fn names(answer: &Value) -> Vec<String> { answer["records"].as_array().unwrap().iter().map(|record| record["data"]["name"].as_str().unwrap().to_string()).collect()}// RULE: a list part's `period` keeps the rows whose own date falls in that stretch from the person's day — today alone, or today and the six after — and a list with no period keeps every row; a period on a built-in table, or with no day to read it from, is refused by name rather than ignored.#[test]fn a_list_keeps_its_period_by_the_tables_own_date() {letmut h = Harness::new();let token = yoga(&mut h);let list = |args: Value| call_tool(&h, &token, "list_records", args); assert_eq!(names(&list(json!({"table": "yoga_session", "period": "today", "today": TODAY}))), ["Synthetic hatha, today"]);let week = names(&list(json!({"table": "yoga_session", "period": "next_7_days", "today": TODAY}))); assert_eq!(week.len(), 2, "{week:?}"); assert_eq!(names(&list(json!({"table": "yoga_session", "today": TODAY}))).len(), 3);let builtin = call_tool_raw(&h, &token, "list_records", json!({"table": "todo", "period": "today", "today": TODAY})); assert!(builtin.is_error && builtin.text.contains("not read by period"), "{}", builtin.text);let dayless = call_tool_raw(&h, &token, "list_records", json!({"table": "yoga_session", "period": "today"})); assert!(dayless.is_error && dayless.text.contains("say today"), "{}", dayless.text);}// RULE: `next_day` keeps the first day after the person's own that holds any of the list's rows — a studio's next class day, "Monday" read on a Friday — and a list with no later row keeps nothing.#[test]fn a_list_keeps_its_next_day_by_the_rows_it_holds() {letmut h = Harness::new();let token = yoga(&mut h);let list = |args: Value| call_tool(&h, &token, "list_records", args); assert_eq!(names(&list(json!({"table": "yoga_session", "period": "next_day", "today": TODAY}))), ["Synthetic hatha, tomorrow"]); assert_eq!(names(&list(json!({"table": "yoga_session", "period": "next_day", "today": "2026-10-20"}))), ["Synthetic hatha, next month"]); assert!(names(&list(json!({"table": "yoga_session", "period": "next_day", "today": "2026-11-20"}))).is_empty());}// RULE: a figure part is worked out and said as a tool card's figure is — its `where` and `period` keep the rows, `many` carries the total for {n}, and a total of nothing says nothing.#[test]fn a_figure_part_says_its_total_in_its_own_words() {letmut h = Harness::new(); yoga(&mut h);let today = chrono::NaiveDate::parse_from_str(TODAY, "%Y-%m-%d").unwrap();let cash = json!({"kind": "figure", "heading": "Cash taken today", "table": "yoga_payment", "op": "sum", "column": "amount","where": {"method": "cash"}, "period": "today", "many": "{n} in cash"});let line = h.with(|db| cotton_tools::tool_figures::part_line(db, &h.workspace_id, &cash, today)).unwrap().expect("a line"); assert!(line.ends_with(" in cash") && line.contains("2,000"), "{line}");let sessions = json!({"kind": "figure", "heading": "Sessions", "table": "yoga_session", "op": "count", "period": "today", "many": "{n} sessions", "one": "One session"}); assert_eq!(h.with(|db| cotton_tools::tool_figures::part_line(db, &h.workspace_id, &sessions, today)).unwrap().as_deref(), Some("One session"));let later = chrono::NaiveDate::parse_from_str("2026-12-01", "%Y-%m-%d").unwrap(); assert_eq!(h.with(|db| cotton_tools::tool_figures::part_line(db, &h.workspace_id, &cash, later)).unwrap(), None, "no cash that day: silence");}