refactor: consolidate nvim crates, extract server library, and update workspace dependencies
This commit is contained in:
1 parent
a083719cf1
commit
533adfd41b
53 files changed
+5967
-1230
No files matched your search
@@ -40,3 +40,48 @@ pub fn extract_log_prefix(json_str: &str, is_response: bool) -> String {
|
||||
"Message".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_extract_log_prefix_response() {
|
||||
let json_str = r#"{"jsonrpc":"2.0","id":123,"result":{}}"#;
|
||||
assert_eq!(extract_log_prefix(json_str, true), "Response id=123 [Error: false]");
|
||||
|
||||
let err_json = r#"{"jsonrpc":"2.0","id":456,"error":{"code":-32600,"message":"Invalid Request"}}"#;
|
||||
assert_eq!(extract_log_prefix(err_json, true), "Response id=456 [Error: true]");
|
||||
|
||||
let is_err_json = r#"{"jsonrpc":"2.0","id":789,"result":{"isError":true}}"#;
|
||||
assert_eq!(extract_log_prefix(is_err_json, true), "Response id=789 [Error: true]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_log_prefix_tool_call() {
|
||||
let json_str = r#"{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"search"}}"#;
|
||||
assert_eq!(extract_log_prefix(json_str, false), "ToolCall[search] id=1");
|
||||
|
||||
let unknown_tool = r#"{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{}}"#;
|
||||
assert_eq!(extract_log_prefix(unknown_tool, false), "ToolCall[unknown] id=2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_log_prefix_request() {
|
||||
let json_str = r#"{"jsonrpc":"2.0","id":10,"method":"initialize"}"#;
|
||||
assert_eq!(extract_log_prefix(json_str, false), "Request[initialize] id=10");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_log_prefix_response_as_request() {
|
||||
let json_str = r#"{"jsonrpc":"2.0","id":99,"result":true}"#;
|
||||
assert_eq!(extract_log_prefix(json_str, false), "Response id=99");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_log_prefix_generic_message() {
|
||||
let json_str = r#"{"foo":"bar"}"#;
|
||||
assert_eq!(extract_log_prefix(json_str, false), "Message");
|
||||
}
|
||||
}
|
||||
|
||||
+11
-9
@@ -70,7 +70,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(req) => req,
|
||||
Err(e) => {
|
||||
tracing::error!("Failed to parse target URL {}: {}", ws_url, e);
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
|
||||
tokio::time::sleep(tokio::time::Duration::from_millis(250)).await;
|
||||
continue;
|
||||
}
|
||||
};
|
||||
@@ -126,9 +126,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
if text.len() > 1000 { "..." } else { "" }
|
||||
);
|
||||
use tokio::io::AsyncWriteExt;
|
||||
let mut payload = Vec::with_capacity(text.len() + 1);
|
||||
payload.extend_from_slice(text.as_bytes());
|
||||
payload.push(b'\n');
|
||||
let mut stdout = tokio::io::stdout();
|
||||
let response = format!("{}\n", text);
|
||||
let _ = stdout.write_all(response.as_bytes()).await;
|
||||
let _ = stdout.write_all(&payload).await;
|
||||
let _ = stdout.flush().await;
|
||||
}
|
||||
}
|
||||
@@ -151,30 +153,30 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
send_task.abort();
|
||||
}
|
||||
}
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
|
||||
tokio::time::sleep(tokio::time::Duration::from_millis(250)).await;
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
tracing::error!("Failed to connect via WSS: {}", e);
|
||||
retry_count += 1;
|
||||
if retry_count >= 5 {
|
||||
if retry_count >= 20 {
|
||||
tracing::error!("Max connection retries reached. Exiting proxy.");
|
||||
break;
|
||||
}
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
|
||||
tokio::time::sleep(tokio::time::Duration::from_millis(250)).await;
|
||||
}
|
||||
Err(_) => {
|
||||
tracing::error!("Connection attempt timed out");
|
||||
retry_count += 1;
|
||||
if retry_count >= 5 {
|
||||
if retry_count >= 20 {
|
||||
tracing::error!("Max connection retries reached. Exiting proxy.");
|
||||
break;
|
||||
}
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
|
||||
tokio::time::sleep(tokio::time::Duration::from_millis(250)).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if retry_count >= 5 {
|
||||
if retry_count >= 20 {
|
||||
return Err("Failed to connect to the MCP memory server after multiple attempts. Is it running?".into());
|
||||
}
|
||||
|
||||
|
||||
+1
-5
@@ -48,11 +48,7 @@ async fn test_full_system_e2e_performance() {
|
||||
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"
|
||||
} else {
|
||||
"mcp-memory-linux-nvim"
|
||||
};
|
||||
let nvim_name = "mcp-memory-nvim";
|
||||
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));
|
||||
|
||||
|
||||
Reference in new issue
Block a user