Skip to content

Commit ac20ae6

Browse files
committed
test(terminal): cover fallback anchor for command_output ask delay
1 parent 0632cb7 commit ac20ae6

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/core/tools/__tests__/executeCommandTool.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,33 @@ describe("executeCommandTool", () => {
538538
expect(mockPushToolResult.mock.calls[0][0]).toContain("still running")
539539
})
540540

541+
it("falls back to the command dispatch time when execution start is never reported", async () => {
542+
vitest.useFakeTimers()
543+
mockCline.ask.mockResolvedValue({ response: "messageResponse", text: "keep going", images: undefined })
544+
const terminal = await setupControllableTerminal()
545+
546+
const handlePromise = handleCommand("sleep 60")
547+
548+
await vitest.waitFor(() => expect(terminal.callbacks).toBeDefined())
549+
const callbacks = terminal.callbacks!
550+
const proc = terminal.proc as unknown as RooTerminalProcess
551+
552+
// No onShellExecutionStarted: the pre-runCommand anchor applies.
553+
await callbacks.onLine("working...\n", proc)
554+
await vitest.advanceTimersByTimeAsync(executeCommandModule.COMMAND_OUTPUT_ASK_DELAY_MS)
555+
556+
expect(mockCline.ask).toHaveBeenCalledWith("command_output", "")
557+
558+
await callbacks.onCompleted!("working...\n", proc)
559+
callbacks.onShellExecutionComplete!({ exitCode: 0 }, proc)
560+
terminal.resolveProcess()
561+
await vitest.advanceTimersByTimeAsync(100)
562+
563+
await handlePromise
564+
565+
expect(mockPushToolResult).toHaveBeenCalled()
566+
})
567+
541568
it("swallows ask errors without failing the command", async () => {
542569
vitest.useFakeTimers()
543570
mockCline.ask.mockRejectedValue(new Error("Current ask promise was ignored"))

0 commit comments

Comments
 (0)