@@ -135,4 +135,60 @@ describe("runAcpServer", () => {
135135 toAgent . end ( ) ;
136136 await serverDone ;
137137 } ) ;
138+
139+ it ( "streams provider failures as visible ACP messages" , async ( ) => {
140+ faux . setResponses ( [
141+ fauxAssistantMessage ( [ ] , {
142+ stopReason : "error" ,
143+ errorMessage : '402 "insufficient_credits"' ,
144+ } ) ,
145+ ] ) ;
146+
147+ const toAgent = new PassThrough ( ) ;
148+ const fromAgent = new PassThrough ( ) ;
149+ const serverDone = runAcpServer ( {
150+ stdin : toAgent ,
151+ stdout : fromAgent ,
152+ configOverride : { model, apiKey : "faux-key" , source : "byok" } ,
153+ } ) ;
154+ const updates : acp . SessionNotification [ ] = [ ] ;
155+ const stream = acp . ndJsonStream ( Writable . toWeb ( toAgent ) , Readable . toWeb ( fromAgent ) as ReadableStream < Uint8Array > ) ;
156+
157+ const result = await acp
158+ . client ( { name : "buzz-error-test" } )
159+ . onNotification ( acp . methods . client . session . update , ( ctx ) => {
160+ updates . push ( ctx . params ) ;
161+ } )
162+ . connectWith ( stream , async ( client ) => {
163+ await client . request ( acp . methods . agent . initialize , {
164+ protocolVersion : acp . PROTOCOL_VERSION ,
165+ clientInfo : { name : "buzz-acp" , version : "test" } ,
166+ } ) ;
167+ const session = await client . request ( acp . methods . agent . session . new , {
168+ cwd,
169+ mcpServers : [ ] ,
170+ } ) ;
171+ return client . request ( acp . methods . agent . session . prompt , {
172+ sessionId : session . sessionId ,
173+ prompt : [ { type : "text" , text : "Reply even if the provider fails." } ] ,
174+ } ) ;
175+ } ) ;
176+
177+ expect ( result . stopReason ) . toBe ( "end_turn" ) ;
178+ const text = updates
179+ . filter (
180+ (
181+ event ,
182+ ) : event is acp . SessionNotification & {
183+ update : { sessionUpdate : "agent_message_chunk" ; content : { type : "text" ; text : string } } ;
184+ } => event . update . sessionUpdate === "agent_message_chunk" && event . update . content . type === "text" ,
185+ )
186+ . map ( ( event ) => event . update . content . text )
187+ . join ( "" ) ;
188+ expect ( text ) . toContain ( "Codebase couldn't complete this turn" ) ;
189+ expect ( text ) . toContain ( "Codebase credits are exhausted" ) ;
190+
191+ toAgent . end ( ) ;
192+ await serverDone ;
193+ } ) ;
138194} ) ;
0 commit comments