Skip to content

Commit 6686bbf

Browse files
committed
test(Task): coverage
1 parent 8fa009c commit 6686bbf

3 files changed

Lines changed: 72 additions & 3 deletions

File tree

‎src/core/assistant-message/presentAssistantMessage.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -959,8 +959,7 @@ export async function presentAssistantMessage(cline: Task) {
959959
if (cline.currentStreamingContentIndex < cline.assistantMessageContent.length) {
960960
// There are already more content blocks to stream, so we'll call
961961
// this function ourselves.
962-
presentAssistantMessage(cline)
963-
return
962+
return presentAssistantMessage(cline)
964963
} else {
965964
// CRITICAL FIX: If we're out of bounds and the stream is complete, set userMessageContentReady
966965
// This handles the case where assistantMessageContent is empty or becomes empty after processing
@@ -972,7 +971,7 @@ export async function presentAssistantMessage(cline: Task) {
972971

973972
// Block is partial, but the read stream may have finished.
974973
if (cline.presentAssistantMessageHasPendingUpdates) {
975-
presentAssistantMessage(cline)
974+
return presentAssistantMessage(cline)
976975
}
977976
}
978977

‎src/core/task/Task.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
13191319
if (message) {
13201320
this.interactiveAsk = message
13211321
this.emit(RooCodeEventName.TaskInteractive, this.taskId)
1322+
/* v8 ignore next 3 -- fires inside 2s timer after ask() resolves; not reachable in unit tests */
13221323
void provider?.postMessageToWebview({ type: "interactionRequired" }).catch((error) => {
13231324
console.error("[Task#ask] postMessageToWebview interactionRequired failed:", error)
13241325
})

‎src/core/task/__tests__/Task.spec.ts‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2648,6 +2648,75 @@ describe("Cline", () => {
26482648
updateSpy.mockRestore()
26492649
saveSpy.mockRestore()
26502650
})
2651+
2652+
it("logs (instead of crashing) when updateClineMessage rejects from the ask() ignore-partial path", async () => {
2653+
// Pins the .catch arm on the fire-and-forget updateClineMessage call
2654+
// in ask() when a new partial ask arrives while the previous partial
2655+
// is still pending (AskIgnoredError path).
2656+
const boom = new Error("updateClineMessage boom")
2657+
const updateSpy = vi.spyOn(Task.prototype as any, "updateClineMessage").mockImplementation(async () => {
2658+
throw boom
2659+
})
2660+
2661+
const task = new Task({
2662+
provider: mockProvider,
2663+
apiConfiguration: mockApiConfig,
2664+
task: "test task",
2665+
startTask: false,
2666+
})
2667+
2668+
// Seed a prior partial ask so the isUpdatingPreviousPartial branch fires.
2669+
task.clineMessages.push({
2670+
ts: Date.now() - 1,
2671+
type: "ask",
2672+
ask: "tool",
2673+
text: "partial",
2674+
partial: true,
2675+
})
2676+
2677+
// Sending a new partial of the same type triggers updateClineMessage
2678+
// then throws AskIgnoredError — catch it so the test doesn't fail.
2679+
await task.ask("tool", "updated partial", true).catch(() => {})
2680+
await flushMicrotasks()
2681+
2682+
expect(updateSpy).toHaveBeenCalled()
2683+
expect(consoleErrorSpy).toHaveBeenCalledWith("[Task#ask] updateClineMessage failed:", boom)
2684+
})
2685+
2686+
it("logs (instead of crashing) when updateClineMessage rejects from handleWebviewAskResponse", async () => {
2687+
// Pins the .catch arm on the fire-and-forget updateClineMessage call
2688+
// in handleWebviewAskResponse when marking a tool ask as answered.
2689+
const boom = new Error("updateClineMessage boom")
2690+
const updateSpy = vi.spyOn(Task.prototype as any, "updateClineMessage").mockImplementation(async () => {
2691+
throw boom
2692+
})
2693+
vi.spyOn(Task.prototype as any, "saveClineMessages").mockResolvedValue(undefined)
2694+
2695+
const task = new Task({
2696+
provider: mockProvider,
2697+
apiConfiguration: mockApiConfig,
2698+
task: "test task",
2699+
startTask: false,
2700+
})
2701+
2702+
// Seed an unanswered tool ask so the lastToolAskIndex branch fires.
2703+
task.clineMessages.push({
2704+
ts: Date.now() - 1,
2705+
type: "ask",
2706+
ask: "tool",
2707+
text: "tool call",
2708+
partial: false,
2709+
})
2710+
2711+
task.handleWebviewAskResponse("yesButtonClicked")
2712+
await flushMicrotasks()
2713+
2714+
expect(updateSpy).toHaveBeenCalled()
2715+
expect(consoleErrorSpy).toHaveBeenCalledWith(
2716+
"[Task#handleWebviewAskResponse] updateClineMessage failed:",
2717+
boom,
2718+
)
2719+
})
26512720
})
26522721
})
26532722

0 commit comments

Comments
 (0)