@@ -10,11 +10,28 @@ import {
1010 shouldSkipSparseTsgoGuardError ,
1111} from "../../scripts/lib/tsgo-sparse-guard.mts" ;
1212import { resolveTsgoTimeoutMs } from "../../scripts/run-tsgo.mts" ;
13- import { waitForChildClose , waitForDead , waitForPidFile } from "../helpers/process-wait.js" ;
13+ import {
14+ isProcessAlive ,
15+ waitForChildClose ,
16+ waitForDead ,
17+ waitForPidFile ,
18+ } from "../helpers/process-wait.js" ;
1419import { createScriptTestHarness } from "./test-helpers.js" ;
1520
1621const { createTempDir } = createScriptTestHarness ( ) ;
1722
23+ it ( "runs the installed compiler version through the real tsgo wrapper" , ( ) => {
24+ const result = spawnSync ( process . execPath , [ path . resolve ( "scripts/run-tsgo.mjs" ) , "--version" ] , {
25+ encoding : "utf8" ,
26+ timeout : 25_000 ,
27+ killSignal : "SIGKILL" ,
28+ } ) ;
29+
30+ expect ( result . error ) . toBeUndefined ( ) ;
31+ expect ( result . status ) . toBe ( 0 ) ;
32+ expect ( result . stdout ) . toMatch ( / ^ V e r s i o n \d / m) ;
33+ } , 30_000 ) ;
34+
1835describe ( "run-tsgo sparse guard" , ( ) => {
1936 it ( "ends sparse-checkout failures with the stable failure trailer" , ( ) => {
2037 const cwd = createTempDir ( "openclaw-run-tsgo-" ) ;
@@ -304,6 +321,59 @@ describe.skipIf(process.platform === "win32")("run-tsgo watchdog", () => {
304321 }
305322 }
306323
324+ it ( "rejects and drains compiler descendants left after a successful leader exit" , async ( ) => {
325+ const cwd = createTempDir ( "openclaw-run-tsgo-lingering-" ) ;
326+ const descendantPidPath = path . join ( cwd , "descendant.pid" ) ;
327+ writeFakeTsgo (
328+ cwd ,
329+ `#!/usr/bin/env node
330+ const fs = require("node:fs");
331+ const { spawn } = require("node:child_process");
332+ fs.writeFileSync("fake-tsgo.pid", String(process.pid));
333+ const child = spawn(process.execPath, ["-e", ${ JSON . stringify ( `
334+ const fs = require("node:fs");
335+ setInterval(() => {}, 1000);
336+ fs.writeFileSync(process.argv[1], String(process.pid));
337+ process.send("ready");
338+ process.disconnect();
339+ ` ) } , ${ JSON . stringify ( descendantPidPath ) } ], { stdio: ["ignore", "ignore", "ignore", "ipc"] });
340+ child.once("message", () => process.exit(0));
341+ ` ,
342+ ) ;
343+ let observedPids : Array < number | undefined > = [ ] ;
344+ let liveBeforeTeardown : number [ ] = [ ] ;
345+ try {
346+ const result = runFakeTsgo ( cwd , undefined , ( pid ) => {
347+ observedPids = [
348+ pid ,
349+ fs . existsSync ( descendantPidPath )
350+ ? Number ( fs . readFileSync ( descendantPidPath , "utf8" ) )
351+ : undefined ,
352+ ] ;
353+ liveBeforeTeardown = observedPids . filter (
354+ ( owned ) : owned is number => owned !== undefined && isProcessAlive ( owned ) ,
355+ ) ;
356+ } ) ;
357+ expect ( result . error ) . toBeUndefined ( ) ;
358+ expect (
359+ observedPids . every ( ( pid ) => pid !== undefined && Number . isSafeInteger ( pid ) && pid > 1 ) ,
360+ ) . toBe ( true ) ;
361+ expect . soft ( result . status ) . toBe ( 1 ) ;
362+ expect . soft ( result . stderr ) . toContain ( "EPROCESSGROUP_CLEANUP_FAILED" ) ;
363+ expect
364+ . soft ( liveBeforeTeardown , "compiler descendants must be absent before fixture teardown" )
365+ . toEqual ( [ ] ) ;
366+ } finally {
367+ for ( const pidFile of [ descendantPidPath , path . join ( cwd , "fake-tsgo.pid" ) ] ) {
368+ if ( ! fs . existsSync ( pidFile ) ) continue ;
369+ const pid = Number ( fs . readFileSync ( pidFile , "utf8" ) ) ;
370+ if ( ! Number . isSafeInteger ( pid ) || pid <= 1 ) continue ;
371+ if ( isProcessAlive ( pid ) ) process . kill ( pid , "SIGKILL" ) ;
372+ await waitForDead ( pid , 2_000 ) ;
373+ }
374+ }
375+ } , 30_000 ) ;
376+
307377 it . each ( [ { bound : "0" } , { bound : "abc" } ] ) (
308378 "explains a rejected OPENCLAW_TSGO_TIMEOUT_MS of $bound instead of crashing" ,
309379 ( { bound } ) => {
0 commit comments