35 lines · 1.9 KB · RustRaw
//! Shared input parsing through the dispatch the phone links.mod support;use serde_json::json;use support::harness::Harness;use support::mcp::{call_tool_as_owner, call_tool_raw, mint_token};/// RULE: The parse_phrase MCP verb and phone dispatch use the shared deterministic engine and reject invalid context.#[test]fn phrase_verb_dispatches_the_shared_engine_and_refuses_bad_context() { // Both entry points must agree, without using the harness's clock instead // of the one the caller supplied. The owner calls through the phone Ctx. let mut h = Harness::new(); let token = mint_token(&mut h, &["read"], "Phrase fixture"); let mut args = json!({"text":"call Sam tomorrow at 6", "now":"2026-10-01T12:00:00Z", "time_zone":"Europe/Berlin", "projects":[], "people":["Sam"]}); let assistant = call_tool_raw(&h, &token, "parse_phrase", args.clone()).json(); let phone = call_tool_as_owner(&h, "device:phrase-fixture", "parse_phrase", args.clone()).json(); assert_eq!(assistant, phone); assert_eq!(phone["person"]["candidates"], json!(["Sam"])); assert_eq!(phone["date"]["candidates"], json!(["2026-10-02"])); assert_eq!(phone["time"]["candidates"], json!(["18:00", "06:00"])); assert_eq!(phone["remainder"], "call"); let tool = cotton_tools::mcp::protocol::tool_by_name("parse_phrase").unwrap(); assert_eq!(tool.scope, cotton_tools::mcp::protocol::McpScope::Read); assert!(tool.annotations.read_only_hint); args["time_zone"] = json!("bad"); assert!(call_tool_raw(&h, &token, "parse_phrase", args.clone()).is_error); args["time_zone"] = json!("UTC"); args.as_object_mut().unwrap().remove("now"); assert!(call_tool_raw(&h, &token, "parse_phrase", args.clone()).is_error); args["now"] = json!("2026-10-01T12:00:00Z"); args["extra"] = json!(true); assert!(call_tool_raw(&h, &token, "parse_phrase", args).is_error);}