From b20d43321e8548e02cd80d707b3658a199c03280 Mon Sep 17 00:00:00 2001 From: B-uchi Date: Sat, 28 Nov 2026 08:59:22 +0100 Subject: [PATCH] M8: a test checks the tools and fields the prompts name exist A prompt is a workflow an agent follows by name. The existing check covers the command ids the instructions and prompts give, but not the MCP tools or the result fields: a renamed tool or field would leave a prompt pointing at nothing, with no test failing. Every snake_case name in the server instructions and the prompt templates must now be a tool, a prompt or that prompt's own argument, and every backticked field must appear in some tool's or command's documentation. --- crates/mcp/src/prompts.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/crates/mcp/src/prompts.rs b/crates/mcp/src/prompts.rs index e0971da01..50a1440b4 100644 --- a/crates/mcp/src/prompts.rs +++ b/crates/mcp/src/prompts.rs @@ -196,6 +196,41 @@ mod tests { assert!(out.len() < 3 * bomb.len(), "{}", out.len()); } + /// Every tool and result field the instructions and prompts name exists: an agent told to call a + /// renamed tool, or to read a field that was renamed, follows a workflow that points at nothing. + #[test] + fn the_tools_and_fields_the_instructions_and_prompts_name_exist() { + let tools = crate::tool_definitions(); + // Every name a tool's or command's documentation gives: its fields and arguments. + let documented: String = tools + .iter() + .map(Value::to_string) + .chain(figcraft_engine::all_commands().iter().map(|c| format!("{} {}", c.id, c.params))) + .collect::>() + .join(" "); + let words: std::collections::HashSet<&str> = + documented.split(|c: char| !(c.is_ascii_alphanumeric() || c == '_' || c == '.')).map(|w| w.trim_matches('.')).collect(); + let tool_names: Vec<&str> = tools.iter().filter_map(|t| t["name"].as_str()).collect(); + let prompt_names: Vec<&str> = PROMPTS.iter().map(|p| p.name).collect(); + let texts = std::iter::once((crate::INSTRUCTIONS, &[][..])).chain(PROMPTS.iter().map(|p| (p.template, p.args))); + let (mut tools_named, mut fields_named) = (0, 0); + for (text, args) in texts { + for word in text.split(|c: char| !(c.is_ascii_alphanumeric() || c == '_')).filter(|w| w.contains('_')) { + tools_named += 1; + let known = tool_names.contains(&word) || prompt_names.contains(&word) || args.iter().any(|a| a.name == word); + assert!(known, "`{word}` is neither a tool, a prompt nor one of the prompt's arguments"); + } + for quoted in text.split('`').skip(1).step_by(2) { + if quoted.is_empty() || !quoted.chars().all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '.') { + continue; + } + fields_named += 1; + assert!(words.contains(quoted), "`{quoted}` is in no tool's or command's documentation"); + } + } + assert!(tools_named > 10 && fields_named > 3, "the check found the names ({tools_named}, {fields_named})"); + } + /// Every command the server's instructions and the prompts name exists: an agent told to run a /// renamed or misspelt one gets an error instead of the workflow. #[test]