chore: rustfmt, clippy lints and code tidying

This commit is contained in:
Riz Ashraf committed 2026-09-17 15:35:41 +01:00
1 parent 3716c3e698
commit 1752753fcc
19 files changed
+1273 -738

No files matched your search

+40 -25
View File
@@ -1,5 +1,5 @@
use serde_json::{json, Value};
use std::io::{BufRead, BufReader, Read, Write};
use serde_json::{Value, json};
use std::io::{BufRead, BufReader, Write};
use std::process::{Command, Stdio};
use std::time::Duration;
@@ -18,21 +18,26 @@ fn read_message(reader: &mut impl BufRead) -> Option<Value> {
serde_json::from_str(line.trim()).ok()
}
#[tokio::test]
async fn test_full_system_e2e_performance() {
let temp_dir = std::env::temp_dir().join(format!("mcp_e2e_{}", std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs()));
let temp_dir = std::env::temp_dir().join(format!(
"mcp_e2e_{}",
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs()
));
std::fs::create_dir_all(&temp_dir).unwrap();
let test_port = "3042"; // Use a distinct port
let test_auth_token = "test-token-12345";
// Since tests run from inside `target/debug/deps`, and `cargo test` does not guarantee
// Since tests run from inside `target/debug/deps`, and `cargo test` does not guarantee
// `env!("CARGO_BIN_EXE_name")` works correctly for binaries compiled in other crates without build dependencies,
// we use `CARGO_MANIFEST_DIR` (which points to `stub`) to reliably locate the workspace `target/debug`.
let manifest_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let debug_dir = manifest_dir.parent().unwrap().join("target").join("debug");
let server_exe = debug_dir.join(format!("mcp-memory-server{}", std::env::consts::EXE_SUFFIX));
let nvim_name = if cfg!(windows) {
"mcp-memory-win-nvim"
@@ -41,21 +46,24 @@ async fn test_full_system_e2e_performance() {
};
let nvim_exe = debug_dir.join(format!("{}{}", nvim_name, std::env::consts::EXE_SUFFIX));
let stub_exe = debug_dir.join(format!("mcp-memory-stub{}", std::env::consts::EXE_SUFFIX));
assert!(server_exe.exists(), "Server not found at {:?}", server_exe);
assert!(nvim_exe.exists(), "Nvim not found at {:?}", nvim_exe);
assert!(stub_exe.exists(), "Stub not found at {:?}", stub_exe);
// 1. Start Server
let mut server = Command::new(&server_exe).arg("--daemon")
.env("MCP_PORT", test_port).env("RUST_LOG", "debug")
let mut server = Command::new(&server_exe)
.arg("--daemon")
.env("MCP_PORT", test_port)
.env("RUST_LOG", "debug")
.env("MCP_MEMORY_STORE_DIR", temp_dir.to_str().unwrap())
.env("MCP_AUTH_TOKEN", test_auth_token).env("RUST_LOG", "debug")
.env("MCP_AUTH_TOKEN", test_auth_token)
.env("RUST_LOG", "debug")
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.spawn()
.expect("Failed to start server");
// Give server time to generate TLS cert and start
let client = reqwest::Client::builder()
.danger_accept_invalid_certs(true)
@@ -63,28 +71,32 @@ async fn test_full_system_e2e_performance() {
.unwrap();
let mut started = false;
for _ in 0..30 {
if let Ok(resp) = client.get(format!("http://127.0.0.1:{}/health", test_port)).send().await {
if resp.status().is_success() {
started = true;
break;
}
if let Ok(resp) = client
.get(format!("http://127.0.0.1:{}/health", test_port))
.send()
.await
&& resp.status().is_success()
{
started = true;
break;
}
tokio::time::sleep(Duration::from_millis(500)).await;
}
assert!(started, "Server failed to start in time");
// 2. Start Stub
let mut stub = Command::new(&stub_exe)
.arg("--target")
.arg(format!("http://127.0.0.1:{}", test_port))
.env("MCP_MEMORY_STORE_DIR", temp_dir.to_str().unwrap())
.env("MCP_AUTH_TOKEN", test_auth_token).env("RUST_LOG", "debug")
.env("MCP_AUTH_TOKEN", test_auth_token)
.env("RUST_LOG", "debug")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::inherit())
.spawn()
.expect("Failed to start stub");
let mut stub_stdin = stub.stdin.take().unwrap();
let mut stub_stdout = BufReader::new(stub.stdout.take().unwrap());
@@ -111,7 +123,7 @@ async fn test_full_system_e2e_performance() {
"params": {},
"id": i
});
// Alternate between LSP header format and JSONL format
if i % 2 == 0 {
send_message(&mut stub_stdin, tools_req);
@@ -121,7 +133,8 @@ async fn test_full_system_e2e_performance() {
stub_stdin.flush().unwrap();
}
let mut resp = read_message(&mut stub_stdout).expect("Failed to read rapid response from stub");
let mut resp =
read_message(&mut stub_stdout).expect("Failed to read rapid response from stub");
while resp.get("id").is_none() || resp["id"].is_null() {
resp = read_message(&mut stub_stdout).expect("Failed to read rapid response from stub");
}
@@ -140,7 +153,7 @@ async fn test_full_system_e2e_performance() {
"params": {},
"id": i
});
if i % 2 == 0 {
send_message(&mut nvim_stdin, tools_req);
} else {
@@ -149,9 +162,11 @@ async fn test_full_system_e2e_performance() {
nvim_stdin.flush().unwrap();
}
let mut resp = read_message(&mut nvim_stdout).expect("Failed to read rapid response from win-nvim");
let mut resp =
read_message(&mut nvim_stdout).expect("Failed to read rapid response from win-nvim");
while resp.get("id").is_none() || resp["id"].is_null() {
resp = read_message(&mut nvim_stdout).expect("Failed to read rapid response from win-nvim");
resp = read_message(&mut nvim_stdout)
.expect("Failed to read rapid response from win-nvim");
}
assert_eq!(resp["id"], i);
}