//! The gates `get_record` owes that no integration test can give it. //! //! The TypeScript gets this from its type system: `GET_RECORD_KINDS` is a //! `const` array, the switch over it is exhaustive, and the schema is built //! from the same array. Here the enum's `match` is the exhaustiveness gate, and //! these tests are the other half — that the enum and the two generated copies //! of the list have not drifted apart. use serde_json::{json, Map, Value}; use super::{validate_get_record, GetRecordKind, GET_RECORD_KINDS}; fn kind_names() -> Vec<&'static str> { GET_RECORD_KINDS.iter().map(|kind| kind.as_str()).collect() } #[test] fn catalogue_names_the_same_get_record_kinds_in_the_same_order() { let tool = crate::mcp::protocol::tool_by_name("get_record").expect("get_record"); let schema = tool.input_schema_json(); let declared: Vec = schema["properties"]["kind"]["enum"] .as_array() .expect("an enum in the generated schema") .iter() .map(|value| value.as_str().unwrap_or_default().to_string()) .collect(); assert_eq!(declared, kind_names()); } /// The verb grid's own copy. It must never promise `get_record` for a kind the /// validator would refuse, which is what this pins from the other side. #[test] fn the_verb_grid_names_the_same_get_record_kinds() { assert_eq!( crate::mcp::surface::GET_RECORD_KINDS.to_vec(), kind_names() ); } fn args(value: Value) -> Map { value.as_object().cloned().unwrap_or_default() } #[test] fn an_unknown_kind_names_the_vocabulary() { let refusal = validate_get_record(&args(json!({ "kind": "mixtape", "id": "x" }))).expect_err("refused"); assert_eq!( refusal.message(), format!("kind is required. Allowed: {}", kind_names().join(", ")) ); } #[test] fn a_missing_kind_is_the_same_refusal() { let refusal = validate_get_record(&args(json!({ "id": "x" }))).expect_err("refused"); assert!(refusal.message().starts_with("kind is required. Allowed: ")); } #[test] fn the_id_must_be_a_uuid() { let refusal = validate_get_record(&args(json!({ "kind": "todo", "id": "42" }))).expect_err("refused"); assert_eq!(refusal.message(), "id must be a uuid"); } #[test] fn a_valid_call_parses() { let parsed = validate_get_record(&args(json!({ "kind": "journal", "id": "0b7f1b8e-1c2d-4e5f-8a9b-0c1d2e3f4a5b", }))) .expect("valid"); assert_eq!(parsed.kind, GetRecordKind::Journal); assert_eq!(parsed.id, "0b7f1b8e-1c2d-4e5f-8a9b-0c1d2e3f4a5b"); }