Skip to content

Commit 6012893

Browse files
roomoteedelauna
authored andcommitted
chore: tighten list_files replay predicates
1 parent d77bf8d commit 6012893

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
import { LLMock } from "@copilotkit/aimock"
2+
import type { ChatCompletionRequest, ChatMessage } from "@copilotkit/aimock"
23

34
type ListFilesFixture = {
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 addListFilesResultFixtures(mock: InstanceType<typeof LLMock>) {
1329
const fixtures: ListFilesFixture[] = [
1430
{
@@ -24,6 +40,7 @@ export function addListFilesResultFixtures(mock: InstanceType<typeof LLMock>) {
2440
toolName: "list_files",
2541
arguments: '{"path":"list-files-tool-fixture","recursive":true}',
2642
toolCallId: "call_list_files_recursive_001",
43+
expected: ["nested/", "nested/deep/"],
2744
result: "The recursive listing for `list-files-tool-fixture` reached the nested structure and includes `nested/`, `deep/`, and `deep-nested-file.ts`.",
2845
id: "call_list_files_recursive_002",
2946
},
@@ -32,6 +49,7 @@ export function addListFilesResultFixtures(mock: InstanceType<typeof LLMock>) {
3249
toolName: "list_files",
3350
arguments: '{"path":"list-files-symlink-fixture","recursive":false}',
3451
toolCallId: "call_list_files_symlink_001",
52+
expected: ["link-to-file.txt", "source/"],
3553
result: "The symlink fixture listing shows the original `source/` directory and its `source-file.txt`, alongside the symlinked entries in `list-files-symlink-fixture`.",
3654
id: "call_list_files_symlink_002",
3755
},
@@ -40,7 +58,8 @@ export function addListFilesResultFixtures(mock: InstanceType<typeof LLMock>) {
4058
toolName: "list_files",
4159
arguments: '{"path":".","recursive":false}',
4260
toolCallId: "call_list_files_workspace_root_001",
43-
result: "The workspace root listing includes top-level directories like `apps/` and `packages/`, plus files such as `README.md`.",
61+
expected: ["list-files-tool-fixture/"],
62+
result: "The workspace root currently contains the `list-files-tool-fixture/` and `list-files-symlink-fixture/` test directories.",
4463
id: "call_list_files_workspace_root_002",
4564
},
4665
]
@@ -64,6 +83,9 @@ export function addListFilesResultFixtures(mock: InstanceType<typeof LLMock>) {
6483
mock.addFixture({
6584
match: {
6685
toolCallId: fixture.toolCallId,
86+
...(fixture.expected && {
87+
predicate: (req) => toolResultContains(req, fixture.toolCallId, fixture.expected!),
88+
}),
6789
},
6890
response: {
6991
toolCalls: [

0 commit comments

Comments
 (0)