Skip to content

Commit fd440d2

Browse files
committed
test(task): pin the restore against mixed turns and the closing thinking tag
What: add two resumeTaskFromHistory cases for the partial-text restore, one where the matching assistant turn also carries a tool_use block and one where the matching text carries a closing </thinking> tag with its whitespace. Why: the existing cases exercised only a text-only turn and only the opening <thinking> tag, so the block-type filter and the closing-tag half of the strip were unpinned against regression. Impact: no production change; coverage only. Both cases were mutation-proven against the code they cover.
1 parent 4bef5f8 commit fd440d2

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2520,6 +2520,60 @@ describe("Task persistence", () => {
25202520
expect(mockSaveTaskMessages).not.toHaveBeenCalled()
25212521
})
25222522

2523+
it.each([
2524+
{
2525+
// The turn that reaches API history right before the presenter release can
2526+
// also carry tool_use blocks; only the text block has to match. This shape
2527+
// additionally re-enters the synthetic tool_result path below, so the restore
2528+
// must survive it rather than depend on the turn being text-only.
2529+
name: "the matching assistant turn also carries a tool_use block",
2530+
assistantContent: [
2531+
{ type: "text" as const, text: "Half a sentence" },
2532+
{ type: "tool_use" as const, id: "toolu_1", name: "read_file", input: {} },
2533+
],
2534+
},
2535+
{
2536+
// Pins the closing-tag half of the strip, which the `<thinking>` case above
2537+
// leaves unexercised: the bubble drops the markup, the accumulator keeps it.
2538+
name: "the matching text carries a closing thinking tag and its whitespace",
2539+
assistantContent: [{ type: "text" as const, text: "Half a sentence\n</thinking>" }],
2540+
},
2541+
])("restores the partial text bubble when $name", async ({ assistantContent }) => {
2542+
mockReadTaskMessages.mockResolvedValue([
2543+
{ ts: 1, type: "say", say: "text", text: "Original task" },
2544+
{ ts: 2, type: "say", say: "text", text: "Half a sentence", partial: true },
2545+
])
2546+
mockReadApiMessages.mockResolvedValue([
2547+
{ role: "user", content: [{ type: "text", text: "Original task" }] },
2548+
{ role: "assistant", content: assistantContent },
2549+
])
2550+
2551+
const task = new Task({
2552+
provider: mockProvider,
2553+
apiConfiguration: mockApiConfig,
2554+
historyItem: {
2555+
id: "issue-257-restore-shape",
2556+
number: 1,
2557+
ts: 1,
2558+
task: "Original task",
2559+
tokensIn: 10,
2560+
tokensOut: 5,
2561+
totalCost: 0.001,
2562+
},
2563+
startTask: false,
2564+
})
2565+
vi.spyOn(task, "ask").mockImplementation(async () => {
2566+
expect(task.clineMessages).toContainEqual(
2567+
expect.objectContaining({ say: "text", text: "Half a sentence", partial: false }),
2568+
)
2569+
expect(task.clineMessages).not.toContainEqual(expect.objectContaining({ partial: true }))
2570+
throw new Error("stop after hydration")
2571+
})
2572+
2573+
await expect(getTaskPersistenceAccess(task).resumeTaskFromHistory()).rejects.toThrow("stop after hydration")
2574+
expect(mockSaveTaskMessages).not.toHaveBeenCalled()
2575+
})
2576+
25232577
it.each([
25242578
{
25252579
name: "the last assistant turn holds different text",

0 commit comments

Comments
 (0)