@@ -5,12 +5,10 @@ import fs from "node:fs";
55import os from "node:os" ;
66import nodePath from "node:path" ;
77import { setTimeout as delay } from "node:timers/promises" ;
8- import { pathToFileURL } from "node:url" ;
98import { describe , expect , it , vi } from "vitest" ;
109import {
1110 resolveTestProjectsRunnerEnv ,
1211 resolveTestProjectsRunnerSpawnParams ,
13- runTestProjectsDelegation ,
1412} from "../../scripts/lib/test-projects-delegation.mts" ;
1513import {
1614 DEFAULT_EXTRA_LONG_RUNNING_VITEST_NO_OUTPUT_TIMEOUT_MS ,
@@ -796,92 +794,6 @@ describe("scripts/run-vitest", () => {
796794 } ) ;
797795 } ) ;
798796
799- posixIt ( "cleans delegated test-project children when the wrapper is signaled" , async ( ) => {
800- expect ( runTestProjectsDelegation ) . toBeTypeOf ( "function" ) ;
801- const fixturePath = nodePath . join (
802- os . tmpdir ( ) ,
803- `openclaw-run-vitest-delegated-signal-${ process . pid } -${ Date . now ( ) } .mjs` ,
804- ) ;
805- const childPidPath = nodePath . join (
806- os . tmpdir ( ) ,
807- `openclaw-run-vitest-delegated-child-${ process . pid } -${ Date . now ( ) } .pid` ,
808- ) ;
809- const descendantPidPath = nodePath . join (
810- os . tmpdir ( ) ,
811- `openclaw-run-vitest-delegated-descendant-${ process . pid } -${ Date . now ( ) } .pid` ,
812- ) ;
813-
814- fs . writeFileSync (
815- fixturePath ,
816- [
817- 'import { spawn } from "node:child_process";' ,
818- 'import fs from "node:fs";' ,
819- 'const child = spawn(process.execPath, ["-e", "process.on(\\\'SIGTERM\\\', () => {}); setInterval(() => {}, 1000);"], { stdio: "ignore" });' ,
820- "fs.writeFileSync(process.env.OPENCLAW_DELEGATED_SIGNAL_CHILD_PID, String(process.pid));" ,
821- "fs.writeFileSync(process.env.OPENCLAW_DELEGATED_SIGNAL_DESCENDANT_PID, String(child.pid));" ,
822- "await new Promise(() => {});" ,
823- "" ,
824- ] . join ( "\n" ) ,
825- ) ;
826-
827- const runner = spawn (
828- process . execPath ,
829- [
830- "--import" ,
831- "tsx" ,
832- "--input-type=module" ,
833- "--eval" ,
834- `import { runTestProjectsDelegation } from ${ JSON . stringify (
835- pathToFileURL ( nodePath . resolve ( "scripts/lib/test-projects-delegation.mts" ) ) . href ,
836- ) } ; runTestProjectsDelegation([], process.env, { runnerPath: ${ JSON . stringify ( fixturePath ) } });`,
837- ] ,
838- {
839- env : {
840- ...process . env ,
841- OPENCLAW_DELEGATED_SIGNAL_CHILD_PID : childPidPath ,
842- OPENCLAW_DELEGATED_SIGNAL_DESCENDANT_PID : descendantPidPath ,
843- } ,
844- stdio : "ignore" ,
845- } ,
846- ) ;
847- let childPid = 0 ;
848- let descendantPid = 0 ;
849-
850- try {
851- await waitFor (
852- ( ) => fs . existsSync ( childPidPath ) && fs . existsSync ( descendantPidPath ) ,
853- LOAD_SENSITIVE_PROCESS_TIMEOUT_MS ,
854- ) ;
855- childPid = Number ( fs . readFileSync ( childPidPath , "utf8" ) ) ;
856- descendantPid = Number ( fs . readFileSync ( descendantPidPath , "utf8" ) ) ;
857- expect ( Number . isInteger ( childPid ) ) . toBe ( true ) ;
858- expect ( Number . isInteger ( descendantPid ) ) . toBe ( true ) ;
859- expect ( isProcessAlive ( childPid ) ) . toBe ( true ) ;
860- expect ( isProcessAlive ( descendantPid ) ) . toBe ( true ) ;
861-
862- expect ( runner . pid ) . toBeGreaterThan ( 0 ) ;
863- process . kill ( runner . pid ! , "SIGTERM" ) ;
864- const result = await waitForClose ( runner , LOAD_SENSITIVE_PROCESS_TIMEOUT_MS ) ;
865-
866- expect ( result ) . toEqual ( { code : null , signal : "SIGTERM" } ) ;
867- await waitFor ( ( ) => ! isProcessAlive ( childPid ) , LOAD_SENSITIVE_PROCESS_TIMEOUT_MS ) ;
868- await waitFor ( ( ) => ! isProcessAlive ( descendantPid ) , LOAD_SENSITIVE_PROCESS_TIMEOUT_MS ) ;
869- } finally {
870- if ( runner . pid && isProcessAlive ( runner . pid ) ) {
871- process . kill ( runner . pid , "SIGKILL" ) ;
872- }
873- if ( childPid && isProcessAlive ( childPid ) ) {
874- process . kill ( childPid , "SIGKILL" ) ;
875- }
876- if ( descendantPid && isProcessAlive ( descendantPid ) ) {
877- process . kill ( descendantPid , "SIGKILL" ) ;
878- }
879- fs . rmSync ( fixturePath , { force : true } ) ;
880- fs . rmSync ( childPidPath , { force : true } ) ;
881- fs . rmSync ( descendantPidPath , { force : true } ) ;
882- }
883- } ) ;
884-
885797 it ( "spawns vitest in a detached process group on Unix hosts" , ( ) => {
886798 expect ( resolveVitestSpawnParams ( { PATH : "/usr/bin" } , "darwin" ) ) . toEqual ( {
887799 env : { PATH : "/usr/bin" } ,
0 commit comments