52 lines
1.5 KiB
Rust
52 lines
1.5 KiB
Rust
|
|
use nu_plugin::Plugin;
|
||
|
|
use nu_plugin_mcp::McpPlugin;
|
||
|
|
use std::sync::{Arc, Mutex};
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn plugin_command_names_match_expected() {
|
||
|
|
let plugin = McpPlugin::new();
|
||
|
|
let cmds = plugin.commands();
|
||
|
|
let names: Vec<String> = cmds.iter().map(|c| c.name().to_string()).collect();
|
||
|
|
assert!(names.contains(&"mcp connect".to_string()));
|
||
|
|
assert!(names.contains(&"mcp tools list".to_string()));
|
||
|
|
assert!(names.contains(&"mcp tool call".to_string()));
|
||
|
|
assert!(names.contains(&"mcp disconnect".to_string()));
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn plugin_version_matches_cargo() {
|
||
|
|
let plugin = McpPlugin::new();
|
||
|
|
assert_eq!(plugin.version(), env!("CARGO_PKG_VERSION"));
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn session_starts_disconnected() {
|
||
|
|
let plugin = McpPlugin::new();
|
||
|
|
let guard = plugin.session.lock().unwrap();
|
||
|
|
assert!(guard.is_none());
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn session_arc_is_shared() {
|
||
|
|
let plugin = McpPlugin::new();
|
||
|
|
let cloned: Arc<Mutex<Option<nu_plugin_mcp::session::McpSession>>> =
|
||
|
|
Arc::clone(&plugin.session);
|
||
|
|
// Both point to the same underlying mutex
|
||
|
|
assert!(Arc::ptr_eq(&plugin.session, &cloned));
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn connect_to_nonexistent_binary_errors() {
|
||
|
|
use nu_plugin_mcp::session::McpSession;
|
||
|
|
match McpSession::connect("/nonexistent/binary_that_does_not_exist", None) {
|
||
|
|
Err(e) => {
|
||
|
|
let msg = e.to_string();
|
||
|
|
assert!(
|
||
|
|
msg.contains("spawn failed") || msg.contains("No such file"),
|
||
|
|
"unexpected error: {msg}"
|
||
|
|
);
|
||
|
|
}
|
||
|
|
Ok(_) => panic!("expected spawn to fail"),
|
||
|
|
}
|
||
|
|
}
|