@@ -538,17 +538,17 @@ describe('devframeTerminalHost interactive PTY sessions', () => {
538538 expect ( secondOutput . output ) . not . toContain ( `run:${ firstResult . pid } ` )
539539 } )
540540
541- itPty ( 'reports a structured error when restart fails to spawn a PTY ' , async ( ) => {
542- expect . assertions ( 5 )
541+ itPty ( 'allows retry after a structured PTY restart spawn error ' , async ( ) => {
542+ expect . assertions ( 9 )
543543
544544 const { host } = createTerminalHost ( )
545545 const session = await host . startPtySession ( {
546546 command : NODE ,
547- args : [ '-e' , 'process.stdout.write("started" ); setInterval(() => {}, 4000)' ] ,
547+ args : [ '-e' , 'process.stdout.write("started:" + process.pid ); setInterval(() => {}, 4000)' ] ,
548548 } , { id : 'pty-result-restart-error' , title : 'PTY result restart error' } )
549549 const result = session . getResult ( )
550550 await waitUntil ( ( ) => {
551- if ( ! session . buffer ?. join ( '' ) . includes ( ' started' ) )
551+ if ( ! session . buffer ?. join ( '' ) . includes ( ` started: ${ result . pid } ` ) )
552552 throw new Error ( 'PTY output has not started' )
553553 } )
554554 zigptyModuleMock . spawn . mockImplementationOnce ( ( ) => {
@@ -559,10 +559,22 @@ describe('devframeTerminalHost interactive PTY sessions', () => {
559559 expect ( session . status ) . toBe ( 'error' )
560560 expect ( session . getProcessName ( ) ) . toBeUndefined ( )
561561 expect ( session . getResult ( ) ) . toBe ( result )
562+
563+ await expect ( session . restart ( ) ) . resolves . toBeUndefined ( )
564+ expect ( session . status ) . toBe ( 'running' )
565+ const retryResult = session . getResult ( )
566+ expect ( retryResult ) . not . toBe ( result )
567+ await waitUntil ( ( ) => {
568+ if ( ! session . buffer ?. join ( '' ) . includes ( `started:${ retryResult . pid } ` ) )
569+ throw new Error ( 'Retried PTY output has not started' )
570+ } )
571+ expect ( session . buffer ?. join ( '' ) ) . toContain ( `started:${ retryResult . pid } ` )
572+ await session . terminate ( )
562573 await expect ( result ) . resolves . toMatchObject ( {
563- output : expect . stringContaining ( ' started' ) ,
574+ output : expect . stringContaining ( ` started: ${ result . pid } ` ) ,
564575 exitCode : undefined ,
565576 } )
577+ await retryResult
566578 } )
567579
568580 itPty ( 'does not accept resize after termination without throwing' , async ( ) => {
0 commit comments