11// Write Cli Startup Metadata tests cover write cli startup metadata script behavior.
2- import { spawn } from "node:child_process" ;
2+ import { spawn , spawnSync } from "node:child_process" ;
33import { EventEmitter } from "node:events" ;
44import { mkdirSync , readFileSync , writeFileSync } from "node:fs" ;
55import path from "node:path" ;
@@ -10,6 +10,11 @@ import { resolveWindowsTaskkillPath } from "../../scripts/lib/windows-taskkill.m
1010import { __testing , writeCliStartupMetadata } from "../../scripts/write-cli-startup-metadata.ts" ;
1111import { createScriptTestHarness } from "./test-helpers.js" ;
1212
13+ vi . mock ( "node:child_process" , async ( importOriginal ) => {
14+ const actual = await importOriginal < typeof import ( "node:child_process" ) > ( ) ;
15+ return { ...actual , spawnSync : vi . fn ( actual . spawnSync ) } ;
16+ } ) ;
17+
1318// These subprocess tests use explicit ready/close signals; timeout only catches broken fixtures.
1419const LOAD_SENSITIVE_PROCESS_TIMEOUT_MS = process . env . CI ? 30_000 : 15_000 ;
1520
@@ -114,6 +119,28 @@ async function waitForChildClose(
114119describe ( "write-cli-startup-metadata" , ( ) => {
115120 const { createTempDir } = createScriptTestHarness ( ) ;
116121
122+ it ( "hard-kills synchronous source root help after its timeout" , ( ) => {
123+ const spawnSyncMock = vi . mocked ( spawnSync ) ;
124+ const successfulRender = {
125+ error : undefined ,
126+ output : [ null , "Usage: openclaw\n" , "" ] ,
127+ pid : 123 ,
128+ signal : null ,
129+ status : 0 ,
130+ stderr : "" ,
131+ stdout : "Usage: openclaw\n" ,
132+ } ;
133+ spawnSyncMock . mockReturnValueOnce ( successfulRender ) ;
134+
135+ expect ( __testing . renderSourceRootHelpText ( ) ) . toBe ( "Usage: openclaw\n" ) ;
136+
137+ expect ( spawnSyncMock ) . toHaveBeenCalledOnce ( ) ;
138+ expect ( spawnSyncMock . mock . calls [ 0 ] ?. [ 2 ] ) . toMatchObject ( {
139+ killSignal : "SIGKILL" ,
140+ timeout : 120_000 ,
141+ } ) ;
142+ } ) ;
143+
117144 it ( "fails command help rendering when captured output exceeds the byte limit" , async ( ) => {
118145 await expect (
119146 __testing . spawnText ( [ "--eval" , "process.stdout.write('x'.repeat(2048))" ] , {
0 commit comments