From 3fff527e2254a9f7bc8a519801184e6452d3ab5e Mon Sep 17 00:00:00 2001 From: Matysh Date: Wed, 26 Aug 2026 00:11:43 +0300 Subject: [PATCH] test: detach Windows mutation worktree dependencies safely Issue: #282 User-Visible: no --- scripts/mutation-gate.mjs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/mutation-gate.mjs b/scripts/mutation-gate.mjs index cd182c73..110a4b6b 100644 --- a/scripts/mutation-gate.mjs +++ b/scripts/mutation-gate.mjs @@ -30,7 +30,8 @@ import { spawnSync } from 'node:child_process'; import { - cpSync, existsSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync, + cpSync, existsSync, mkdtempSync, readFileSync, rmSync, symlinkSync, unlinkSync, + writeFileSync, } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; @@ -3016,6 +3017,11 @@ function makeWorktree() { } function dropWorktree(dir) { + // On Windows a directory junction can be traversed by recursive worktree + // cleanup. Detach it first; otherwise removing the mutant may empty the real + // repository's node_modules target instead of deleting only the junction. + const modules = join(dir, 'node_modules'); + if (existsSync(modules)) unlinkSync(modules); spawnSync('git', ['-C', repoRoot, 'worktree', 'remove', '--force', dir], { encoding: 'utf8' }); rmSync(dir, { recursive: true, force: true }); }