Files
mcp-memory/server/tests/parity_test.rs
T

78 lines
2.9 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 entries = std::fs::read_dir("src/handlers_v2").expect("Failed to read handlers_v2 dir");
for entry in entries {
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();
if let Some(eager) = config["mcpServers"]["memory"]["eagerTools"].as_array() {
for tool in eager {
let name = tool.as_str().unwrap();
assert!(
memory_tools.contains(name),
"Windows config Memory tool '{}' not implemented in handlers.rs!",
name
);
}
}
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 '{}' not implemented in nvim-core!",
name
);
}
}
}
}