@@ -2,7 +2,6 @@ import fs from "node:fs/promises";
22import path from "node:path" ;
33import { PassThrough } from "node:stream" ;
44import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
5- import { quoteCmdScriptArg } from "./cmd-argv.js" ;
65import "./test-helpers/schtasks-base-mocks.js" ;
76import {
87 inspectPortUsage ,
@@ -91,11 +90,25 @@ async function writeStartupFallbackEntry(env: Record<string, string>) {
9190 return startupEntryPath ;
9291}
9392
94- function expectStartupFallbackSpawn ( env : Record < string , string > ) {
95- expect ( spawn ) . toHaveBeenCalledWith (
96- "cmd.exe" ,
97- [ "/d" , "/s" , "/c" , quoteCmdScriptArg ( resolveTaskScriptPath ( env ) ) ] ,
98- expect . objectContaining ( { detached : true , stdio : "ignore" , windowsHide : true } ) ,
93+ function expectStartupFallbackSpawn ( ) {
94+ expect ( spawn ) . toHaveBeenCalled ( ) ;
95+ const calls = spawn . mock . calls as unknown as Array <
96+ [ string , readonly string [ ] , Record < string , unknown > ]
97+ > ;
98+ const lastCall = calls [ calls . length - 1 ] ;
99+ if ( ! lastCall ) {
100+ throw new Error ( "expected gateway launch spawn call" ) ;
101+ }
102+ const [ executable , args , options ] = lastCall ;
103+ expect ( executable ) . not . toBe ( "cmd.exe" ) ;
104+ expect ( args ) . toEqual ( expect . arrayContaining ( [ "--port" , "18789" ] ) ) ;
105+ expect ( options ) . toEqual (
106+ expect . objectContaining ( {
107+ detached : true ,
108+ env : expect . objectContaining ( { OPENCLAW_GATEWAY_PORT : "18789" } ) ,
109+ stdio : "ignore" ,
110+ windowsHide : true ,
111+ } ) ,
99112 ) ;
100113}
101114
@@ -197,11 +210,7 @@ describe("Windows startup fallback", () => {
197210 expect ( result . scriptPath ) . toBe ( resolveTaskScriptPath ( env ) ) ;
198211 expect ( startupScript ) . toContain ( 'start "" /min cmd.exe /d /c' ) ;
199212 expect ( startupScript ) . toContain ( "gateway.cmd" ) ;
200- expect ( spawn ) . toHaveBeenCalledWith (
201- "cmd.exe" ,
202- [ "/d" , "/s" , "/c" , quoteCmdScriptArg ( resolveTaskScriptPath ( env ) ) ] ,
203- expect . objectContaining ( { detached : true , stdio : "ignore" , windowsHide : true } ) ,
204- ) ;
213+ expectStartupFallbackSpawn ( ) ;
205214 expect ( childUnref ) . toHaveBeenCalled ( ) ;
206215 expect ( printed ) . toContain ( "Installed Windows login item" ) ;
207216 } ) ;
@@ -216,7 +225,7 @@ describe("Windows startup fallback", () => {
216225 await installGatewayScheduledTask ( env ) ;
217226
218227 await expect ( fs . access ( resolveStartupEntryPath ( env ) ) ) . resolves . toBeUndefined ( ) ;
219- expectStartupFallbackSpawn ( env ) ;
228+ expectStartupFallbackSpawn ( ) ;
220229 } ) ;
221230 } ) ;
222231
@@ -231,18 +240,18 @@ describe("Windows startup fallback", () => {
231240 await installGatewayScheduledTask ( env ) ;
232241
233242 await expect ( fs . access ( resolveStartupEntryPath ( env ) ) ) . resolves . toBeUndefined ( ) ;
234- expectStartupFallbackSpawn ( env ) ;
243+ expectStartupFallbackSpawn ( ) ;
235244 } ) ;
236245 } ) ;
237246
238- it ( "launches the task script directly when schtasks /Run is accepted but never starts the task" , async ( ) => {
247+ it ( "launches through the Startup-style launcher when schtasks /Run is accepted but never starts the task" , async ( ) => {
239248 await withWindowsEnv ( "openclaw-win-startup-" , async ( { env } ) => {
240249 fastForwardTaskStartWait ( ) ;
241250 addAcceptedRunNeverStartsResponses ( ) ;
242251
243252 await installGatewayScheduledTask ( env ) ;
244253
245- expectStartupFallbackSpawn ( env ) ;
254+ expectStartupFallbackSpawn ( ) ;
246255 } ) ;
247256 } ) ;
248257
@@ -388,6 +397,7 @@ describe("Windows startup fallback", () => {
388397 { code : 0 , stdout : "" , stderr : "" } ,
389398 { code : 1 , stdout : "" , stderr : "not found" } ,
390399 ] ) ;
400+ await writeGatewayScript ( env ) ;
391401 await writeStartupFallbackEntry ( env ) ;
392402 inspectPortUsage . mockResolvedValue ( {
393403 port : 18789 ,
@@ -401,7 +411,7 @@ describe("Windows startup fallback", () => {
401411 outcome : "completed" ,
402412 } ) ;
403413 expectGatewayTermination ( 5151 ) ;
404- expectStartupFallbackSpawn ( env ) ;
414+ expectStartupFallbackSpawn ( ) ;
405415 } ) ;
406416 } ) ;
407417
@@ -432,7 +442,7 @@ describe("Windows startup fallback", () => {
432442 outcome : "completed" ,
433443 } ) ;
434444
435- expectStartupFallbackSpawn ( env ) ;
445+ expectStartupFallbackSpawn ( ) ;
436446 } ) ;
437447 } ) ;
438448
0 commit comments