@@ -118,7 +118,9 @@ describe("TerminalProcess", () => {
118118 // onDidEndTerminalShellExecution is a separate global VSCode event, not
119119 // something coupled to the stream iterator being pulled again -- emit it
120120 // independently of stream consumption, matching real-world timing.
121- terminalProcess . emit ( "shell_execution_complete" , { exitCode : 0 } )
121+ // Use setTimeout(0) so it fires after microtask-based stream processing
122+ // (async generator iterations) has consumed all chunks including the D marker.
123+ setTimeout ( ( ) => terminalProcess . emit ( "shell_execution_complete" , { exitCode : 0 } ) , 0 )
122124
123125 await runPromise
124126
@@ -363,10 +365,12 @@ describe("TerminalProcess", () => {
363365 terminalProcess . once ( "no_shell_integration" , noShellIntegrationSpy )
364366
365367 const runPromise = terminalProcess . run ( "test command" )
368+ // stream_available is now emitted by TerminalRegistry (onDidStartTerminalShellExecution).
369+ // Simulate that here so run() can proceed to consume the stream.
370+ terminalProcess . emit ( "stream_available" , mockStream )
366371 await runPromise
367372 await eventPromises
368373
369- expect ( mockExecution . read ) . toHaveBeenCalledTimes ( 1 )
370374 expect ( completedOutput ) . toBe ( "" )
371375 expect ( noShellIntegrationSpy ) . not . toHaveBeenCalled ( )
372376 } )
@@ -396,10 +400,12 @@ describe("TerminalProcess", () => {
396400 terminalProcess . once ( "no_shell_integration" , noShellIntegrationSpy )
397401
398402 const runPromise = terminalProcess . run ( "test command" )
403+ // stream_available is now emitted by TerminalRegistry (onDidStartTerminalShellExecution).
404+ // Simulate that here so run() can proceed to consume the stream.
405+ terminalProcess . emit ( "stream_available" , mockStream )
399406 await runPromise
400407 await eventPromises
401408
402- expect ( mockExecution . read ) . toHaveBeenCalledTimes ( 1 )
403409 expect ( completedOutput ) . toBe ( "some output without marker\n" )
404410 expect ( noShellIntegrationSpy ) . not . toHaveBeenCalled ( )
405411 } )
@@ -437,7 +443,9 @@ describe("TerminalProcess", () => {
437443 // onDidEndTerminalShellExecution is a separate global VSCode event, not
438444 // something coupled to the stream iterator being pulled again -- emit it
439445 // independently of stream consumption, matching real-world timing.
440- terminalProcess . emit ( "shell_execution_complete" , { exitCode : 0 } )
446+ // Use setTimeout(0) so it fires after microtask-based stream processing
447+ // has consumed all chunks including the D marker.
448+ setTimeout ( ( ) => terminalProcess . emit ( "shell_execution_complete" , { exitCode : 0 } ) , 0 )
441449
442450 await runPromise
443451
0 commit comments