Skip to content

Commit 55cb374

Browse files
roomoteedelauna
authored andcommitted
test(e2e): restore replay result validation
1 parent d7776cf commit 55cb374

3 files changed

Lines changed: 61 additions & 14 deletions

File tree

apps/vscode-e2e/src/fixtures/list-files.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type ListFilesFixture = {
66
toolName: string
77
arguments: string
88
toolCallId: string
9-
expected?: string[]
9+
expected: string[]
1010
result: string
1111
id: string
1212
}
@@ -32,6 +32,7 @@ export function addListFilesResultFixtures(mock: InstanceType<typeof LLMock>) {
3232
toolName: "list_files",
3333
arguments: '{"path":"list-files-tool-fixture","recursive":false}',
3434
toolCallId: "call_list_files_non_recursive_001",
35+
expected: ["root-file-1.txt", ".hidden-file", "nested/"],
3536
result: "The non-recursive listing for `list-files-tool-fixture` includes `root-file-1.txt`, `root-file-2.js`, `config.yaml`, `README.md`, `.hidden-file`, and the `nested/` directory.",
3637
id: "call_list_files_non_recursive_002",
3738
},
@@ -50,7 +51,7 @@ export function addListFilesResultFixtures(mock: InstanceType<typeof LLMock>) {
5051
arguments: '{"path":"list-files-symlink-fixture","recursive":false}',
5152
toolCallId: "call_list_files_symlink_001",
5253
expected: ["link-to-file.txt", "source/"],
53-
result: "The symlink fixture listing shows the original `source/` directory and its `source-file.txt`, alongside the symlinked entries in `list-files-symlink-fixture`.",
54+
result: "The symlink fixture listing shows the original `source/` directory and its `source-file.txt`, plus the symlink entry `link-to-file.txt` in `list-files-symlink-fixture`.",
5455
id: "call_list_files_symlink_002",
5556
},
5657
{
@@ -83,9 +84,7 @@ export function addListFilesResultFixtures(mock: InstanceType<typeof LLMock>) {
8384
mock.addFixture({
8485
match: {
8586
toolCallId: fixture.toolCallId,
86-
...(fixture.expected && {
87-
predicate: (req) => toolResultContains(req, fixture.toolCallId, fixture.expected!),
88-
}),
87+
predicate: (req) => toolResultContains(req, fixture.toolCallId, fixture.expected),
8988
},
9089
response: {
9190
toolCalls: [

apps/vscode-e2e/src/fixtures/search-files.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,42 @@
11
import { LLMock } from "@copilotkit/aimock"
2+
import type { ChatCompletionRequest, ChatMessage } from "@copilotkit/aimock"
23

34
type SearchFilesFixture = {
45
userMessagePattern: string
56
toolName: string
67
arguments: string
78
toolCallId: string
9+
expected: string[]
810
result: string
911
id: string
1012
}
1113

14+
function toolResultContains(req: ChatCompletionRequest, toolCallId: string, expected: string[]) {
15+
const messages = Array.isArray(req?.messages) ? req.messages : []
16+
const toolMessage = messages.find(
17+
(message: ChatMessage) => message?.role === "tool" && message.tool_call_id === toolCallId,
18+
)
19+
20+
const content = toolMessage?.content
21+
if (typeof content !== "string") {
22+
return false
23+
}
24+
25+
return expected.every((text) => content.includes(text))
26+
}
27+
1228
export function addSearchFilesResultFixtures(mock: InstanceType<typeof LLMock>) {
1329
const fixtures: SearchFilesFixture[] = [
1430
{
1531
userMessagePattern: "SEARCH_FILES_FUNCTIONS_SMOKE",
1632
toolName: "search_files",
1733
arguments: '{"path":"search-files-tool-fixture","regex":"function\\\\s+\\\\w+"}',
1834
toolCallId: "call_search_files_functions_001",
35+
expected: [
36+
"# search-files-tool-fixture/search-fixture.js",
37+
"function calculateTotal(items) {",
38+
"function validateUser(user) {",
39+
],
1940
result: "The function search found declarations including `calculateTotal`, `validateUser`, and `formatCurrency`.",
2041
id: "call_search_files_functions_002",
2142
},
@@ -24,6 +45,11 @@ export function addSearchFilesResultFixtures(mock: InstanceType<typeof LLMock>)
2445
toolName: "search_files",
2546
arguments: '{"path":"search-files-tool-fixture","regex":"TODO.*"}',
2647
toolCallId: "call_search_files_todo_001",
48+
expected: [
49+
"# search-files-tool-fixture/search-fixture.js",
50+
"// TODO: Add more validation functions",
51+
"// TODO: Implement user fetching",
52+
],
2753
result: "The TODO search found matching TODO entries in the fixture files, including the validation and user-fetching notes.",
2854
id: "call_search_files_todo_002",
2955
},
@@ -32,6 +58,7 @@ export function addSearchFilesResultFixtures(mock: InstanceType<typeof LLMock>)
3258
toolName: "search_files",
3359
arguments: '{"path":"search-files-tool-fixture","regex":"interface\\\\s+\\\\w+","file_pattern":"*.ts"}',
3460
toolCallId: "call_search_files_typescript_001",
61+
expected: ["# search-files-tool-fixture/search-fixture.ts", "interface User {", "interface Product {"],
3562
result: "The TypeScript-only search found the `User` and `Product` interface definitions.",
3663
id: "call_search_files_typescript_002",
3764
},
@@ -40,6 +67,7 @@ export function addSearchFilesResultFixtures(mock: InstanceType<typeof LLMock>)
4067
toolName: "search_files",
4168
arguments: '{"path":"search-files-tool-fixture","regex":"\\"\\\\w+\\":\\\\s*","file_pattern":"*.json"}',
4269
toolCallId: "call_search_files_json_001",
70+
expected: ["# search-files-tool-fixture/search-config.json", '"name": "test-app",', '"dependencies": {'],
4371
result: "The JSON search found configuration keys such as `name`, `version`, and `dependencies` in `search-config.json`.",
4472
id: "call_search_files_json_002",
4573
},
@@ -48,6 +76,11 @@ export function addSearchFilesResultFixtures(mock: InstanceType<typeof LLMock>)
4876
toolName: "search_files",
4977
arguments: '{"path":"search-files-tool-fixture","regex":"function\\\\s+(format|debounce)"}',
5078
toolCallId: "call_search_files_nested_001",
79+
expected: [
80+
"# search-files-tool-fixture/nested/nested-search.js",
81+
"function formatCurrency(amount) {",
82+
"function debounce(func, wait) {",
83+
],
5184
result: "The nested-directory search found the utility functions `formatCurrency` and `debounce`.",
5285
id: "call_search_files_nested_002",
5386
},
@@ -56,6 +89,11 @@ export function addSearchFilesResultFixtures(mock: InstanceType<typeof LLMock>)
5689
toolName: "search_files",
5790
arguments: '{"path":"search-files-tool-fixture","regex":"(import|export).*","file_pattern":"*.{js,ts}"}',
5891
toolCallId: "call_search_files_complex_regex_001",
92+
expected: [
93+
"# search-files-tool-fixture/search-fixture.js",
94+
"export { calculateTotal, validateUser }",
95+
"module.exports = { formatCurrency, debounce }",
96+
],
5997
result: "The import/export search found the `export` statement in the JavaScript fixture module.",
6098
id: "call_search_files_complex_regex_002",
6199
},
@@ -64,6 +102,7 @@ export function addSearchFilesResultFixtures(mock: InstanceType<typeof LLMock>)
64102
toolName: "search_files",
65103
arguments: '{"path":"search-files-tool-fixture","regex":"nonExistentPattern12345"}',
66104
toolCallId: "call_search_files_no_match_001",
105+
expected: ["Found 0 results."],
67106
result: "No matches were found for `nonExistentPattern12345` in the search fixture directory.",
68107
id: "call_search_files_no_match_002",
69108
},
@@ -73,6 +112,11 @@ export function addSearchFilesResultFixtures(mock: InstanceType<typeof LLMock>)
73112
arguments:
74113
'{"path":"search-files-tool-fixture","regex":"(class\\\\s+\\\\w+|async\\\\s+\\\\w+)","file_pattern":"*.ts"}',
75114
toolCallId: "call_search_files_class_method_001",
115+
expected: [
116+
"# search-files-tool-fixture/search-fixture.ts",
117+
"class UserService {",
118+
"async getUser(id: number): Promise<User> {",
119+
],
76120
result: "The class-and-method search found `UserService` and its async `getUser` method in the TypeScript fixture.",
77121
id: "call_search_files_class_method_002",
78122
},
@@ -97,6 +141,7 @@ export function addSearchFilesResultFixtures(mock: InstanceType<typeof LLMock>)
97141
mock.addFixture({
98142
match: {
99143
toolCallId: fixture.toolCallId,
144+
predicate: (req) => toolResultContains(req, fixture.toolCallId, fixture.expected),
100145
},
101146
response: {
102147
toolCalls: [

apps/vscode-e2e/src/suite/tools/list-files.test.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,18 @@ This directory contains various files and subdirectories for testing the list_fi
350350
// Wait for task completion
351351
await waitFor(() => taskCompleted, { timeout: 120_000 })
352352

353-
const completionMessage = messages.find(
354-
(m) =>
355-
m.type === "say" &&
356-
(m.say === "completion_result" || m.say === "text") &&
357-
(m.text?.includes("source-file.txt") ||
358-
m.text?.includes("link-to-file.txt") ||
359-
m.text?.includes("source/")),
360-
)
361-
assert.ok(completionMessage, "AI should have summarized the symlink directory contents")
353+
const completionMessage = messages.find((m) => {
354+
if (m.type !== "say" || (m.say !== "completion_result" && m.say !== "text")) {
355+
return false
356+
}
357+
358+
const text = m.text ?? ""
359+
const mentionsOriginalEntry = text.includes("source-file.txt") || text.includes("source/")
360+
const mentionsSymlinkEntry = text.includes("link-to-file.txt") || text.includes("link-to-dir")
361+
362+
return mentionsOriginalEntry && mentionsSymlinkEntry
363+
})
364+
assert.ok(completionMessage, "AI should have summarized both the original and symlinked directory contents")
362365

363366
console.log("Test passed! Symlinked files and directories are now visible")
364367

0 commit comments

Comments
 (0)