Skip to content

Commit bacb853

Browse files
committed
test: unskip use_mcp_tool e2e suite
1 parent f73ae42 commit bacb853

3 files changed

Lines changed: 371 additions & 849 deletions

File tree

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import * as path from "path"
2+
3+
import { LLMock } from "@copilotkit/aimock"
4+
5+
const TEST_DIR_NAME = "use-mcp-tool-fixture"
6+
const FILESYSTEM_SERVER_NAME = "filesystem"
7+
8+
type UseMcpToolFixture = {
9+
userMessagePattern: string
10+
toolCallId: string
11+
toolName: string
12+
toolArguments?: Record<string, unknown>
13+
serverName?: string
14+
result: string
15+
id: string
16+
}
17+
18+
export function addUseMcpToolResultFixtures(mock: InstanceType<typeof LLMock>, workspaceDir: string) {
19+
const readFilePath = path.join(workspaceDir, TEST_DIR_NAME, "mcp-read-target.txt")
20+
const writeFilePath = path.join(workspaceDir, TEST_DIR_NAME, "mcp-write-target.txt")
21+
22+
const fixtures: UseMcpToolFixture[] = [
23+
{
24+
userMessagePattern: "USE_MCP_TOOL_READ_FILE_SMOKE",
25+
toolCallId: "call_use_mcp_tool_read_file_001",
26+
toolName: "read_file",
27+
toolArguments: { path: readFilePath },
28+
result: "Read the requested file through the MCP filesystem server.",
29+
id: "call_use_mcp_tool_read_file_002",
30+
},
31+
{
32+
userMessagePattern: "USE_MCP_TOOL_WRITE_FILE_SMOKE",
33+
toolCallId: "call_use_mcp_tool_write_file_001",
34+
toolName: "write_file",
35+
toolArguments: { path: writeFilePath, content: "Hello from MCP!" },
36+
result: "Created the requested file through the MCP filesystem server.",
37+
id: "call_use_mcp_tool_write_file_002",
38+
},
39+
{
40+
userMessagePattern: "USE_MCP_TOOL_LIST_DIRECTORY_SMOKE",
41+
toolCallId: "call_use_mcp_tool_list_directory_001",
42+
toolName: "list_directory",
43+
toolArguments: { path: path.join(workspaceDir, TEST_DIR_NAME) },
44+
result: "Listed the requested directory through the MCP filesystem server.",
45+
id: "call_use_mcp_tool_list_directory_002",
46+
},
47+
{
48+
userMessagePattern: "USE_MCP_TOOL_DIRECTORY_TREE_SMOKE",
49+
toolCallId: "call_use_mcp_tool_directory_tree_001",
50+
toolName: "directory_tree",
51+
toolArguments: { path: path.join(workspaceDir, TEST_DIR_NAME) },
52+
result: "Returned the directory tree through the MCP filesystem server.",
53+
id: "call_use_mcp_tool_directory_tree_002",
54+
},
55+
{
56+
userMessagePattern: "USE_MCP_TOOL_GET_FILE_INFO_SMOKE",
57+
toolCallId: "call_use_mcp_tool_get_file_info_001",
58+
toolName: "get_file_info",
59+
toolArguments: { path: readFilePath },
60+
result: "Returned the requested file metadata through the MCP filesystem server.",
61+
id: "call_use_mcp_tool_get_file_info_002",
62+
},
63+
{
64+
userMessagePattern: "USE_MCP_TOOL_UNKNOWN_SERVER_SMOKE",
65+
toolCallId: "call_use_mcp_tool_unknown_server_001",
66+
serverName: "nonexistent-server",
67+
toolName: "read_file",
68+
toolArguments: { path: readFilePath },
69+
result: "Handled the missing MCP server gracefully.",
70+
id: "call_use_mcp_tool_unknown_server_002",
71+
},
72+
]
73+
74+
for (const fixture of fixtures) {
75+
mock.addFixture({
76+
match: {
77+
userMessage: new RegExp(fixture.userMessagePattern),
78+
},
79+
response: {
80+
toolCalls: [
81+
{
82+
name: "use_mcp_tool",
83+
arguments: JSON.stringify({
84+
server_name: fixture.serverName ?? FILESYSTEM_SERVER_NAME,
85+
tool_name: fixture.toolName,
86+
arguments: fixture.toolArguments,
87+
}),
88+
id: fixture.toolCallId,
89+
},
90+
],
91+
},
92+
})
93+
94+
mock.addFixture({
95+
match: {
96+
toolCallId: fixture.toolCallId,
97+
},
98+
response: {
99+
toolCalls: [
100+
{
101+
name: "attempt_completion",
102+
arguments: JSON.stringify({ result: fixture.result }),
103+
id: fixture.id,
104+
},
105+
],
106+
},
107+
})
108+
}
109+
}

apps/vscode-e2e/src/runTest.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { addExecuteCommandResultFixtures } from "./fixtures/execute-command"
1010
import { addListFilesResultFixtures } from "./fixtures/list-files"
1111
import { addReadFileResultFixtures } from "./fixtures/read-file"
1212
import { addSearchFilesResultFixtures } from "./fixtures/search-files"
13+
import { addUseMcpToolResultFixtures } from "./fixtures/use-mcp-tool"
1314
import { addWriteToFileResultFixtures } from "./fixtures/write-to-file"
1415

1516
async function main() {
@@ -39,6 +40,9 @@ async function main() {
3940
let testWorkspace: string | undefined
4041

4142
try {
43+
// Create a temporary workspace folder for tests
44+
testWorkspace = await fs.mkdtemp(path.join(os.tmpdir(), "roo-test-workspace-"))
45+
4246
if (useMock) {
4347
const fixturesDir = path.resolve(__dirname, "../fixtures")
4448

@@ -67,6 +71,7 @@ async function main() {
6771
addListFilesResultFixtures(mock)
6872
addReadFileResultFixtures(mock)
6973
addSearchFilesResultFixtures(mock)
74+
addUseMcpToolResultFixtures(mock, testWorkspace)
7075
addWriteToFileResultFixtures(mock)
7176

7277
// The modes test (switch_mode → ask) triggers a second API call whose last
@@ -90,9 +95,6 @@ async function main() {
9095

9196
await mock.start()
9297
}
93-
94-
// Create a temporary workspace folder for tests
95-
testWorkspace = await fs.mkdtemp(path.join(os.tmpdir(), "roo-test-workspace-"))
9698
// Get test filter from command line arguments or environment variable
9799
// Usage examples:
98100
// - npm run test:e2e -- --grep "write-to-file"

0 commit comments

Comments
 (0)