|
| 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