@@ -4,6 +4,7 @@ import os from "node:os";
44import path from "node:path" ;
55import { afterEach , beforeAll , beforeEach , describe , expect , it , vi } from "vitest" ;
66import { captureFullEnv } from "../test-utils/env.js" ;
7+ import { getWindowsCmdExePath } from "./windows-install-roots.js" ;
78
89const spawnMock = vi . hoisted ( ( ) => vi . fn ( ) ) ;
910const resolvePreferredOpenClawTmpDirMock = vi . hoisted ( ( ) => vi . fn ( ( ) => os . tmpdir ( ) ) ) ;
@@ -100,13 +101,14 @@ describe("relaunchGatewayScheduledTask", () => {
100101 } ) ;
101102
102103 const result = relaunchGatewayScheduledTask ( { OPENCLAW_PROFILE : "work" } ) ;
104+ const cmdExePath = getWindowsCmdExePath ( ) ;
103105
104106 expect ( result . ok ) . toBe ( true ) ;
105107 expect ( result . method ) . toBe ( "schtasks" ) ;
106108 expect ( result . tried ) . toContain ( 'schtasks /Run /TN "OpenClaw Gateway (work)"' ) ;
107- expect ( result . tried ) . toContain ( `cmd.exe /d /s /c ${ seenCommandArg } ` ) ;
109+ expect ( result . tried ) . toContain ( `${ cmdExePath } /d /s /c ${ seenCommandArg } ` ) ;
108110 const spawnCall = requireFirstMockCall ( spawnMock , "restart helper spawn" ) ;
109- expect ( spawnCall [ 0 ] ) . toBe ( "cmd.exe" ) ;
111+ expect ( spawnCall [ 0 ] ) . toBe ( cmdExePath ) ;
110112 expect ( spawnCall [ 1 ] ) . toStrictEqual ( [ "/d" , "/s" , "/c" , seenCommandArg ] ) ;
111113 expect ( spawnCall [ 2 ] ) . toStrictEqual ( {
112114 detached : true ,
@@ -200,7 +202,7 @@ describe("relaunchGatewayScheduledTask", () => {
200202 if ( typeof commandArg !== "string" ) {
201203 throw new Error ( "expected quoted restart helper path" ) ;
202204 }
203- expect ( spawnCall [ 0 ] ) . toBe ( "cmd.exe" ) ;
205+ expect ( spawnCall [ 0 ] ) . toBe ( getWindowsCmdExePath ( ) ) ;
204206 expect ( commandArgs ) . toStrictEqual ( [ "/d" , "/s" , "/c" , commandArg ] ) ;
205207 expect ( commandArg . startsWith ( '"' ) ) . toBe ( true ) ;
206208 expect ( commandArg . endsWith ( '"' ) ) . toBe ( true ) ;
@@ -231,7 +233,7 @@ describe("relaunchGatewayScheduledTask", () => {
231233 const script = fs . readFileSync ( scriptPath , "utf8" ) ;
232234 expect ( script ) . toContain ( `schtasks /Query /TN` ) ;
233235 expect ( script ) . toContain ( ":fallback" ) ;
234- expect ( script ) . toContain ( `start "" /min cmd.exe /d /c` ) ;
236+ expect ( script ) . toContain ( `start "" /min ${ getWindowsCmdExePath ( ) } /d /c` ) ;
235237 expect ( script ) . toContain ( taskScriptPath ) ;
236238 } ) ;
237239} ) ;
0 commit comments