@@ -3,12 +3,13 @@ use std::fs::File;
|
||||
use std::path::PathBuf;
|
||||
use std::{env, fs};
|
||||
|
||||
use rmcp::model::{CallToolRequestParam, Content};
|
||||
use rmcp::object;
|
||||
use rmcp::model::Content;
|
||||
use serde_json::json;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
use goose::agents::extension::{Envs, ExtensionConfig};
|
||||
use goose::agents::extension_manager::ExtensionManager;
|
||||
use mcp_core::ToolCall;
|
||||
|
||||
use test_case::test_case;
|
||||
|
||||
@@ -20,66 +21,66 @@ enum TestMode {
|
||||
#[test_case(
|
||||
vec!["npx", "-y", "@modelcontextprotocol/server-everything"],
|
||||
vec![
|
||||
CallToolRequestParam { name: "echo".into(), arguments: Some(object!({"message": "Hello, world!" })) },
|
||||
CallToolRequestParam { name: "add".into(), arguments: Some(object!({"a": 1, "b": 2 })) },
|
||||
CallToolRequestParam { name: "longRunningOperation".into(), arguments: Some(object!({"duration": 1, "steps": 5 })) },
|
||||
CallToolRequestParam { name: "structuredContent".into(), arguments: Some(object!({"location": "11238"})) },
|
||||
ToolCall::new("echo", json!({"message": "Hello, world!"})),
|
||||
ToolCall::new("add", json!({"a": 1, "b": 2})),
|
||||
ToolCall::new("longRunningOperation", json!({"duration": 1, "steps": 5})),
|
||||
ToolCall::new("structuredContent", json!({"location": "11238"})),
|
||||
],
|
||||
vec![]
|
||||
)]
|
||||
#[test_case(
|
||||
vec!["github-mcp-server", "stdio"],
|
||||
vec![
|
||||
CallToolRequestParam { name: "get_file_contents".into(), arguments: Some(object!({
|
||||
ToolCall::new("get_file_contents", json!({
|
||||
"owner": "block",
|
||||
"repo": "goose",
|
||||
"path": "README.md",
|
||||
"sha": "ab62b863c1666232a67048b6c4e10007a2a5b83c"
|
||||
}))},
|
||||
})),
|
||||
],
|
||||
vec!["GITHUB_PERSONAL_ACCESS_TOKEN"]
|
||||
)]
|
||||
#[test_case(
|
||||
vec!["uvx", "mcp-server-fetch"],
|
||||
vec![
|
||||
CallToolRequestParam { name: "fetch".into(), arguments: Some(object!({
|
||||
ToolCall::new("fetch", json!({
|
||||
"url": "https://example.com",
|
||||
})) }
|
||||
})),
|
||||
],
|
||||
vec![]
|
||||
)]
|
||||
#[test_case(
|
||||
vec!["cargo", "run", "--quiet", "-p", "goose-server", "--bin", "goosed", "--", "mcp", "developer"],
|
||||
vec![
|
||||
CallToolRequestParam { name: "text_editor".into(), arguments: Some(object!({
|
||||
ToolCall::new("text_editor", json!({
|
||||
"command": "view",
|
||||
"path": "~/goose/crates/goose/tests/tmp/goose.txt"
|
||||
}))},
|
||||
CallToolRequestParam { name: "text_editor".into(), arguments: Some(object!({
|
||||
})),
|
||||
ToolCall::new("text_editor", json!({
|
||||
"command": "str_replace",
|
||||
"path": "~/goose/crates/goose/tests/tmp/goose.txt",
|
||||
"old_str": "# goose",
|
||||
"new_str": "# goose (modified by test)"
|
||||
}))},
|
||||
})),
|
||||
// Test shell command to verify file was modified
|
||||
CallToolRequestParam { name: "shell".into(), arguments: Some(object!({
|
||||
ToolCall::new("shell", json!({
|
||||
"command": "cat ~/goose/crates/goose/tests/tmp/goose.txt"
|
||||
})) },
|
||||
})),
|
||||
// Test text_editor tool to restore original content
|
||||
CallToolRequestParam { name: "text_editor".into(), arguments: Some(object!({
|
||||
ToolCall::new("text_editor", json!({
|
||||
"command": "str_replace",
|
||||
"path": "~/goose/crates/goose/tests/tmp/goose.txt",
|
||||
"old_str": "# goose (modified by test)",
|
||||
"new_str": "# goose"
|
||||
}))},
|
||||
CallToolRequestParam { name: "list_windows".into(), arguments: Some(object!({})) },
|
||||
})),
|
||||
ToolCall::new("list_windows", json!({})),
|
||||
],
|
||||
vec![]
|
||||
)]
|
||||
#[tokio::test]
|
||||
async fn test_replayed_session(
|
||||
command: Vec<&str>,
|
||||
tool_calls: Vec<CallToolRequestParam>,
|
||||
tool_calls: Vec<ToolCall>,
|
||||
required_envs: Vec<&str>,
|
||||
) {
|
||||
let replay_file_name = command
|
||||
@@ -158,12 +159,10 @@ async fn test_replayed_session(
|
||||
#[allow(clippy::redundant_closure_call)]
|
||||
let result = (async || -> Result<(), Box<dyn std::error::Error>> {
|
||||
extension_manager.add_extension(extension_config).await?;
|
||||
|
||||
let mut results = Vec::new();
|
||||
for tool_call in tool_calls {
|
||||
let tool_call = CallToolRequestParam {
|
||||
name: format!("test__{}", tool_call.name).into(),
|
||||
arguments: tool_call.arguments,
|
||||
};
|
||||
let tool_call = ToolCall::new(format!("test__{}", tool_call.name), tool_call.arguments);
|
||||
let result = extension_manager
|
||||
.dispatch_tool_call(tool_call, CancellationToken::default())
|
||||
.await;
|
||||
|
||||
Reference in New Issue
Block a user