//! The kit's packages travel as data: export, import and export again are the //! same bytes. mod support; use base64::{engine::general_purpose::STANDARD, Engine}; use serde_json::json; use support::{ mcp::{call_tool, mint_token}, Harness, }; /// One kit tool as this database exports it, unsigned, so two exports compare /// byte for byte. fn exported(h: &Harness, id: &str) -> Vec { let package = cotton_tools::tool_export::package(&h.db, &h.workspace_id, id).expect("the tool exports"); cotton_core::definitions::package::encode_unsigned_package(&package).expect("the package encodes") } /// The kit tools a package of views alone reads: every kit package that /// carries tables, added first (Artifacts reads Documents' document). fn add_its_tables(h: &Harness, token: &str, id: &str) { let package = cotton_core::kit::package(id).expect("a kit tool").expect("the kit decodes").package; if !package.tables.is_empty() { return; } for other in cotton_core::kit::ids() { let carries = cotton_core::kit::package(other).expect("a kit tool").expect("the kit decodes").package.tables; if other != id && !carries.is_empty() { call_tool(h, token, "add_tool", json!({"tool_id": other})); } } } /// RULE (72nd amendment, 21 Oct 2026: tools are records only): every kit /// package round-trips export → import → export byte-equal. A tool is data a /// database holds; if a field were lost or rewritten on the way through a /// database, a tool shared from one database would arrive as a different tool /// in the next, and the kit would drift from what any database holds. #[test] fn every_kit_package_round_trips_export_import_byte_equal() { for id in cotton_core::kit::ids() { let mut first = Harness::bare(); let token = mint_token(&mut first, &["read", "write"], "Synthetic exporter"); add_its_tables(&first, &token, id); let added = call_tool(&first, &token, "add_tool", json!({"tool_id": id})); assert_eq!(added["added"], true, "{id}: {added}"); let once = exported(&first, id); let mut second = Harness::bare(); let token = mint_token(&mut second, &["read", "write"], "Synthetic importer"); add_its_tables(&second, &token, id); let imported = call_tool(&second, &token, "import_tool", json!({"bytes": STANDARD.encode(&once)})); assert!(imported.get("error").is_none(), "{id}: {imported}"); let twice = exported(&second, id); assert!(once == twice, "{id}: the package changed on its way through a database"); } } /// RULE (owner, 21 Oct 2026): the kit is the one folder of packages — the /// eight, Documents and Artifacts. Artifacts (Web pages) carries its own table /// since 5 Nov 2026 (`page`, the links a person shares), so it installs on its /// own; its Made for you view reads Documents' HTML rows once Documents is in. #[test] fn the_kit_holds_documents_and_artifacts_and_artifacts_carries_its_own_table() { for id in ["documents", "artifacts"] { assert!(cotton_core::kit::ids().contains(&id), "{id} is a kit package"); } let mut alone = Harness::bare(); let token = mint_token(&mut alone, &["read", "write"], "Synthetic adder"); let added = call_tool(&alone, &token, "add_tool", json!({"tool_id": "artifacts"})); assert_eq!(added["added"], true, "{added}"); let read = call_tool(&alone, &token, "list_records", json!({"table": "page", "view": "artifacts/all"})); assert!(read["records"].is_array(), "Web pages reads its own links: {read}"); }