From 90e60b414595f510d6f519e5087ce7b7943ae38c Mon Sep 17 00:00:00 2001 From: Tom Boucher Date: Sat, 16 May 2026 13:05:45 -0400 Subject: [PATCH] fix(3597): avoid cleanup EPERM when cwd is inside tmp test dir --- tests/helpers.cjs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/helpers.cjs b/tests/helpers.cjs index 8aa5d58a8..f1cacb109 100644 --- a/tests/helpers.cjs +++ b/tests/helpers.cjs @@ -104,12 +104,19 @@ function createTempGitProject(prefix = 'gsd-test-') { } function cleanup(tmpDir) { + if (typeof tmpDir !== 'string' || tmpDir.length === 0) return; + const target = path.resolve(tmpDir); + const cwd = path.resolve(process.cwd()); + if (cwd === target || cwd.startsWith(`${target}${path.sep}`)) { + // Windows cannot remove a directory that is the current working directory. + process.chdir(path.dirname(target)); + } // maxRetries/retryDelay absorbs transient Windows EBUSY where AV scanners, // file-indexers, or just-exited child processes still hold handles when // teardown runs. On POSIX the retry loop is a no-op (rmSync succeeds first try). // Budget: 20 × 250ms = 5s total — Windows Defender's deferred scan can hold // newly-written files for several seconds on cold runners. - fs.rmSync(tmpDir, { recursive: true, force: true, maxRetries: 20, retryDelay: 250 }); + fs.rmSync(target, { recursive: true, force: true, maxRetries: 20, retryDelay: 250 }); } /**