Skip to content

Commit 8fbd901

Browse files
test(write-to-file): cover directory release ordering when the denied-path report rejects
Review follow-up: rename the preview-open case to match its assertions and add an isEditing=false case that adopts directories, rejects the report, and asserts removeAdoptedDirectories runs before reset. writeToFileTool.spec 74 passed.
1 parent 629b9f5 commit 8fbd901

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ describe("writeToFileTool", () => {
942942
writeToFileTool["taskPartialStreamState"].clear()
943943
}
944944
})
945-
it("still releases adopted directories and resets when the discard report also rejects", async () => {
945+
it("still reaches the diff-view reset when the discard report also rejects", async () => {
946946
// The early-exit teardown discards the preview, then reports a failed discard through
947947
// say(). That report is wrapped in .catch, but the directory release and the reset must
948948
// still run: a rejected report must not skip them.
@@ -973,6 +973,34 @@ describe("writeToFileTool", () => {
973973
}
974974
})
975975

976+
it("releases adopted directories before reset when the denied-path report rejects", async () => {
977+
// With no preview open (isEditing=false), releaseEarlyDirectories is the only
978+
// directory cleanup owner: the removal must run before reset() clears createdDirs.
979+
// The denied-path report rejecting must not skip either step.
980+
mockCline.diffViewProvider.isEditing = false
981+
await executeWriteFileTool({ content: "" }, { isPartial: true })
982+
await executeWriteFileTool({ content: "" }, { isPartial: true })
983+
expect(mockCline.diffViewProvider.open).not.toHaveBeenCalled()
984+
985+
mockCline.say.mockRejectedValue(new Error("report failed"))
986+
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {})
987+
988+
try {
989+
await executeWriteFileTool({}, { accessAllowed: false }).catch(() => {})
990+
991+
expect(mockCline.diffViewProvider.removeAdoptedDirectories).toHaveBeenCalledTimes(1)
992+
expect(mockCline.diffViewProvider.reset).toHaveBeenCalledTimes(1)
993+
// Ordering: reset() drops createdDirs, so removal must happen first.
994+
expect(mockCline.diffViewProvider.removeAdoptedDirectories.mock.invocationCallOrder[0]).toBeLessThan(
995+
mockCline.diffViewProvider.reset.mock.invocationCallOrder[0],
996+
)
997+
} finally {
998+
errorSpy.mockRestore()
999+
mockCline.say.mockResolvedValue(undefined)
1000+
writeToFileTool["taskPartialStreamState"].clear()
1001+
}
1002+
})
1003+
9761004
it("discards a streamed preview when the completed call lacks a path", async () => {
9771005
// Streaming can open the diff view and fill it with unapproved content before the
9781006
// completed call reaches execute(). A malformed completed call must not just reset:

0 commit comments

Comments
 (0)