//! `search_records` and `get_record` over `dispatch::call_tool`. //! //! Every case this group owns is here; a case for another group's tool belongs //! in that group's file. //! //! Every case drives the tool through `dispatch::call_tool` over a fake //! `ToolServices` rather than the `/v1/mcp` endpoint, so what is under test is //! the answer an assistant actually receives. The fixtures are folded the way a //! phone's push folds them, FTS triggers included: a search suite that INSERTed //! its rows would be testing an index nothing had ever written. mod support; use std::sync::atomic::{AtomicU64, Ordering}; use cotton_store::schema::ddl::SCHEMA_VERSION; use rusqlite::types::Value as SqlValue; use serde_json::{json, Value}; use support::harness::Harness; use support::mcp::{call_tool, call_tool_raw, mint_token}; /// When every seeded row says it was written. const AT: &str = "2026-08-22T10:00:00.000Z"; // ── the fixture ───────────────────────────────────────────────────────────── /// An op the way a device would mint one. The ids are DERIVED from a /// per-process counter, never random. fn op(table: &str, row_id: &str, patch: Value) -> Value { static NEXT: AtomicU64 = AtomicU64::new(0); let n = NEXT.fetch_add(1, Ordering::Relaxed); json!({ "opId": format!("01J{:023}", n), "deviceId": "device:seed", "kind": "upsert", "table": table, "rowId": row_id, "patch": patch, "hlc": format!("1700000000{:03}:0000:device:seed", n), "schemaVersion": SCHEMA_VERSION, }) } /// A uuid-shaped id a fixture can name. DERIVED, never random. fn fixture_id(label: &str) -> String { support::harness::synthetic_uuid(label) } /// One statement straight against the file — for the rows no MCP tool writes. fn run(h: &Harness, sql: &str, params: &[SqlValue]) { h.with(|db| db.run(sql, params)) .expect("the statement runs"); } fn kinds_of(result: &Value) -> Vec { result["records"] .as_array() .expect("records") .iter() .map(|hit| hit["kind"].as_str().unwrap_or_default().to_string()) .collect() } fn ids_of(result: &Value) -> Vec { result["records"] .as_array() .expect("records") .iter() .map(|hit| hit["id"].as_str().unwrap_or_default().to_string()) .collect() } fn hits_of<'a>(result: &'a Value, kind: &str) -> Vec<&'a Value> { result["records"] .as_array() .expect("records") .iter() .filter(|hit| hit["kind"] == *kind) .collect() } // ── the whole-file fixture: one "bali" per kind this suite asserts on ─────── struct WholeFile { h: Harness, secret: String, todo: String, done_todo: String, note: String, journal: String, thread: String, message: String, memory: String, } fn whole_file_harness() -> WholeFile { let mut h = Harness::new(); let secret = mint_token(&mut h, &["read", "write"], "Claude"); let todo = fixture_id("search-todo"); let done_todo = fixture_id("search-done-todo"); let note = fixture_id("search-note"); let journal = fixture_id("search-journal"); let contact = fixture_id("search-contact"); let thread = fixture_id("search-thread"); let message = fixture_id("search-message"); let txn = fixture_id("search-txn"); let goal = fixture_id("search-goal"); let memory = fixture_id("search-memory"); h.seed(&[ op( "cotton_todos", &todo, json!({ "title": "book bali flights", "status": "open", "priority": 0, "workspace_id": h.workspace_id, "created_at": AT, "updated_at": AT, }), ), op( "cotton_todos", &done_todo, json!({ "title": "bali visa forms", "status": "done", "priority": 0, "workspace_id": h.workspace_id, "created_at": AT, "updated_at": AT, }), ), op( "cotton_notes", ¬e, json!({ "title": "trip planning", "body": "the bali leg needs three nights in ubud", "kind": "note", "workspace_id": h.workspace_id, "created_at": AT, "updated_at": AT, }), ), op( "cotton_notes", &journal, json!({ "title": Value::Null, "body": "dreamt about bali again", "kind": "journal", "journal_date": "2026-08-21", "workspace_id": h.workspace_id, "created_at": AT, "updated_at": AT, }), ), op( "cotton_msg_contacts", &contact, json!({ "phone_e164": "911234562100", "display_name": "Bali Homestay", "workspace_id": h.workspace_id, "created_at": AT, "updated_at": AT, }), ), op( "cotton_msg_threads", &thread, json!({ "kind": "dm", "contact_id": contact, "archived": false, "last_message_at": AT, "workspace_id": h.workspace_id, "created_at": AT, "updated_at": AT, }), ), op( "cotton_msg_messages", &message, json!({ "thread_id": thread, "direction": "in", "channel": "cotton", "origin": "live", "body": "the bali pool villa is free that week", "sent_at": AT, "workspace_id": h.workspace_id, "created_at": AT, }), ), op( "cotton_money_transactions", &txn, json!({ "occurred_on": "2026-08-18", "description": "bali hotel deposit", "status": "actual", "amount_known": false, "amount_minor": Value::Null, "workspace_id": h.workspace_id, "created_at": AT, "updated_at": AT, }), ), op( "cotton_goals", &goal, json!({ "title": "Surf in bali", "why": "the one trip that is for me", "status": "achieved", "achieved_at": AT, "workspace_id": h.workspace_id, "created_at": AT, "updated_at": AT, }), ), op( "cotton_memories", &memory, json!({ "slug": "bali-rule", "title": "Bali stays a holiday, never a workation", "body": "", "status": "active", "machine": Value::Null, "visibility": "private", "origin_kind": "user", "origin_label": Value::Null, "source_external_id": Value::Null, "archived_at": Value::Null, "workspace_id": h.workspace_id, "created_at": AT, "updated_at": AT, }), ), ]); WholeFile { h, secret, todo, done_todo, note, journal, thread, message, memory, } } // ── search_records — the whole file ───────────────────────────────────────── #[test] fn answers_every_kind_from_one_query_with_totals() { let f = whole_file_harness(); let result = call_tool( &f.h, &f.secret, "search_records", json!({ "query": "bali" }), ); // The new kinds are findable at all — the point of the adoption. let kinds = kinds_of(&result); // The imported kit draws a transaction (Money carries its table) and a // memory (the kit's own tables), so both are found. for expected in ["todo", "note", "journal", "message", "thread", "transaction", "memory"] { assert!( kinds.iter().any(|kind| kind == expected), "no {expected} hit in {kinds:?}" ); } // A table no tool here draws answers no hit and no total. for undrawn in ["goal"] { assert!(!kinds.iter().any(|kind| kind == undrawn), "a {undrawn} hit in {kinds:?}"); assert!(result["totals"].get(undrawn).is_none(), "a {undrawn} total: {result}"); } // A message hit carries its thread and anchor for read_message_thread. let message = hits_of(&result, "message")[0]; assert_eq!(message["id"], Value::from(f.message.clone())); assert_eq!(message["threadId"], Value::from(f.thread.clone())); assert_eq!(message["sentAt"], AT); assert_eq!(message["title"], "Bali Homestay"); assert!( message["detail"] .as_str() .unwrap_or_default() .contains("pool villa"), "{message}" ); // A chat matched by NAME answers as a thread. assert_eq!(hits_of(&result, "thread")[0]["id"], Value::from(f.thread)); // A finished todo says so instead of hiding. let struck = hits_of(&result, "todo") .into_iter() .find(|hit| hit["id"] == *f.done_todo) .expect("the done todo"); assert_eq!(struck["struck"], Value::Bool(true)); // A journal page is its own kind, worded by its date. let journal = hits_of(&result, "journal")[0]; assert_eq!(journal["id"], Value::from(f.journal)); assert_eq!(journal["title"], "Journal 2026-08-21"); // Totals count per section. assert_eq!(result["totals"]["todo"], 2); assert_eq!(result["totals"]["message"], 2); // one message + one thread let _ = (f.todo, f.note, f.memory); } #[test] fn honours_the_kinds_filter_including_the_note_journal_split() { let f = whole_file_harness(); let only_messages = call_tool( &f.h, &f.secret, "search_records", json!({ "query": "bali", "kinds": ["message"] }), ); let mut kinds = kinds_of(&only_messages); kinds.sort(); kinds.dedup(); assert_eq!(kinds, vec!["message".to_string()]); let only_journal = call_tool( &f.h, &f.secret, "search_records", json!({ "query": "bali", "kinds": ["journal"] }), ); assert_eq!(ids_of(&only_journal), vec![f.journal.clone()]); let only_notes = call_tool( &f.h, &f.secret, "search_records", json!({ "query": "bali", "kinds": ["note"] }), ); assert_eq!(ids_of(&only_notes), vec![f.note.clone()]); } // RULE: Search refuses a kind that neither the built-in vocabulary nor a synced definition names, so a misspelled table id never looks like an empty search. #[test] fn refuses_an_unknown_kind_by_naming_the_vocabulary() { let f = whole_file_harness(); let answer = call_tool_raw( &f.h, &f.secret, "search_records", json!({ "query": "bali", "kinds": ["mixtape"] }), ); assert!(answer.is_error, "{}", answer.text); assert!(answer.text.contains("message"), "{}", answer.text); } // ── the Mac ingestor's tables fold, and its calls are findable ────────────── // // Two things at once, deliberately: the fold ACCEPTS the two tables the Mac // ingestor writes (nothing about them is hand-listed anywhere on the server — // they are accepted because the store's TABLE_SPECS declares them), and the // call log answers `search_records`. // // A call is on the LIKE lane, not FTS: there is no prose on the row to rank, so // the searchable thing is the HANDLE. That is what makes "who was that 98… I // keep missing" answerable before anybody has named them. #[test] fn accepts_a_push_of_contact_handles_and_call_log_rows_into_a_v38_file() { let mut h = Harness::new(); let contact_id = fixture_id("mac-contact"); let handle_id = fixture_id("mac-handle"); let call_id = fixture_id("mac-call"); // `seed` asserts nothing was rejected — an unknown table would come back as // `unknown table: …` rather than land. h.seed(&[ op( "cotton_msg_contacts", &contact_id, json!({ "phone_e164": "919812345678", "display_name": "Ravi Kumar", "workspace_id": h.workspace_id, "created_at": AT, "updated_at": AT, }), ), op( "cotton_msg_contact_handles", &handle_id, json!({ "workspace_id": h.workspace_id, "contact_id": contact_id, "kind": "email", "value": "ravi@example.com", "created_at": AT, }), ), op( "cotton_call_log", &call_id, json!({ "source": "ios_call_history", "external_id": "ZUNIQUE-1", "provider": "cellular", "direction": "out", "outcome": "answered", "started_at": "2026-09-01T09:00:00.000Z", "duration_s": 312, "handle": "919812345678", "contact_id": contact_id, "person_id": Value::Null, "device": "mac-a", "meta": {}, "workspace_id": h.workspace_id, "created_at": AT, "updated_at": AT, }), ), ]); let handle_value = h .with(|db| { db.get( "SELECT value FROM cotton_msg_contact_handles WHERE id = ?", &[SqlValue::Text(handle_id.clone())], ) }) .expect("the read runs") .and_then(|row| row.text("value").map(str::to_string)); assert_eq!(handle_value.as_deref(), Some("ravi@example.com")); // The `json` column arrives as an OBJECT and is stored as one — a // doubly-encoded '"{}"' would fail the row's own json_type CHECK. let meta = h .with(|db| { db.get( "SELECT meta FROM cotton_call_log WHERE id = ?", &[SqlValue::Text(call_id.clone())], ) }) .expect("the read runs") .and_then(|row| row.text("meta").map(str::to_string)); assert_eq!(meta.as_deref(), Some("{}")); let secret = mint_token(&mut h, &["read", "write"], "Claude"); let result = call_tool( &h, &secret, "search_records", json!({ "query": "9812345678", "kinds": ["call"] }), ); // Calling draws calls (Cotton Calling's Recents, Cotton's Calls, 13 Nov // 2026): the pushed row is held and found by its number. let records = result["records"].as_array().expect("records"); assert_eq!(records.len(), 1, "{result}"); assert_eq!(records[0]["id"], call_id.as_str(), "{result}"); assert_eq!(records[0]["kind"], "call", "{result}"); assert_eq!(result["totals"]["call"], 1, "{result}"); } // ── the `read tools` block of mcp.test.ts ─────────────────────────────────── struct Seeded { h: Harness, secret: String, todo_id: String, } fn seeded_harness() -> Seeded { let mut h = Harness::new(); let secret = mint_token(&mut h, &["read", "write"], "Claude"); let todo_id = fixture_id("cardamom-todo"); let note_id = fixture_id("cardamom-note"); h.seed(&[ op( "cotton_todos", &todo_id, json!({ "title": "buy cardamom", "notes": "the green ones", "status": "open", "priority": 0, "workspace_id": h.workspace_id, "created_at": AT, "updated_at": AT, }), ), op( "cotton_notes", ¬e_id, json!({ "title": "kitchen rebuild", "body": "cardamom shelf goes above the hob", "kind": "note", "workspace_id": h.workspace_id, "created_at": AT, "updated_at": AT, }), ), ]); Seeded { h, secret, todo_id } } #[test] fn searches_across_kinds_and_returns_the_compact_record_shape() { let s = seeded_harness(); let result = call_tool( &s.h, &s.secret, "search_records", json!({ "query": "cardamom", "limit": 10 }), ); let records = result["records"].as_array().expect("records"); assert!(records.len() >= 2, "{result}"); let mut kinds = kinds_of(&result); kinds.sort(); assert_eq!(kinds, vec!["note".to_string(), "todo".to_string()]); assert_eq!(hits_of(&result, "todo")[0]["title"], "buy cardamom"); } #[test] fn a_note_carries_the_project_it_belongs_to() { // `toINote` answers `projectId` (`note/transforms.ts:14`) off a column the // row has had since `ddl.v1.ts:930`, and it is what tells a journal page // opened inside a project from the owner's own: without it the page draws // the owner's day switcher, and picking a day walks the reader out of the // project entirely. let mut h = Harness::new(); let secret = mint_token(&mut h, &["read", "write"], "Claude"); let project = fixture_id("kitchen-project"); let note_id = fixture_id("kitchen-journal"); let loose_id = fixture_id("loose-journal"); h.seed(&[ op( "cotton_memory_projects", &project, json!({ "slug": "kitchen", "name": "Kitchen", "status": "active", "workspace_id": h.workspace_id, "created_at": AT, "updated_at": AT, }), ), op( "cotton_notes", ¬e_id, json!({ "title": "day one", "body": "the hob arrived", "kind": "journal", "journal_date": "2026-09-01", "project_id": project, "workspace_id": h.workspace_id, "created_at": AT, "updated_at": AT, }), ), op( "cotton_notes", &loose_id, json!({ "title": "day one", "body": "nothing to do with it", "kind": "journal", "journal_date": "2026-09-01", "workspace_id": h.workspace_id, "created_at": AT, "updated_at": AT, }), ), ]); let inside = call_tool( &h, &secret, "get_record", json!({ "kind": "note", "id": note_id }), ); assert_eq!(inside["project_id"], json!(project)); // And a note that belongs to nobody says so rather than omitting the key. let loose = call_tool( &h, &secret, "get_record", json!({ "kind": "note", "id": loose_id }), ); assert!(loose.as_object().expect("a record").contains_key("project_id")); assert_eq!(loose["project_id"], Value::Null); } #[test] fn gets_one_record_by_kind_and_id() { let s = seeded_harness(); let result = call_tool( &s.h, &s.secret, "get_record", json!({ "kind": "todo", "id": s.todo_id }), ); assert_eq!(result["title"], "buy cardamom"); } /// Every kind `get_record` can expand, against a real file. /// /// This closes the class the TypeScript's fix round found: `memory` selected a /// column schema v14 had dropped and answered a 500 to every call, because /// nothing in the suite had ever expanded a memory. Asserting the exact refusal /// MESSAGE is the point — "it errored" is satisfied just as well by /// `no such column: …`, and cannot tell the failure this exists to catch from /// the one it is testing. /// /// It closes a second hole nothing else guards: in the TypeScript the switch /// sits in an IIFE whose result is object-spread, so a kind with no `case` /// yields a record with no fields and compiles clean. In Rust the `match` is /// exhaustive and that shape is unreachable — but a DELEGATION that answered /// `Ok` for a row it could not find would look the same from here, which is /// what this loop still catches. #[test] fn refuses_an_unknown_id_on_every_kind_with_a_refusal_never_a_sql_error() { let s = seeded_harness(); for kind in [ "todo", "event", "note", "journal", "person", "location", "meeting", "document", "memory", "transaction", "thought", ] { let id = fixture_id(&format!("absent-{kind}")); let answer = call_tool_raw( &s.h, &s.secret, "get_record", json!({ "kind": kind, "id": id }), ); assert!(answer.is_error, "{kind} did not refuse: {}", answer.text); // A kind no tool here draws is the typed refusal before any read. assert!( answer.text == format!("no {kind} with id {id}") || answer.text == cotton_core::definitions::no_tool_draws_this_table(&[]), "{kind} answered something other than a refusal: {}", answer.text ); } } // ── get_record on an event ────────────────────────────────────────────────── #[test] fn says_which_series_an_occurrence_stands_in_for_and_which_instants_a_series_skips() { let mut h = Harness::new(); let secret = mint_token(&mut h, &["read", "write"], "Claude"); let calendar = fixture_id("calendar"); let vicky = fixture_id("vicky"); let vicky_moved_to_the_8th = fixture_id("vicky-8th"); let bella = fixture_id("bella"); h.seed(&[ op( "cotton_collections", &calendar, json!({ "kind": "calendar", "name": "Personal", "is_default": true, "workspace_id": h.workspace_id, "created_at": AT, }), ), op( "cotton_events", &vicky, json!({ "collection_id": calendar, "title": "Vicky", "starts_at": "2026-09-04T06:30:00.000Z", "ends_at": "2026-09-04T07:30:00.000Z", "all_day": false, "rrule": "FREQ=WEEKLY", "created_at": AT, "updated_at": AT, }), ), op( "cotton_events", &vicky_moved_to_the_8th, json!({ "collection_id": calendar, "title": "Vicky", "starts_at": "2026-09-08T06:30:00.000Z", "ends_at": "2026-09-08T07:30:00.000Z", "all_day": false, "series_id": vicky, "original_starts_at": "2026-09-04T06:30:00.000Z", "created_at": AT, "updated_at": AT, }), ), op( "cotton_events", &bella, json!({ "collection_id": calendar, "title": "Call with Bella", "starts_at": "2026-09-16T09:00:00.000Z", "ends_at": "2026-09-16T09:30:00.000Z", "all_day": false, "rrule": "FREQ=WEEKLY", "exdates": ["2026-09-23T09:00:00.000Z"], "created_at": AT, "updated_at": AT, }), ), ]); let exception = call_tool( &h, &secret, "get_record", json!({ "kind": "event", "id": vicky_moved_to_the_8th }), ); assert_eq!(exception["series_id"], Value::from(vicky)); assert_eq!(exception["original_starts_at"], "2026-09-04T06:30:00.000Z"); assert_eq!(exception["trashed_at"], Value::Null); let series = call_tool( &h, &secret, "get_record", json!({ "kind": "event", "id": bella }), ); assert_eq!(series["exdates"], json!(["2026-09-23T09:00:00.000Z"])); } // ── get_record on a person ────────────────────────────────────────────────── // // Schema v15: the prose about a person is a summary with provenance, and // `get_record` is where an assistant reads it — as ONE object carrying who // wrote it and how much has arrived since, never three loose columns. const SUMMARY_AT: &str = "2026-08-23T10:00:00.000Z"; struct Person { h: Harness, secret: String, ravi: String, } fn person_harness() -> Person { let mut h = Harness::new(); let secret = mint_token(&mut h, &["read", "write"], "Claude"); let ravi = fixture_id("person-ravi"); h.seed(&[ op( "cotton_people", &ravi, json!({ "full_name": "Ravi Uncle", "contact_source": "manual", "workspace_id": h.workspace_id, "created_at": AT, "updated_at": AT, }), ), // A phone is a handle row since v90. op( "cotton_person_handles", &fixture_id("handle-person-ravi-0"), json!({ "workspace_id": h.workspace_id, "person_id": ravi, "kind": "phone", "value": "919812345678", "normalised": "919812345678", "source": "manual", "position": 0, "created_at": AT, "updated_at": AT, }), ), ]); Person { h, secret, ravi } } fn person_note(h: &Harness, person_id: &str, created_at: &str) { run( h, "INSERT INTO cotton_person_notes (id, person_id, body, noted_at, created_at) VALUES (?, ?, 'said the timber is delayed', ?, ?)", &[ SqlValue::Text(fixture_id(&format!("note-{created_at}"))), SqlValue::Text(person_id.to_string()), SqlValue::Text(created_at.to_string()), SqlValue::Text(created_at.to_string()), ], ); } fn write_summary(h: &Harness, person_id: &str, at: &str) { run( h, "UPDATE cotton_people SET summary = ?, summary_by = ?, summary_updated_at = ? WHERE id = ?", &[ SqlValue::Text( "Runs the timber yard on Old Madras Road; sends quotes by Friday.".to_string(), ), SqlValue::Text("Claude Code".to_string()), SqlValue::Text(at.to_string()), SqlValue::Text(person_id.to_string()), ], ); } #[test] fn carries_the_summary_who_wrote_it_and_what_has_arrived_since() { let p = person_harness(); write_summary(&p.h, &p.ravi, SUMMARY_AT); person_note(&p.h, &p.ravi, "2026-08-22T09:00:00.000Z"); // before the summary person_note(&p.h, &p.ravi, "2026-08-24T09:00:00.000Z"); // after person_note(&p.h, &p.ravi, "2026-08-25T09:00:00.000Z"); // after let record = call_tool( &p.h, &p.secret, "get_record", json!({ "kind": "person", "id": p.ravi }), ); assert_eq!( record["summary"], json!({ "text": "Runs the timber yard on Old Madras Road; sends quotes by Friday.", "by": "Claude Code", "updatedAt": SUMMARY_AT, "since": { "count": 2, "noun": "note" }, }) ); // The provenance travels INSIDE the summary — the raw columns never reach // an assistant, which is what keeps one shape across all three reads. assert!(record.get("summary_by").is_none(), "{record}"); assert!(record.get("summary_updated_at").is_none(), "{record}"); } #[test] fn omits_the_summary_key_entirely_when_there_is_none() { // Figure or silence: `summary: null` is a key every caller has to test. let p = person_harness(); let record = call_tool( &p.h, &p.secret, "get_record", json!({ "kind": "person", "id": p.ravi }), ); assert!(record.get("summary").is_none(), "{record}"); assert_eq!(record["full_name"], "Ravi Uncle"); } #[test] fn omits_since_when_nothing_has_arrived() { let p = person_harness(); write_summary(&p.h, &p.ravi, SUMMARY_AT); person_note(&p.h, &p.ravi, "2026-08-22T09:00:00.000Z"); // before the summary let record = call_tool( &p.h, &p.secret, "get_record", json!({ "kind": "person", "id": p.ravi }), ); let keys: Vec<&String> = record["summary"] .as_object() .expect("a summary object") .keys() .collect(); assert_eq!(keys, vec!["text", "by", "updatedAt"]); } // ── the meaning lane, where it can answer at all ──────────────────────────── // // The `mode` parameter and the four shapes of its absence are the TOOL's, and // they are held here. The lane ANSWERING is not: it would need a query path (the // provider round-trip, the spend meter, the owner's own key) and a // `semantic_search` column, which this store's schema does not carry. With no // column no person has ever been shown the paragraph, nobody has consented and // nobody has turned anything on, so `off` is the TRUE answer here rather than a // guess at one, and it is what these cases assert. #[test] fn answers_identically_with_the_mode_absent_explicit_and_the_switch_off() { let mut h = Harness::new(); let secret = mint_token(&mut h, &["read", "write"], "Claude"); let exact = fixture_id("ferry-note"); h.seed(&[op( "cotton_notes", &exact, json!({ "title": "ferry timings", "body": "the 6am boat", "kind": "note", "workspace_id": h.workspace_id, "created_at": AT, "updated_at": AT, }), )]); let absent = call_tool(&h, &secret, "search_records", json!({ "query": "ferry" })); let explicit = call_tool( &h, &secret, "search_records", json!({ "query": "ferry", "mode": "text" }), ); assert_eq!(explicit, absent); assert_eq!(ids_of(&absent), vec![exact]); // Not one field more than the shape a caller written before this saw. assert!(absent["records"][0].get("matchedBy").is_none(), "{absent}"); assert!(absent.get("meaning").is_none(), "{absent}"); } #[test] fn says_the_switch_is_off_and_still_answers_with_the_text_lane() { let mut h = Harness::new(); let secret = mint_token(&mut h, &["read", "write"], "Claude"); let note = fixture_id("ferry-note-off"); h.seed(&[op( "cotton_notes", ¬e, json!({ "title": "ferry timings", "body": "", "kind": "note", "workspace_id": h.workspace_id, "created_at": AT, "updated_at": AT, }), )]); let result = call_tool( &h, &secret, "search_records", json!({ "query": "ferry", "mode": "both" }), ); assert_eq!(ids_of(&result), vec![note]); assert_eq!(result["meaning"]["available"], Value::Bool(false)); assert_eq!(result["meaning"]["reason"], "off"); assert!( result["meaning"]["note"] .as_str() .unwrap_or_default() .contains("AI plan"), "{result}" ); } #[test] fn returns_an_empty_set_with_a_reason_never_a_tool_error_in_meaning_mode() { let mut h = Harness::new(); let secret = mint_token(&mut h, &["read", "write"], "Claude"); let note = fixture_id("ferry-note-meaning"); h.seed(&[op( "cotton_notes", ¬e, json!({ "title": "ferry timings", "body": "", "kind": "note", "workspace_id": h.workspace_id, "created_at": AT, "updated_at": AT, }), )]); // A failure here would make an assistant retry a settled preference (D20). let result = call_tool( &h, &secret, "search_records", json!({ "query": "ferry", "mode": "meaning" }), ); assert_eq!(result["records"], json!([])); assert_eq!(result["meaning"]["available"], Value::Bool(false)); assert_eq!(result["meaning"]["reason"], "off"); } #[test] fn refuses_an_unknown_mode_with_a_message_naming_the_three() { let mut h = Harness::new(); let secret = mint_token(&mut h, &["read", "write"], "Claude"); let answer = call_tool_raw( &h, &secret, "search_records", json!({ "query": "x", "mode": "semantic" }), ); assert!(answer.is_error, "{}", answer.text); assert!( answer.text.contains("text, meaning, both"), "{}", answer.text ); } // ── a repository's children carry the address they are opened at ────────────