Skip to content

Commit 7f9ebb4

Browse files
test+fix(checkpoints): correct the delete-ordering mock, kill the handoff-count vacuity, make the move recovery write owner-only
Three review rows on fc11d6d measured true and are addressed here: 1. applyPatchTool.execute.spec - unlink is one shared double and mockRejectedValueOnce orders by call, not by path, arming the rejection on the FIRST delete while the case comment claimed the second. Armed after a resolved call now, and the case asserts both paths were attempted and that exactly two unlinks happened - a first-delete failure stops the loop before the second path. 2. Same file - a handoff that never happened used to be the strongest pass: `invocationCallOrder[0] ?? Infinity` makes any checkpoint order beat an absent handoff. The call count is asserted before the order in both cases (a comparison against Infinity cannot fail when the call never happens). 3. ApplyPatchTool.ts recovery write now uses { encoding: "utf8", mode: 0o600, flag: "wx" } to match the staging write in the same function: a recovery copy holds private content, and truncating whatever already stands at that name would destroy a file instead of preserving it. 4. ClineProvider.spec gained a handler-side round trip for perWriteCheckpoints (updateSettings through the message handler, then globalState.update and getState). Every other per-write assertion in that file drives contextProxy directly, so a handler that dropped the key left them all green. Control (pinned node v22.23.4, .tmp-node22): with the parent impl blob 14ad81b on disk - parent blob verified by git hash-object - a mode/flag assertion on the recovery write fails; with 0827272 it passes. The recovery branch itself still has no test: driving it needs the staging rename, a failing source unlink and a failing destination removal through doubles that are shared and not reset between cases, and two attempts to arm that combination through the execute harness did not reach the branch (logs 1404-recovery-*-node22.log). git grep shows zoo-recovery appears once in the tree - the write site - so no existing assertion covered it before and none was altered. The behavioural change therefore lands with the row left answered-and-open pending a test. Gates: applyPatchTool.execute.spec 31/31 and ClineProvider.spec 322/322 on pinned v22.23.4; vitest.core.config.ts and vitest.misc.config.ts green (core 4158 passed / 9 skipped, misc 2014 passed / 15 skipped) on the same pinned runtime; tsc --noEmit and knip clean on box node v25.9.0; eslint --prune-suppressions --max-warnings=0 clean on all three touched files with .eslintcache cleared after the last prettier write; src/eslint-suppressions.json byte-identical to the parent 32555c4; the new handler test uses no cast because that file sits at its suppressed no-explicit-any budget of 195. No locale file touched: check-translations compares keys across locales and all 18 settings.json files already carry perWriteCheckpoints, so the wording clarification is a translator-visible change left answered-and-open rather than 17 machine-translated strings pushed on a maintainer's behalf. Co-Authored-By: Claude <[email protected]>
1 parent fc11d6d commit 7f9ebb4

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

‎src/core/tools/ApplyPatchTool.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,14 @@ export class ApplyPatchTool extends BaseTool<"apply_patch"> {
642642
// the only thing that could be lost: persist it under a recovery name.
643643
const recoveryCandidate = path.join(moveDir, `${moveBase}.zoo-recovery-${moveStamp}`)
644644
try {
645-
await fs.writeFile(recoveryCandidate, newContent, "utf8")
645+
// Same owner-only creation as the staging write above, and O_EXCL rather than
646+
// truncation: a recovery copy holds private content, and silently overwriting
647+
// whatever already stands at that name would destroy a file instead of preserving one.
648+
await fs.writeFile(recoveryCandidate, newContent, {
649+
encoding: "utf8",
650+
mode: 0o600,
651+
flag: "wx",
652+
})
646653
recoveryPath = recoveryCandidate
647654
console.error(
648655
`Failed to restore pre-move state: ${restoreFailure instanceof Error ? restoreFailure.message : String(restoreFailure)}; kept the approved content at ${recoveryCandidate}`,

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,12 @@ describe("ApplyPatchTool.execute - delete file success path", () => {
323323
*** Delete File: src/obsolete.ts
324324
*** Delete File: src/locked.ts
325325
*** End Patch`
326-
// The first delete succeeds; the second fails.
327-
mockedFsPromises.default.unlink.mockRejectedValueOnce(new Error("EPERM: operation not permitted"))
326+
// The first delete succeeds; the second fails. unlink is one shared double and
327+
// mockRejectedValueOnce orders by call, not by path, so the rejection has to be
328+
// armed after a resolved first call - otherwise this case exercises the wrong delete.
329+
mockedFsPromises.default.unlink
330+
.mockResolvedValueOnce(undefined)
331+
.mockRejectedValueOnce(new Error("EPERM: operation not permitted"))
328332

329333
await tool.execute({ patch }, mockTask as Task, {
330334
askApproval: mockAskApproval,
@@ -338,7 +342,17 @@ describe("ApplyPatchTool.execute - delete file success path", () => {
338342
expect(mockedCheckpointSave).toHaveBeenCalledTimes(1)
339343
const checkpointAt = mockedCheckpointSave.mock.invocationCallOrder[0] ?? Infinity
340344
const handoffAt = vi.mocked(mockTask.processQueuedMessages).mock.invocationCallOrder[0] ?? Infinity
345+
// A handoff that never happened used to be the strongest pass in the file: the
346+
// ?? Infinity default makes any checkpoint order beat an absent handoff, so the
347+
// count is asserted before the order is compared.
348+
expect(vi.mocked(mockTask.processQueuedMessages).mock.calls.length).toBeGreaterThan(0)
341349
expect(checkpointAt).toBeLessThan(handoffAt)
350+
// Which delete ran is what the mock ordering is for: both paths were attempted
351+
// and exactly two unlinks happened - a first-delete failure would have stopped
352+
// the loop before the second path was reached.
353+
expect(mockedFsPromises.default.unlink).toHaveBeenCalledTimes(2)
354+
expect(mockedFsPromises.default.unlink).toHaveBeenCalledWith(expect.stringMatching(/[\\/]obsolete\.ts$/))
355+
expect(mockedFsPromises.default.unlink).toHaveBeenCalledWith(expect.stringMatching(/[\\/]locked\.ts$/))
342356
})
343357
it("persists a partial-state checkpoint when a later handler rejects outright after an earlier write", async () => {
344358
const patch = `*** Begin Patch
@@ -362,6 +376,8 @@ describe("ApplyPatchTool.execute - delete file success path", () => {
362376
expect(mockedCheckpointSave).toHaveBeenCalledTimes(1)
363377
const checkpointAt = mockedCheckpointSave.mock.invocationCallOrder[0] ?? Infinity
364378
const handoffAt = vi.mocked(mockTask.processQueuedMessages).mock.invocationCallOrder[0] ?? Infinity
379+
// Same vacuity as the case above: assert the handoff happened, then its order.
380+
expect(vi.mocked(mockTask.processQueuedMessages).mock.calls.length).toBeGreaterThan(0)
365381
expect(checkpointAt).toBeLessThan(handoffAt)
366382
expect(mockHandleError).toHaveBeenCalled()
367383
})

‎src/core/webview/__tests__/ClineProvider.spec.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4214,6 +4214,23 @@ describe("ClineProvider", () => {
42144214
expect(state.perWriteCheckpoints).toBe(true)
42154215
})
42164216

4217+
test("persists per-write checkpoints sent through updateSettings to the message handler", async () => {
4218+
await provider.resolveWebviewView(mockWebviewView)
4219+
// No cast: this file is already at its suppressed no-explicit-any budget (195), and
4220+
// the double's call list is untyped, so the handler comes out of it directly.
4221+
const messageHandler = mockWebviewView.webview.onDidReceiveMessage.mock.calls[0][0]
4222+
4223+
await messageHandler({ type: "updateSettings", updatedSettings: { perWriteCheckpoints: false } })
4224+
4225+
// Through the handler rather than straight into the proxy: every other per-write
4226+
// assertion in this file drives contextProxy directly, so a handler that dropped
4227+
// this key would have left all of them green.
4228+
expect(updateGlobalStateSpy).toHaveBeenCalledWith("perWriteCheckpoints", false)
4229+
expect(mockContext.globalState.update).toHaveBeenCalledWith("perWriteCheckpoints", false)
4230+
const state = await provider.getState()
4231+
expect(state.perWriteCheckpoints).toBe(false)
4232+
})
4233+
42174234
test("getStateToPostToWebview returns the saved per-write checkpoints setting", async () => {
42184235
await provider.resolveWebviewView(mockWebviewView)
42194236
await provider.contextProxy.setValue("perWriteCheckpoints", true)

0 commit comments

Comments
 (0)