From 1ac2c814210f7c83297fa1d84d4cfb6cfedc4947 Mon Sep 17 00:00:00 2001 From: daniel-lxs Date: Tue, 2 Dec 2025 22:15:17 -0500 Subject: [PATCH] test: add regression test for malformed native tool call hang fix Adds a test that reads the actual Task.ts source code and verifies that the broken condition (filtering out tool_use blocks) is not present, preventing future regressions of https://github.com/RooCodeInc/Roo-Code/pull/9758 --- src/core/task/__tests__/Task.spec.ts | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/core/task/__tests__/Task.spec.ts b/src/core/task/__tests__/Task.spec.ts index 4bae9c49d09..1c9f772dc4e 100644 --- a/src/core/task/__tests__/Task.spec.ts +++ b/src/core/task/__tests__/Task.spec.ts @@ -1967,3 +1967,40 @@ describe("Queued message processing after condense", () => { expect(taskB.messageQueueService.isEmpty()).toBe(true) }) }) + +describe("Partial tool_use blocks at stream end", () => { + /** + * Regression test for: https://github.com/RooCodeInc/Roo-Code/pull/9758 + * + * The bug: malformed native tool calls leave partial=true, causing infinite hang. + * + * The fix at Task.ts line ~2947 must be: + * if (partialBlocks.length > 0) { presentAssistantMessage(this) } + * + * THE BROKEN CONDITION (causes infinite hang): + * if (partialBlocks.length > 0 && partialBlocks.some(block => block.type !== "tool_use")) + * + * This test reads the actual Task.ts source code and verifies the fix is correct. + */ + it("Task.ts must NOT filter out tool_use blocks when calling presentAssistantMessage", async () => { + const fs = await import("fs") + const path = await import("path") + + // Read Task.ts source + const taskTsPath = path.join(__dirname, "..", "Task.ts") + const taskSource = fs.readFileSync(taskTsPath, "utf-8") + + // The BROKEN pattern we must NOT have: + const hasBrokenCondition = taskSource.includes('partialBlocks.some((block) => block.type !== "tool_use")') + + // The CORRECT pattern we MUST have: + const hasCorrectCondition = taskSource.includes( + "if (partialBlocks.length > 0) {\n\t\t\t\t\t// If there is content to update", + ) + + // The code MUST NOT use the broken condition (filtering out tool_use) + expect(hasBrokenCondition).toBe(false) + // The code MUST use the correct condition (simple length check) + expect(hasCorrectCondition).toBe(true) + }) +})