Apply recent changes
This commit is contained in:
53
crates/owlen-core/tests/file_server.rs
Normal file
53
crates/owlen-core/tests/file_server.rs
Normal file
@@ -0,0 +1,53 @@
|
||||
use owlen_core::mcp::client::McpClient;
|
||||
use owlen_core::mcp::remote_client::RemoteMcpClient;
|
||||
use owlen_core::mcp::McpToolCall;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use tempfile::tempdir;
|
||||
|
||||
#[tokio::test]
|
||||
async fn remote_file_server_read_and_list() {
|
||||
// Create temporary directory with a file
|
||||
let dir = tempdir().expect("tempdir failed");
|
||||
let file_path = dir.path().join("hello.txt");
|
||||
let mut file = File::create(&file_path).expect("create file");
|
||||
writeln!(file, "world").expect("write file");
|
||||
|
||||
// Change current directory for the test process so the server sees the temp dir as its root
|
||||
std::env::set_current_dir(dir.path()).expect("set cwd");
|
||||
|
||||
// Ensure the MCP server binary is built.
|
||||
// Build the MCP server binary using the workspace manifest.
|
||||
let manifest_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../..")
|
||||
.join("Cargo.toml");
|
||||
let build_status = std::process::Command::new("cargo")
|
||||
.args(&["build", "-p", "owlen-mcp-server", "--manifest-path"])
|
||||
.arg(manifest_path)
|
||||
.status()
|
||||
.expect("failed to run cargo build for MCP server");
|
||||
assert!(build_status.success(), "MCP server build failed");
|
||||
|
||||
// Spawn remote client after the cwd is set and binary built
|
||||
let client = RemoteMcpClient::new().expect("remote client init");
|
||||
|
||||
// Read file via MCP
|
||||
let call = McpToolCall {
|
||||
name: "resources/get".to_string(),
|
||||
arguments: serde_json::json!({"path": "hello.txt"}),
|
||||
};
|
||||
let resp = client.call_tool(call).await.expect("call_tool");
|
||||
let content: String = serde_json::from_value(resp.output).expect("parse output");
|
||||
assert!(content.trim().ends_with("world"));
|
||||
|
||||
// List directory via MCP
|
||||
let list_call = McpToolCall {
|
||||
name: "resources/list".to_string(),
|
||||
arguments: serde_json::json!({"path": "."}),
|
||||
};
|
||||
let list_resp = client.call_tool(list_call).await.expect("list_tool");
|
||||
let entries: Vec<String> = serde_json::from_value(list_resp.output).expect("parse list");
|
||||
assert!(entries.contains(&"hello.txt".to_string()));
|
||||
|
||||
// Cleanup handled by tempdir
|
||||
}
|
||||
Reference in New Issue
Block a user