//! A todo is a record like any other: delete_record puts it in the Bin, Undo //! and restore_from_bin bring it back, and while it waits there no todo read //! lists it (owner's todo sweep, 15 Oct 2026). Driven end to end through the //! dispatcher. //! //! Every value is invented ([nothing-real-ever-goes-in-cotton-s-public-tree]). mod support; use serde_json::json; use support::harness::{synthetic_uuid, Harness}; use support::mcp::{call_tool, call_tool_raw, mint_token}; fn listed(h: &Harness, secret: &str, id: &str) -> bool { let todos = call_tool(h, secret, "list_todos", json!({})); todos["todos"].as_array().expect("a list").iter().any(|todo| todo["id"] == id) } fn binned(h: &Harness, secret: &str, id: &str) -> bool { let bin = call_tool(h, secret, "list_bin", json!({ "kind": "todo" })); bin.to_string().contains(id) } /// RULE: A todo list_todos lists is deleted by delete_record into the Bin — gone from list_todos, waiting in list_bin, brought back by Undo and by restore_from_bin — because a todo is a definition-kind table like any other and a delete that refuses one leaves the person no way to remove it; "no longer here" is answered only for an id no table holds. #[test] fn a_listed_todo_is_deleted_into_the_bin_and_restored() { let mut h = Harness::new(); let secret = mint_token(&mut h, &["read", "write"], "Claude"); let made = call_tool(&h, &secret, "create_todo", json!({ "title": "Water the invented fern" })); let id = made["id"].as_str().expect("the todo's id").to_string(); assert!(listed(&h, &secret, &id)); let gone = call_tool(&h, &secret, "delete_record", json!({ "table": "todo", "id": id })); assert_eq!(gone["change"]["undoable"], true, "{gone}"); assert!(!listed(&h, &secret, &id), "list_todos still lists a binned todo"); assert!(binned(&h, &secret, &id), "the bin does not hold the deleted todo"); call_tool(&h, &secret, "undo", json!({ "change_id": gone["change"]["id"] })); assert!(listed(&h, &secret, &id) && !binned(&h, &secret, &id), "Undo did not bring the todo back"); call_tool(&h, &secret, "delete_record", json!({ "table": "todo", "id": id })); let back = call_tool(&h, &secret, "restore_from_bin", json!({ "kind": "todo", "id": id })); assert_eq!(back["restored"], true, "{back}"); assert!(listed(&h, &secret, &id) && !binned(&h, &secret, &id), "restore_from_bin did not bring the todo back"); let nowhere = synthetic_uuid("a todo no table holds"); let refused = call_tool_raw(&h, &secret, "delete_record", json!({ "table": "todo", "id": nowhere })); assert!(refused.is_error && refused.text.contains("no longer here"), "{}", refused.text); }