Skip to content

Commit d3c9557

Browse files
author
Zoo (VP)
committed
fix(tools): process queued messages when terminal command finishes
1 parent bac8adc commit d3c9557

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

‎src/core/tools/ExecuteCommandTool.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ export class ExecuteCommandTool extends BaseTool<"execute_command"> {
203203
}
204204

205205
pushToolResult(result)
206+
task.processQueuedMessages()
206207
} catch (error: unknown) {
207208
// Invalidate pending ask from first execution to prevent race condition
208209
task.supersedePendingAsk()
@@ -222,6 +223,7 @@ export class ExecuteCommandTool extends BaseTool<"execute_command"> {
222223
}
223224

224225
pushToolResult(result)
226+
task.processQueuedMessages()
225227
} else {
226228
// Command was submitted but shell integration lost track of it — show warning.
227229
await task.say("shell_integration_warning")

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

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ describe("executeCommandTool", () => {
8888
recordToolUsage: vitest.fn().mockReturnValue({} as ToolUsage),
8989
recordToolError: vitest.fn(),
9090
supersedePendingAsk: vitest.fn(),
91+
processQueuedMessages: vitest.fn(),
9192
providerRef: {
9293
deref: vitest.fn().mockResolvedValue({
9394
contextProxy: {
@@ -497,6 +498,74 @@ describe("executeCommandTool", () => {
497498
})
498499
})
499500

501+
describe("Queued message processing", () => {
502+
it("processes queued messages after the command completes", async () => {
503+
mockToolUse.params.command = "echo test"
504+
mockToolUse.nativeArgs = { command: "echo test" }
505+
506+
await executeCommandTool.handle(mockCline as unknown as Task, mockToolUse, {
507+
askApproval: mockAskApproval as unknown as AskApproval,
508+
handleError: mockHandleError as unknown as HandleError,
509+
pushToolResult: mockPushToolResult as unknown as PushToolResult,
510+
})
511+
512+
expect(mockPushToolResult).toHaveBeenCalled()
513+
expect(mockCline.processQueuedMessages).toHaveBeenCalledTimes(1)
514+
})
515+
516+
it("processes queued messages after the execa fallback retry completes", async () => {
517+
const shellError = new executeCommandModule.ShellIntegrationError("startup failed", false)
518+
const failedProcess = Object.assign(Promise.reject(shellError), {
519+
continue: vitest.fn(),
520+
abort: vitest.fn(),
521+
})
522+
const successfulProcess = Object.assign(Promise.resolve(), {
523+
continue: vitest.fn(),
524+
abort: vitest.fn(),
525+
})
526+
const successfulTerminalProcess = successfulProcess as unknown as RooTerminalProcess
527+
528+
vitest
529+
.mocked(TerminalRegistry.getOrCreateTerminal)
530+
.mockResolvedValueOnce({
531+
runCommand: vitest.fn().mockReturnValue(failedProcess),
532+
getCurrentWorkingDirectory: vitest.fn().mockReturnValue("/test/workspace"),
533+
} as never)
534+
.mockResolvedValueOnce({
535+
runCommand: vitest.fn().mockImplementation((_command: string, callbacks: RooTerminalCallbacks) => {
536+
void callbacks.onCompleted?.("", successfulTerminalProcess)
537+
callbacks.onShellExecutionComplete?.({ exitCode: 0 }, successfulTerminalProcess)
538+
return successfulProcess
539+
}),
540+
getCurrentWorkingDirectory: vitest.fn().mockReturnValue("/test/workspace"),
541+
} as never)
542+
543+
await executeCommandTool.handle(mockCline as unknown as Task, mockToolUse, {
544+
askApproval: mockAskApproval as unknown as AskApproval,
545+
handleError: mockHandleError as unknown as HandleError,
546+
pushToolResult: mockPushToolResult as unknown as PushToolResult,
547+
})
548+
549+
expect(mockPushToolResult).toHaveBeenCalled()
550+
expect(mockCline.processQueuedMessages).toHaveBeenCalledTimes(1)
551+
})
552+
553+
it("does not process queued messages when the user rejects the command", async () => {
554+
mockAskApproval.mockResolvedValue(false)
555+
mockToolUse.params.command = "echo test"
556+
mockToolUse.nativeArgs = { command: "echo test" }
557+
558+
await executeCommandTool.handle(mockCline as unknown as Task, mockToolUse, {
559+
askApproval: mockAskApproval as unknown as AskApproval,
560+
handleError: mockHandleError as unknown as HandleError,
561+
pushToolResult: mockPushToolResult as unknown as PushToolResult,
562+
})
563+
564+
expect(mockPushToolResult).not.toHaveBeenCalled()
565+
expect(mockCline.processQueuedMessages).not.toHaveBeenCalled()
566+
})
567+
})
568+
500569
describe("Command execution timeout configuration", () => {
501570
it("should include timeout parameter in ExecuteCommandOptions", () => {
502571
// This test verifies that the timeout configuration is properly typed

0 commit comments

Comments
 (0)