| 1 | #!/usr/bin/env node |
| 2 | |
| 3 | const assert = require("node:assert/strict"); |
| 4 | const test = require("node:test"); |
| 5 | |
| 6 | const { |
| 7 | CLEANUP_MAX_RETRIES, |
| 8 | CLEANUP_RETRY_DELAY_MS, |
| 9 | removeSmokeWorkspace, |
| 10 | } = require("./npm-wrapper-smoke"); |
| 11 | |
| 12 | test("npm wrapper cleanup bounds retries for transient Windows removal races", async () => { |
| 13 | const calls = []; |
| 14 | await removeSmokeWorkspace("C:\\Temp\\codewhale-smoke", async (...args) => { |
| 15 | calls.push(args); |
| 16 | }); |
| 17 | |
| 18 | assert.deepEqual(calls, [ |
| 19 | [ |
| 20 | "C:\\Temp\\codewhale-smoke", |
| 21 | { |
| 22 | force: true, |
| 23 | recursive: true, |
| 24 | maxRetries: CLEANUP_MAX_RETRIES, |
| 25 | retryDelay: CLEANUP_RETRY_DELAY_MS, |
| 26 | }, |
| 27 | ], |
| 28 | ]); |
| 29 | assert.ok(Number.isInteger(CLEANUP_MAX_RETRIES)); |
| 30 | assert.ok(CLEANUP_MAX_RETRIES > 0); |
| 31 | assert.ok(Number.isFinite(CLEANUP_RETRY_DELAY_MS)); |
| 32 | assert.ok(CLEANUP_RETRY_DELAY_MS > 0); |
| 33 | }); |
| 34 | |
| 35 | test("npm wrapper cleanup surfaces persistent removal failures", async () => { |
| 36 | const failure = Object.assign(new Error("directory remains non-empty"), { |
| 37 | code: "ENOTEMPTY", |
| 38 | }); |
| 39 | |
| 40 | await assert.rejects( |
| 41 | removeSmokeWorkspace("C:\\Temp\\codewhale-smoke", async () => { |
| 42 | throw failure; |
| 43 | }), |
| 44 | (error) => error === failure, |
| 45 | ); |
| 46 | }); |
| 47 |