@@ -864,19 +864,34 @@ describe("diagnostic-events", () => {
864864 ) . toBe ( true ) ;
865865 } ) ;
866866
867- it ( "preserves trusted terminal tool diagnostics when the async queue is full" , async ( ) => {
867+ it ( "preserves trusted lifecycle terminals when the async queue is full" , async ( ) => {
868868 const events : DiagnosticEventPayload [ ] = [ ] ;
869869 onInternalDiagnosticEvent ( ( event ) => {
870870 events . push ( event ) ;
871871 } ) ;
872+ const model = {
873+ runId : "run-model" ,
874+ callId : "call-model" ,
875+ provider : "openai" ,
876+ model : "gpt-5.4" ,
877+ } ;
878+ const harness = { runId : "run-harness" , harnessId : "harness" } ;
879+ const terminalEvents : Array < Parameters < typeof emitTrustedDiagnosticEvent > [ 0 ] > = [
880+ { type : "tool.execution.completed" , toolName : "exec" , durationMs : 1 } ,
881+ { type : "tool.execution.error" , toolName : "exec" , durationMs : 1 , errorCategory : "test" } ,
882+ { type : "model.call.completed" , ...model , durationMs : 1 } ,
883+ { type : "model.call.error" , ...model , durationMs : 1 , errorCategory : "test" } ,
884+ { type : "harness.run.completed" , ...harness , durationMs : 1 , outcome : "completed" } ,
885+ {
886+ type : "harness.run.error" ,
887+ ...harness ,
888+ durationMs : 1 ,
889+ phase : "resolve" ,
890+ errorCategory : "test" ,
891+ } ,
892+ ] ;
872893
873- emitTrustedDiagnosticEvent ( {
874- type : "tool.execution.completed" ,
875- runId : "run-saturation-first" ,
876- toolName : "exec" ,
877- toolCallId : "call-saturation-first" ,
878- durationMs : 1 ,
879- } ) ;
894+ emitTrustedDiagnosticEvent ( terminalEvents [ 0 ] ! ) ;
880895
881896 for ( let index = 0 ; index < 9_999 ; index += 1 ) {
882897 emitDiagnosticEvent ( {
@@ -887,52 +902,26 @@ describe("diagnostic-events", () => {
887902 model : "gpt-5.4" ,
888903 } ) ;
889904 }
890-
891- emitTrustedDiagnosticEvent ( {
892- type : "tool.execution.error" ,
893- runId : "run-saturation-second" ,
894- toolName : "exec" ,
895- toolCallId : "call-saturation-second" ,
896- durationMs : 1 ,
897- errorCategory : "test" ,
898- } ) ;
905+ for ( const terminalEvent of terminalEvents . slice ( 1 ) ) {
906+ emitTrustedDiagnosticEvent ( terminalEvent ) ;
907+ }
899908
900909 expect (
901910 hasPendingInternalDiagnosticEvent (
902- ( event , metadata ) =>
903- metadata . trusted &&
904- event . type === "tool.execution.error" &&
905- event . toolCallId === "call-saturation-second" ,
911+ ( event , metadata ) => metadata . trusted && event . type === "harness.run.error" ,
906912 ) ,
907913 ) . toBe ( true ) ;
908914
909915 await waitForDiagnosticEventsDrained ( ) ;
910916
917+ for ( const terminalEvent of terminalEvents ) {
918+ expect ( events ) . toContainEqual ( expect . objectContaining ( terminalEvent ) ) ;
919+ }
911920 expect (
912- events
913- . filter (
914- (
915- event ,
916- ) : event is Extract <
917- DiagnosticEventPayload ,
918- { type : "tool.execution.completed" | "tool.execution.error" }
919- > => event . type === "tool.execution.completed" || event . type === "tool.execution.error" ,
920- )
921- . map ( ( event ) => ( {
922- type : event . type ,
923- toolCallId : event . toolCallId ,
924- } ) ) ,
925- ) . toEqual ( [
926- {
927- type : "tool.execution.completed" ,
928- toolCallId : "call-saturation-first" ,
929- } ,
930- {
931- type : "tool.execution.error" ,
932- toolCallId : "call-saturation-second" ,
933- } ,
934- ] ) ;
935- expect ( events . filter ( ( event ) => event . type === "model.call.started" ) ) . toHaveLength ( 9_998 ) ;
921+ events . filter (
922+ ( event ) => event . type === "model.call.started" && event . runId . startsWith ( "saturation-run-" ) ,
923+ ) ,
924+ ) . toHaveLength ( 9_994 ) ;
936925 } ) ;
937926
938927 it ( "emits a bounded summary when async diagnostics are dropped at saturation" , async ( ) => {
0 commit comments