Skip to content

Commit 047c3f8

Browse files
author
s3-1395 lane
committed
test(tools): pin the revert-before-reset order on the parse-failure teardown
1 parent e42a64d commit 047c3f8

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,17 @@ describe("writeToFileTool", () => {
643643
nativeArgs: undefined,
644644
partial: false,
645645
}
646+
// Record the relative order of revertChanges() and reset() (vitest mocks expose
647+
// no invocationCallOrder). This is the only teardown in the test, so nothing else
648+
// can move these two entries.
649+
const diffViewCallOrder: string[] = []
650+
mockCline.diffViewProvider.revertChanges.mockImplementation(async () => {
651+
diffViewCallOrder.push("revert")
652+
})
653+
mockCline.diffViewProvider.reset.mockImplementation(async () => {
654+
diffViewCallOrder.push("reset")
655+
})
656+
646657
await writeToFileTool.handle(mockCline, toolUse as ToolUse<"write_to_file">, {
647658
askApproval: mockAskApproval,
648659
toolCallId: "test-tool-call-id",
@@ -657,6 +668,10 @@ describe("writeToFileTool", () => {
657668
// failure happened, so this is the only revert + reset in the test).
658669
expect(mockCline.diffViewProvider.revertChanges).toHaveBeenCalledTimes(1)
659670
expect(mockCline.diffViewProvider.reset).toHaveBeenCalledTimes(1)
671+
// The counts above pass when the two are swapped. A teardown that resets first
672+
// leaves the streamed content in the document, because reset() clears the state
673+
// revertChanges() reads, so the order is the invariant worth asserting.
674+
expect(diffViewCallOrder).toEqual(["revert", "reset"])
660675
// Per-task state torn down: guard cleared, exact listener detached.
661676
expect(writeToFileTool["taskPartialStreamState"].size).toBe(0)
662677
expect(abortListener).toBeTypeOf("function")

0 commit comments

Comments
 (0)