Skip to content

Commit 748f8e3

Browse files
committed
test: assert partial-failure write-through call and release error details
- The partial write-through failure test now asserts the flush call, its item payload, and the logged write-through error next to the original unlink rejection. - The unrelated release error test asserts the exact log arguments and error object.
1 parent 981b668 commit 748f8e3

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎src/core/task-persistence/__tests__/TaskHistoryStore.spec.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,15 @@ describe("TaskHistoryStore", () => {
393393

394394
// The deletion failure is the primary error and must not be masked
395395
// by the failed write-through.
396+
const consoleError = vi.spyOn(console, "error").mockImplementation(() => {})
396397
await expect(store.deleteMany([first.id, failed.id, later.id])).rejects.toBe(unlinkError)
398+
expect(onWrite).toHaveBeenCalledTimes(4)
399+
expect(onWrite.mock.calls[3][0].map((item: HistoryItem) => item.id)).not.toContain(first.id)
400+
expect(consoleError).toHaveBeenCalledWith(
401+
"[TaskHistoryStore] deleteMany write-through after partial deletion failed:",
402+
expect.objectContaining({ message: "write-through failed" }),
403+
)
404+
consoleError.mockRestore()
397405

398406
vi.mocked(fs.unlink).mockImplementation(async (filePath) => actualFs.unlink(filePath))
399407
})

‎src/utils/__tests__/fileLock.spec.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,15 @@ describe("fileLock", () => {
9595
})
9696

9797
it("keeps reporting success when an unrelated release error occurs", async () => {
98-
underlyingRelease.mockRejectedValue(new Error("unlock failed"))
98+
const unlockError = new Error("unlock failed")
99+
underlyingRelease.mockRejectedValue(unlockError)
99100

100101
await expect(
101102
withFileLock(
102103
absoluteFilePath,
103104
vi.fn(async () => "done"),
104105
),
105106
).resolves.toBe("done")
106-
expect(consoleError).toHaveBeenCalled()
107+
expect(consoleError).toHaveBeenCalledWith(`Failed to release lock for ${absoluteFilePath}:`, unlockError)
107108
})
108109
})

0 commit comments

Comments
 (0)