@@ -6036,6 +6036,50 @@ public async Task AgentEvent_ItemEndAfterCommandOutput_PreservesOutput()
60366036 Assert . Equal ( "hi\n " , entry . ToolOutput ) ;
60376037 }
60386038
6039+ [ Theory ]
6040+ [ InlineData ( "missing" ) ]
6041+ [ InlineData ( "empty" ) ]
6042+ [ InlineData ( "whitespace" ) ]
6043+ public async Task AgentEvent_ItemWithoutUsableId_UsesLegacyFallbackAndPreservesOutput ( string idCase )
6044+ {
6045+ var ( bridge , provider , snapshots , _) = CreateProvider ( new [ ] { MainSession ( ) } ) ;
6046+ await provider . LoadAsync ( ) ;
6047+
6048+ string ItemPayload ( string phase )
6049+ {
6050+ var payload = new Dictionary < string , object ? >
6051+ {
6052+ [ "phase" ] = phase ,
6053+ [ "kind" ] = "tool" ,
6054+ [ "title" ] = "Tool"
6055+ } ;
6056+ if ( idCase != "missing" )
6057+ payload [ "itemId" ] = idCase == "empty" ? string . Empty : " " ;
6058+ return JsonSerializer . Serialize ( payload ) ;
6059+ }
6060+
6061+ bridge . RaiseAgent ( MakeAgentEvent (
6062+ "lifecycle" ,
6063+ """{"phase":"start"}""" ,
6064+ runId : "run-1" ) ) ;
6065+ bridge . RaiseAgent ( MakeAgentEvent ( "item" , ItemPayload ( "start" ) , runId : "run-1" ) ) ;
6066+ bridge . RaiseAgent ( MakeAgentEvent (
6067+ "command_output" ,
6068+ """{"phase":"end","output":"legacy output"}""" ,
6069+ runId : "run-1" ) ) ;
6070+ bridge . RaiseAgent ( MakeAgentEvent ( "item" , ItemPayload ( "end" ) , runId : "run-1" ) ) ;
6071+ bridge . RaiseAgent ( MakeAgentEvent (
6072+ "lifecycle" ,
6073+ """{"phase":"end"}""" ,
6074+ runId : "run-1" ) ) ;
6075+
6076+ var timeline = snapshots [ ^ 1 ] . Timelines [ "main" ] ;
6077+ var entry = Assert . Single ( timeline . Entries ) ;
6078+ Assert . Equal ( ChatToolCallStatus . Success , entry . ToolResult ) ;
6079+ Assert . Equal ( "legacy output" , entry . ToolOutput ) ;
6080+ Assert . False ( timeline . TurnActive ) ;
6081+ }
6082+
60396083 [ Fact ]
60406084 public async Task AgentEvent_GenericParentAndBashChild_RendersSpecificSafeIdentity ( )
60416085 {
0 commit comments