Skip to content

Commit 0310c99

Browse files
committed
test(tools): pin the partial-failure handoff semantics of the patch checkpoint fix
Upstream handed off queued messages in each handler right after every successful write, so a patch whose first write succeeded and whose later write failed - or whose later file failed the access check and returned early - still drained the queue. The deferral preserves that condition and only moves its timing after the checkpoint attempt; requiring full-patch success would strand queued input on any partial failure, a behavior change beyond the checkpoint-ordering fix this unit ships. Two tests pin the fidelity semantics against future regressions in either direction. Review feedback on PR 1404 (thread on the finally-block handoff).
1 parent 484d5cf commit 0310c99

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

‎src/core/tools/__tests__/applyPatchTool.execute.spec.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,57 @@ describe("ApplyPatchTool.execute - delete file success path", () => {
231231
expect(mockTask.processQueuedMessages).not.toHaveBeenCalled()
232232
})
233233

234+
it("hands off queued messages after a partial patch failure", async () => {
235+
// Fidelity: upstream handed off in each handler right after every
236+
// successful write, so a patch whose first write succeeded and whose
237+
// later write failed still drained the queue. The deferral preserves
238+
// that condition (a write happened) and only moves its timing after
239+
// the checkpoint attempt; requiring full-patch success would strand
240+
// queued input on any partial failure.
241+
const mixedPatch = `*** Begin Patch
242+
*** Add File: src/new.ts
243+
+hello
244+
*** Delete File: src/obsolete.ts
245+
*** End Patch`
246+
// Add sees no existing file and succeeds; the delete's unlink fails.
247+
mockedFileExistsAtPath.mockResolvedValueOnce(false)
248+
mockedFsPromises.default.unlink.mockRejectedValueOnce(new Error("EBUSY"))
249+
250+
await tool.execute({ patch: mixedPatch }, mockTask as Task, {
251+
askApproval: mockAskApproval,
252+
handleError: mockHandleError,
253+
pushToolResult: mockPushToolResult,
254+
})
255+
256+
// No whole-patch checkpoint (the patch failed), but the successful
257+
// write still hands off.
258+
expect(mockedCheckpointSave).not.toHaveBeenCalled()
259+
expect(mockTask.processQueuedMessages).toHaveBeenCalled()
260+
})
261+
262+
it("hands off queued messages when a later file fails the access check", async () => {
263+
// The rooignored path makes execute return early, but the earlier
264+
// successful write had already handed off upstream - the deferred
265+
// handoff preserves that too.
266+
const mixedPatch = `*** Begin Patch
267+
*** Delete File: src/obsolete.ts
268+
*** Add File: src/secret.ts
269+
+hidden
270+
*** End Patch`
271+
const validateAccess = mockTask.rooIgnoreController?.validateAccess as MockedFunction<
272+
(path: string) => boolean
273+
>
274+
validateAccess.mockReturnValueOnce(true).mockReturnValueOnce(false)
275+
276+
await tool.execute({ patch: mixedPatch }, mockTask as Task, {
277+
askApproval: mockAskApproval,
278+
handleError: mockHandleError,
279+
pushToolResult: mockPushToolResult,
280+
})
281+
282+
expect(mockTask.processQueuedMessages).toHaveBeenCalled()
283+
})
284+
234285
it("does not record a checkpoint when perWriteCheckpoints is disabled", async () => {
235286
// Structural cast for the test double (matches the mock style used for the controllers above).
236287
const ref = (mockTask["providerRef"] as unknown as { deref: MockedFunction<() => unknown> }).deref

0 commit comments

Comments
 (0)