1- // CLI backends report a tool result without repeating the request, so the
2- // terminal progress event has to carry the args the tool started with .
1+ // Correlated CLI tool results already carry their started args; display-only
2+ // results must not duplicate that potentially large payload .
33import { describe , expect , it , vi } from "vitest" ;
44import { type AgentEventRuntimePayload , onAgentEvent } from "../../infra/agent-events.js" ;
55import { createCliEventHandlers } from "./execute-events.js" ;
@@ -66,7 +66,7 @@ function collectToolEvents(runId: string): {
6666}
6767
6868describe ( "cli tool result events" , ( ) => {
69- it ( "carries the started args into the terminal event " , ( ) => {
69+ it ( "keeps correlated result args without adding them to display results " , ( ) => {
7070 const runId = "run-tool-result-args" ;
7171 const handlers = createCliEventHandlers ( {
7272 context : buildContext ( runId ) ,
@@ -88,10 +88,32 @@ describe("cli tool result events", () => {
8888 isError : true ,
8989 result : "bash: nope-not-a-command: command not found" ,
9090 } ) ;
91+ handlers . emitCliDisplayToolUseStart ( {
92+ toolCallId : "call-2" ,
93+ name : "write" ,
94+ kind : "tool_use" ,
95+ args : { path : "note.txt" , content : "hello" } ,
96+ } ) ;
97+ handlers . emitCliDisplayToolResult ( {
98+ toolCallId : "call-2" ,
99+ name : "write" ,
100+ isError : false ,
101+ result : "wrote note.txt" ,
102+ } ) ;
103+ // The display result also releases correlation state for this call id.
104+ handlers . emitCliToolResult ( {
105+ toolCallId : "call-2" ,
106+ name : "write" ,
107+ isError : false ,
108+ result : "duplicate terminal" ,
109+ } ) ;
91110
92- const result = events . find ( ( event ) => event . data . phase === "result" ) ;
93- expect ( result ?. data . args ) . toEqual ( { command : "nope-not-a-command" } ) ;
94- expect ( result ?. data . isError ) . toBe ( true ) ;
111+ const results = events . filter ( ( event ) => event . data . phase === "result" ) ;
112+ expect ( results [ 0 ] ?. data . args ) . toEqual ( { command : "nope-not-a-command" } ) ;
113+ expect ( results [ 0 ] ?. data . isError ) . toBe ( true ) ;
114+ expect ( results [ 1 ] ?. data . args ) . toBeUndefined ( ) ;
115+ expect ( results [ 1 ] ?. data . isError ) . toBe ( false ) ;
116+ expect ( results [ 2 ] ?. data . args ) . toBeUndefined ( ) ;
95117 } finally {
96118 dispose ( ) ;
97119 }
0 commit comments