CI 在 windows lane 上红在**清理**而不是断言:
`rmSync(scratch, { recursive: true, force: true })` 抛
`ENOTEMPTY: rmdir …archives-pvpAWR`——刚被 kill 的 zip/tar 子进程(以及刚关闭的
fs.watch / 刚结束的 git 子进程)还没被系统释放句柄,删除于是失败在一个**已经通过**
的用例的 afterEach 里(那一次 2466 个用例全过,只有清理挂掉,整个 lane 变红)。
`maxRetries` + `retryDelay` 正是 Node 为这种场景提供的对策,因此新增
`tests/temp-tree.ts` 的 `removeTree()`,把 30 份 spec(175 处 `{ recursive, force }`
写法)统一换过去,并清掉随之不再使用的 `rmSync` 导入。POSIX 上首次即成功、不触发
重试,行为不变。
本地:typecheck / lint 干净,全量 210 文件 / 2524 通过。
28 lines
1.3 KiB
TypeScript
28 lines
1.3 KiB
TypeScript
/**
|
|
* Temp-tree removal for specs that spawn real child processes or hold OS
|
|
* handles (zip / tar / git / fd / rg / powershell / `fs.watch`) inside the
|
|
* tree they are about to delete.
|
|
*
|
|
* `rmSync(path, { recursive: true, force: true })` is not enough on Windows:
|
|
* a child that was just killed, or a watcher that was just closed, can still
|
|
* hold a handle for a few milliseconds, and the removal then fails with
|
|
* ENOTEMPTY / EBUSY / EPERM **from the cleanup of a test that had already
|
|
* passed** — which is how the Windows lane went red on 2026-10-15
|
|
* (`tests/archive.spec.ts`'s afterEach, `ENOTEMPTY: rmdir …archives-pvpAWR`,
|
|
* on a run where only that cleanup failed and 2466 tests passed).
|
|
*
|
|
* `maxRetries` + `retryDelay` is Node's own remedy for exactly this, so every
|
|
* risky cleanup goes through here instead of repeating the retry inline.
|
|
* POSIX runs are unaffected: the first attempt succeeds and no retry happens.
|
|
*/
|
|
import { rmSync } from 'node:fs'
|
|
|
|
/**
|
|
* Remove one file or directory tree, retrying while a just-closed handle is
|
|
* still being released by the OS.
|
|
* @param path - file or directory to remove (missing paths are ignored).
|
|
*/
|
|
export function removeTree(path: string): void {
|
|
rmSync(path, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 })
|
|
}
|