@@ -129,6 +129,53 @@ describe('runCloudPlanPi', () => {
129129 expect ( mockRun . mock . calls [ 0 ] [ 1 ] . envs . BASE_BRANCH ) . toBe ( '' )
130130 } )
131131
132+ it ( 'returns only the final assistant response while preserving live progress events' , async ( ) => {
133+ mockRun . mockImplementation (
134+ ( command : string , options : { onStdout ?: ( chunk : string ) => void } ) => {
135+ if ( command . includes ( 'git clone' ) ) {
136+ return Promise . resolve ( { stdout : '' , stderr : '' , exitCode : 0 } )
137+ }
138+ options . onStdout ?.(
139+ `${ [
140+ JSON . stringify ( {
141+ type : 'message_update' ,
142+ assistantMessageEvent : { type : 'text_delta' , delta : 'Inspecting files...' } ,
143+ } ) ,
144+ JSON . stringify ( {
145+ type : 'agent_end' ,
146+ messages : [
147+ {
148+ role : 'assistant' ,
149+ stopReason : 'stop' ,
150+ content : [ { type : 'text' , text : 'Inspecting files...' } ] ,
151+ } ,
152+ {
153+ role : 'assistant' ,
154+ stopReason : 'stop' ,
155+ content : [
156+ { type : 'thinking' , thinking : 'Hidden reasoning' } ,
157+ { type : 'text' , text : '# Final Plan\n\n1. Make the change.' } ,
158+ ] ,
159+ } ,
160+ ] ,
161+ } ) ,
162+ ] . join ( '\n' ) } \n`
163+ )
164+ return Promise . resolve ( { stdout : '' , stderr : '' , exitCode : 0 } )
165+ }
166+ )
167+ const onEvent = vi . fn ( )
168+
169+ const result = await runCloudPlanPi ( params ( ) , { onEvent } )
170+
171+ expect ( onEvent ) . toHaveBeenCalledWith ( { type : 'text' , text : 'Inspecting files...' } )
172+ expect ( onEvent ) . toHaveBeenCalledWith ( {
173+ type : 'final' ,
174+ text : '# Final Plan\n\n1. Make the change.' ,
175+ } )
176+ expect ( result . totals . finalText ) . toBe ( '# Final Plan\n\n1. Make the change.' )
177+ } )
178+
132179 it ( 'loads only the Sim search extension and scopes its key to the Pi command' , async ( ) => {
133180 await runCloudPlanPi ( params ( { search : { provider : 'exa' , apiKey : 'exa-secret' } } ) , {
134181 onEvent : vi . fn ( ) ,
0 commit comments