@@ -90,6 +90,10 @@ vi.mock("./windows-port-pids.js", () => ({
9090 mockReadWindowsProcessArgsResult ( pid , timeoutMs ) ,
9191} ) ) ;
9292
93+ vi . mock ( "./windows-install-roots.js" , ( ) => ( {
94+ getWindowsInstallRoots : ( ) => ( { systemRoot : "C:\\Windows" } ) ,
95+ } ) ) ;
96+
9397import { resolveLsofCommandSync } from "./ports-lsof.js" ;
9498let __testing : typeof import ( "./restart-stale-pids.js" ) . __testing ;
9599let cleanStaleGatewayProcessesSync : typeof import ( "./restart-stale-pids.js" ) . cleanStaleGatewayProcessesSync ;
@@ -980,8 +984,10 @@ describe.skipIf(isWindows)("restart-stale-pids", () => {
980984
981985 it ( "does not report Windows pids as killed when taskkill fails" , ( ) => {
982986 const origDescriptor = Object . getOwnPropertyDescriptor ( process , "platform" ) ;
987+ const originalSystemRoot = process . env . SystemRoot ;
983988 const stalePid = process . pid + 911 ;
984989 Object . defineProperty ( process , "platform" , { value : "win32" , configurable : true } ) ;
990+ process . env . SystemRoot = "C:\\PoisonedWindows" ;
985991 try {
986992 let fakeNow = 0 ;
987993 __testing . setDateNowOverride ( ( ) => fakeNow ) ;
@@ -1012,12 +1018,17 @@ describe.skipIf(isWindows)("restart-stale-pids", () => {
10121018
10131019 expect ( cleanStaleGatewayProcessesSync ( ) ) . toEqual ( [ ] ) ;
10141020 expect ( mockSpawnSync ) . toHaveBeenCalledWith (
1015- expect . stringContaining ( " taskkill.exe") ,
1021+ "C:\\Windows\\System32\\ taskkill.exe",
10161022 [ "/T" , "/PID" , String ( stalePid ) ] ,
10171023 expect . objectContaining ( { timeout : 5000 } ) ,
10181024 ) ;
10191025 } finally {
10201026 __testing . setDateNowOverride ( null ) ;
1027+ if ( originalSystemRoot === undefined ) {
1028+ delete process . env . SystemRoot ;
1029+ } else {
1030+ process . env . SystemRoot = originalSystemRoot ;
1031+ }
10211032 if ( origDescriptor ) {
10221033 Object . defineProperty ( process , "platform" , origDescriptor ) ;
10231034 }
@@ -1063,13 +1074,13 @@ describe.skipIf(isWindows)("restart-stale-pids", () => {
10631074 expect ( cleanStaleGatewayProcessesSync ( ) ) . toEqual ( [ ] ) ;
10641075 expect ( mockSpawnSync ) . toHaveBeenNthCalledWith (
10651076 1 ,
1066- expect . stringContaining ( " taskkill.exe") ,
1077+ "C:\\Windows\\System32\\ taskkill.exe",
10671078 [ "/T" , "/PID" , String ( stalePid ) ] ,
10681079 expect . objectContaining ( { timeout : 5000 } ) ,
10691080 ) ;
10701081 expect ( mockSpawnSync ) . toHaveBeenNthCalledWith (
10711082 2 ,
1072- expect . stringContaining ( " taskkill.exe") ,
1083+ "C:\\Windows\\System32\\ taskkill.exe",
10731084 [ "/F" , "/T" , "/PID" , String ( stalePid ) ] ,
10741085 expect . objectContaining ( { timeout : 5000 } ) ,
10751086 ) ;
0 commit comments