| 1 | import assert from "node:assert/strict"; |
| 2 | import { purgeTrashBatch } from "../lib/trashOperations"; |
| 3 | const calls: string[] = []; |
| 4 | let release!: () => void; |
| 5 | const pending = new Promise<void>((resolve) => { release = resolve; }); |
| 6 | const paths = ["a", "b", "a", "c"]; |
| 7 | const batch = purgeTrashBatch(paths, async (path) => { |
| 8 | calls.push(path); |
| 9 | if (path === "a") await pending; |
| 10 | if (path === "b") throw new Error("busy"); |
| 11 | }); |
| 12 | paths.push("later"); |
| 13 | assert.deepEqual(calls, ["a"], "batch executes sequentially"); |
| 14 | release(); |
| 15 | const result = await batch; |
| 16 | assert.deepEqual(calls, ["a", "b", "c"], "snapshot excludes new arrivals and duplicate paths"); |
| 17 | assert.deepEqual(result, { succeeded: ["a", "c"], failed: ["b"] }); |
| 18 | const retryCalls: string[] = []; |
| 19 | await purgeTrashBatch(result.failed, async (path) => { retryCalls.push(path); }); |
| 20 | assert.deepEqual(retryCalls, ["b"], "retry never repeats known successful deletions"); |
| 21 | console.log("PASS trash partial failure, fixed targets, deduplication and explicit failed-only retry"); |
| 22 |