//! A database with no tool at all is a whole database. mod support; use serde_json::json; use support::{ mcp::{call_tool, call_tool_raw, mint_token}, Harness, }; /// RULE (72nd amendment, 21 Oct 2026: tools are records only; the architect's /// meaning, 21 Oct): a database with zero tools opens, lists and syncs — zero /// package records, with the shell's board and theme rows present. No tool is /// built in, so a database nobody imported a tool into is an ordinary state, /// not a broken one: its tools list is empty, a read of a table no tool draws /// answers the typed `no_tool_draws_this_table` refusal (never a fallback to a /// shipped definition), and a write to its Home board reaches a peer. If this /// broke, every new database — which holds no tool until one is imported — /// would fail to open, to list or to sync. #[test] fn a_database_with_zero_tools_opens_lists_and_syncs() { let mut h = Harness::bare(); // What creation writes: the shell and nothing else. cotton_tools::presentation::write_shell(&h.db, chrono::Utc::now(), h.random.clone(), cotton_store::mint::Held::Served) .expect("the shell writes"); for table in ["cotton_tool_definitions", "cotton_toolkits"] { assert_eq!(h.count(&format!("SELECT COUNT(*) AS n FROM {table}"), &[]), 0, "no {table} row"); } assert_eq!(h.count("SELECT COUNT(*) AS n FROM cotton_board_definitions WHERE id = 'home'", &[]), 1, "Home's board"); assert_eq!(h.count("SELECT COUNT(*) AS n FROM cotton_theme_definitions WHERE id IN ('paper', 'plain')", &[]), 2, "the themes"); let token = mint_token(&mut h, &["read", "write"], "Synthetic assistant"); let tools = call_tool(&h, &token, "list_tools", json!({})); assert_eq!(tools["tools"], json!([]), "{tools}"); let refused = call_tool_raw(&h, &token, "list_records", json!({"table": "todo"})); assert!(refused.is_error, "{}", refused.text); assert!( refused.text.contains(cotton_core::definitions::NO_TOOL_DRAWS_THIS_TABLE) || refused.text.contains(&cotton_core::definitions::no_tool_draws_this_table(&[])), "{}", refused.text ); let board = call_tool(&h, &token, "get_board", json!({"id": "home"})); assert!(board.get("error").is_none(), "Home's board reads: {board}"); let before = h.cursors(); let written = call_tool( &h, &token, "update_board", json!({"id": "home", "definition": {"id": "home", "parts": [{"kind": "tools", "face": "grid"}]}}), ); assert!(written.get("error").is_none(), "{written}"); let handed = h.ops_since(&before); assert!(handed.iter().any(|op| op["tbl"] == "cotton_board_definitions"), "the write reaches a peer: {handed:?}"); }