Skip to content

Commit 3fa7910

Browse files
committed
test(read-files): exercise native batch in real extension host
1 parent e588c13 commit 3fa7910

2 files changed

Lines changed: 105 additions & 0 deletions

File tree

‎apps/vscode-e2e/src/fixtures/read-file.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { LLMock } from "@copilotkit/aimock"
2+
import { READ_FILES_TOOL_NAME } from "@roo-code/types"
23

34
import {
45
isToolResultExpectation,
@@ -15,6 +16,51 @@ type ReadFileResultFixture = {
1516
}
1617

1718
export function addReadFileResultFixtures(mock: InstanceType<typeof LLMock>) {
19+
const batchCallId = "call_native_read_files_batch_001"
20+
mock.addFixture({
21+
match: { userMessage: "NATIVE_READ_FILES_BATCH_SMOKE" },
22+
response: {
23+
toolCalls: [
24+
{
25+
name: READ_FILES_TOOL_NAME,
26+
id: batchCallId,
27+
arguments: JSON.stringify({
28+
entries: [
29+
{ path: "batch-read-slice.txt", offset: 2, limit: 1 },
30+
{
31+
path: "batch-read-block.ts",
32+
mode: "indentation",
33+
indentation: { anchor_line: 2, include_header: false },
34+
},
35+
],
36+
}),
37+
},
38+
],
39+
},
40+
})
41+
mock.addFixture({
42+
match: {
43+
predicate: (req) =>
44+
toolResultContains(req, batchCallId, [
45+
'Entry 1: "batch-read-slice.txt"',
46+
'Entry 2: "batch-read-block.ts"',
47+
"2 | second",
48+
"return 'hello'",
49+
]),
50+
},
51+
response: {
52+
toolCalls: [
53+
{
54+
name: "attempt_completion",
55+
id: "call_native_read_files_batch_002",
56+
arguments: JSON.stringify({
57+
result: "NATIVE_READ_FILES_BATCH_OK: second and hello were returned in one batch result.",
58+
}),
59+
},
60+
],
61+
},
62+
})
63+
1864
const fixtures: ReadFileResultFixture[] = [
1965
{
2066
toolCallId: "call_read_file_simple_001",
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import * as assert from "node:assert/strict"
2+
import * as fs from "node:fs/promises"
3+
import path from "node:path"
4+
import * as vscode from "vscode"
5+
import { RooCodeEventName, type ClineMessage } from "@roo-code/types"
6+
import { waitFor } from "../utils"
7+
import { setDefaultSuiteTimeout } from "../test-utils"
8+
9+
suite("Zoo Code native batch reading", function () {
10+
setDefaultSuiteTimeout(this)
11+
12+
test("returns slice and structural reads in one native tool result", async () => {
13+
const workspace = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath
14+
assert.ok(workspace, "Expected the test workspace")
15+
const slicePath = path.join(workspace, "batch-read-slice.txt")
16+
const blockPath = path.join(workspace, "batch-read-block.ts")
17+
await fs.writeFile(slicePath, "first\nsecond")
18+
await fs.writeFile(blockPath, "function greet() {\n return 'hello'\n}")
19+
const api = globalThis.api
20+
const messages: ClineMessage[] = []
21+
const onMessage = ({ message }: { message: ClineMessage }) => messages.push(message)
22+
api.on(RooCodeEventName.Message, onMessage)
23+
try {
24+
await api.clearCurrentTask()
25+
await api.startNewTask({
26+
configuration: {
27+
mode: "code",
28+
autoApprovalEnabled: true,
29+
alwaysAllowReadOnly: true,
30+
alwaysAllowReadOnlyOutsideWorkspace: true,
31+
},
32+
text: "NATIVE_READ_FILES_BATCH_SMOKE: Read the two known files in one native batch call using independent slice and structural parameters.",
33+
})
34+
await waitFor(
35+
() =>
36+
messages.some(
37+
(message) =>
38+
message.say === "completion_result" && message.text?.includes("NATIVE_READ_FILES_BATCH_OK"),
39+
),
40+
{ timeout: 60_000 },
41+
)
42+
assert.ok(
43+
messages.some(
44+
(message) => message.say === "completion_result" && message.text?.includes("second and hello"),
45+
),
46+
"The mock only completes after a single batch tool result contains both file reads",
47+
)
48+
assert.deepEqual(
49+
messages.filter((message) => message.say === "error").map((message) => message.text),
50+
[],
51+
)
52+
} finally {
53+
api.off(RooCodeEventName.Message, onMessage)
54+
await api.clearCurrentTask()
55+
await fs.rm(slicePath, { force: true })
56+
await fs.rm(blockPath, { force: true })
57+
}
58+
})
59+
})

0 commit comments

Comments
 (0)