81 lines
3.0 KiB
Rust
81 lines
3.0 KiB
Rust
use std::collections::HashSet;
|
|
|
|
#[test]
|
|
fn test_eager_tools_parity() {
|
|
// 1. Read handlers_v2/*.rs to get memory tools
|
|
let mut memory_tools = HashSet::new();
|
|
let v2_handlers_dir = std::fs::read_dir("src/handlers").expect("Failed to read handlers dir");
|
|
for entry in v2_handlers_dir {
|
|
let entry = entry.unwrap();
|
|
if entry.path().extension().unwrap_or_default() == "rs" {
|
|
let memory_source = std::fs::read_to_string(entry.path()).unwrap();
|
|
let parts: Vec<&str> = memory_source.split("crate::mcp::tool_def").collect();
|
|
for part in parts.iter().skip(1) {
|
|
if let Some(start) = part.find('"') {
|
|
let rest = &part[start + 1..];
|
|
if let Some(end) = rest.find('"') {
|
|
memory_tools.insert(rest[..end].to_string());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
assert!(
|
|
!memory_tools.is_empty(),
|
|
"Could not find memory tools in handlers_v2 directory"
|
|
);
|
|
|
|
// 2. Read nvim-core/src/lib.rs to get nvim tools
|
|
let nvim_source =
|
|
std::fs::read_to_string("../nvim-core/src/lib.rs").expect("Failed to read nvim lib.rs");
|
|
let mut nvim_tools = HashSet::new();
|
|
for line in nvim_source.lines() {
|
|
if line.contains("\"name\": \"nvim_")
|
|
&& let Some(start) = line.find("\"name\": \"")
|
|
{
|
|
let rest = &line[start + 9..];
|
|
if let Some(end) = rest.find('"') {
|
|
nvim_tools.insert(rest[..end].to_string());
|
|
}
|
|
}
|
|
}
|
|
assert!(
|
|
!nvim_tools.is_empty(),
|
|
"Could not find nvim tools in lib.rs"
|
|
);
|
|
|
|
// 3. Read Windows mcp_config.json
|
|
let win_home =
|
|
std::env::var("USERPROFILE").unwrap_or_else(|_| "C:\\Users\\reazul.ashraf".to_string());
|
|
let win_config_path = std::path::PathBuf::from(win_home).join(".gemini/config/mcp_config.json");
|
|
if win_config_path.exists() {
|
|
let config_str = std::fs::read_to_string(&win_config_path).unwrap();
|
|
let config: serde_json::Value = serde_json::from_str(&config_str).unwrap();
|
|
|
|
let mem_server = if config["mcpServers"]["mcp-memory"].is_object() {
|
|
&config["mcpServers"]["mcp-memory"]
|
|
} else {
|
|
&config["mcpServers"]["memory"]
|
|
};
|
|
if let Some(eager) = mem_server["eagerTools"].as_array() {
|
|
for tool in eager {
|
|
let name = tool.as_str().unwrap();
|
|
assert!(
|
|
memory_tools.contains(name),
|
|
"Windows config Memory tool '{name}' not implemented in handlers.rs!"
|
|
);
|
|
}
|
|
}
|
|
|
|
if let Some(nvim_eager) = config["mcpServers"]["win-nvim"]["eagerTools"].as_array() {
|
|
for tool in nvim_eager {
|
|
let name = tool.as_str().unwrap();
|
|
assert!(
|
|
nvim_tools.contains(name),
|
|
"Windows config Nvim tool '{name}' not implemented in nvim-core!"
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|