返回 CodeWhale
canonical_action_test_support.rs
根目录 / crates / engine / src / tools / canonical_action_test_support.rs
1 /// Names the v0.9.3 consolidation retired from the model-facing catalog.
2 /// Each stays registered only as a hidden (`model_visible=false`)
3 /// replay alias or is gone entirely, so any one of them inside a
4 /// model-visible description or schema teaches a call the catalog never
5 /// offers. `retired_names_are_not_model_visible` pins that invariant.
6 ///
7 /// `list_dir`, `file_search`, and `grep_files` are deliberately absent:
8 /// they are live, model-visible tools, not retired names
9 /// (#6747).
10 pub(super) const RETIRED_TOOL_NAMES: &[&str] = &[
11 "read_file",
12 "write_file",
13 "edit_file",
14 "git_status",
15 "git_diff",
16 "git_log",
17 "git_show",
18 "git_blame",
19 "run_tests",
20 "run_verifiers",
21 "web_search",
22 "fetch_url",
23 "wait_for_dev_server",
24 "exec_shell",
25 "exec_shell_wait",
26 "exec_shell_interact",
27 "exec_shell_cancel",
28 ];
29
30 pub(super) fn full_native_registry(root: &std::path::Path) -> crate::tools::registry::ToolRegistry {
31 use crate::tools::registry::ToolRegistryBuilder;
32 use crate::tools::spec::ToolContext;
33
34 ToolRegistryBuilder::new()
35 .with_file_tools()
36 .with_shell_tools()
37 .with_search_tools()
38 .with_git_tools()
39 .with_git_history_tools()
40 .with_test_runner_tool()
41 .with_web_tools()
42 .with_patch_tools()
43 .with_handle_tools()
44 .with_rlm_tool()
45 .build(ToolContext::new(root.to_path_buf()))
46 }
47
48 /// Assert that model-facing `text` names only tools a model can call
49 /// (#6747): no hidden (`model_visible=false`) registry name and no
50 /// retired name. Shared by every site that writes tool names into
51 /// prompts, briefs, or tool output.
52 pub fn assert_text_names_only_callable_tools(label: &str, text: &str) {
53 let tmp = tempfile::tempdir().expect("tempdir");
54 let registry = full_native_registry(tmp.path());
55 let mut hidden: Vec<String> = RETIRED_TOOL_NAMES.iter().map(|n| n.to_string()).collect();
56 for tool in registry.all() {
57 if !tool.model_visible() {
58 hidden.push(tool.name().to_string());
59 }
60 }
61 // Snake-case names are unambiguous as bare words; short names such as
62 // `File` or `Bash` only count as tool references inside backticks.
63 let names = |name: &str, text: &str| {
64 text.contains(&format!("`{name}`")) || (name.contains('_') && text.contains(name))
65 };
66 for name in &hidden {
67 assert!(
68 !names(name, text),
69 "{label} names `{name}`, which the model-visible catalog never offers:\n{text}"
70 );
71 }
72 }
73
73 lines RUST