@@ -395,41 +395,64 @@ describe.skipIf(process.platform === "win32")("qa scenario command lifecycle", (
395395 expect ( parentHandlers . size ) . toBe ( 0 ) ;
396396 } ) ;
397397
398- it ( "forwards parent signals, cleans handlers, and preserves interruption details" , async ( ) => {
399- createChild ( ) ;
400- setQaScenarioCommandCleanupTimings ( { killGraceMs : 20 , forceSettleMs : 10 } ) ;
401- let processGroupAlive = true ;
402- processKill . mockImplementation ( ( pid , signal ) => {
403- if ( pid === - 42 && signal === "SIGKILL" ) {
404- processGroupAlive = false ;
405- }
406- if ( pid === - 42 && signal === 0 && ! processGroupAlive ) {
407- throw Object . assign ( new Error ( "gone" ) , { code : "ESRCH" } ) ;
408- }
409- return true ;
410- } ) ;
411-
412- const resultPromise = runCommand ( ) ;
413- const signalHandler = parentHandlers . get ( "SIGTERM" ) as
414- | ( ( signal : ParentSignal ) => void )
415- | undefined ;
416- expect ( signalHandler ) . toBeDefined ( ) ;
417- signalHandler ?.( "SIGTERM" ) ;
418- await vi . advanceTimersByTimeAsync ( 20 ) ;
419- const child = spawnMock . mock . results [ 0 ] ?. value as ChildProcess ;
420- child . emit ( "exit" , null , "SIGKILL" ) ;
421- child . emit ( "close" , null , "SIGKILL" ) ;
422- await vi . advanceTimersByTimeAsync ( 10 ) ;
398+ it . each ( [
399+ {
400+ phase : "running" ,
401+ result : {
402+ exitCode : 1 ,
403+ failureMessage : "scenario-command interrupted by SIGTERM" ,
404+ signal : "SIGTERM" ,
405+ } ,
406+ } ,
407+ { phase : "exited" , result : { exitCode : 7 , signal : null } } ,
408+ {
409+ phase : "timed out" ,
410+ result : {
411+ exitCode : 1 ,
412+ failureMessage : "scenario-command timed out after 100ms" ,
413+ signal : null ,
414+ } ,
415+ } ,
416+ ] ) (
417+ "re-raises a parent signal when the command is $phase without changing its outcome" ,
418+ async ( { phase, result } ) => {
419+ const child = createChild ( ) ;
420+ setQaScenarioCommandCleanupTimings ( { killGraceMs : 20 , forceSettleMs : 10 } ) ;
421+ let processGroupAlive = true ;
422+ processKill . mockImplementation ( ( pid , signal ) => {
423+ if ( pid === - 42 && signal === "SIGKILL" ) {
424+ processGroupAlive = false ;
425+ }
426+ if ( pid === - 42 && signal === 0 && ! processGroupAlive ) {
427+ throw Object . assign ( new Error ( "gone" ) , { code : "ESRCH" } ) ;
428+ }
429+ return true ;
430+ } ) ;
423431
424- await expect ( resultPromise ) . resolves . toEqual ( {
425- exitCode : 1 ,
426- failureMessage : "scenario-command interrupted by SIGTERM" ,
427- signal : "SIGTERM" ,
428- stdout : "" ,
429- stderr : "" ,
430- } ) ;
431- expect ( processKill ) . toHaveBeenCalledWith ( - 42 , "SIGTERM" ) ;
432- expect ( processKill ) . toHaveBeenCalledWith ( process . pid , "SIGTERM" ) ;
433- expect ( parentHandlers . size ) . toBe ( 0 ) ;
434- } ) ;
432+ const resultPromise = runCommand ( 100 ) ;
433+ if ( phase === "exited" ) {
434+ child . emit ( "exit" , 7 , null ) ;
435+ } else if ( phase === "timed out" ) {
436+ await vi . advanceTimersByTimeAsync ( 100 ) ;
437+ }
438+ const signalHandler = parentHandlers . get ( "SIGTERM" ) as
439+ | ( ( signal : ParentSignal ) => void )
440+ | undefined ;
441+ expect ( signalHandler ) . toBeDefined ( ) ;
442+ signalHandler ?.( "SIGTERM" ) ;
443+ await vi . advanceTimersByTimeAsync ( 20 ) ;
444+ child . emit ( "exit" , null , "SIGKILL" ) ;
445+ child . emit ( "close" , null , "SIGKILL" ) ;
446+ await vi . advanceTimersByTimeAsync ( 10 ) ;
447+
448+ await expect ( resultPromise ) . resolves . toEqual ( {
449+ ...result ,
450+ stdout : "" ,
451+ stderr : "" ,
452+ } ) ;
453+ expect ( processKill ) . toHaveBeenCalledWith ( - 42 , "SIGTERM" ) ;
454+ expect ( processKill ) . toHaveBeenCalledWith ( process . pid , "SIGTERM" ) ;
455+ expect ( parentHandlers . size ) . toBe ( 0 ) ;
456+ } ,
457+ ) ;
435458} ) ;
0 commit comments