@@ -33,6 +33,7 @@ function buildPreparedContext(params?: {
3333 prompt : "hi" ,
3434 provider : "codex-cli" ,
3535 model : "gpt-5.4" ,
36+ thinkLevel : "low" ,
3637 timeoutMs : 1_000 ,
3738 runId : params ?. runId ?? "run-2" ,
3839 } ,
@@ -177,6 +178,74 @@ describe("runCliAgent reliability", () => {
177178
178179 expect ( supervisorSpawnMock ) . toHaveBeenCalledTimes ( 2 ) ;
179180 } ) ;
181+
182+ it ( "returns the assembled CLI prompt in meta for raw trace consumers" , async ( ) => {
183+ supervisorSpawnMock . mockResolvedValueOnce (
184+ createManagedRun ( {
185+ reason : "exit" ,
186+ exitCode : 0 ,
187+ exitSignal : null ,
188+ durationMs : 50 ,
189+ stdout : "hello from cli" ,
190+ stderr : "" ,
191+ timedOut : false ,
192+ noOutputTimedOut : false ,
193+ } ) ,
194+ ) ;
195+
196+ const result = await runPreparedCliAgent ( {
197+ ...buildPreparedContext ( ) ,
198+ bootstrapPromptWarningLines : [ "Warning: prompt budget low." ] ,
199+ } ) ;
200+
201+ expect ( result . meta . finalPromptText ) . toContain ( "Warning: prompt budget low." ) ;
202+ expect ( result . meta . finalPromptText ) . toContain ( "hi" ) ;
203+ expect ( result . meta . finalAssistantRawText ) . toBe ( "hello from cli" ) ;
204+ expect ( result . meta . executionTrace ) . toMatchObject ( {
205+ winnerProvider : "codex-cli" ,
206+ winnerModel : "gpt-5.4" ,
207+ fallbackUsed : false ,
208+ runner : "cli" ,
209+ attempts : [ { provider : "codex-cli" , model : "gpt-5.4" , result : "success" } ] ,
210+ } ) ;
211+ expect ( result . meta . requestShaping ) . toMatchObject ( {
212+ thinking : "low" ,
213+ } ) ;
214+ expect ( result . meta . completion ) . toMatchObject ( {
215+ finishReason : "stop" ,
216+ stopReason : "completed" ,
217+ refusal : false ,
218+ } ) ;
219+ } ) ;
220+
221+ it ( "keeps raw assistant output separate from transformed visible CLI output" , async ( ) => {
222+ supervisorSpawnMock . mockResolvedValueOnce (
223+ createManagedRun ( {
224+ reason : "exit" ,
225+ exitCode : 0 ,
226+ exitSignal : null ,
227+ durationMs : 50 ,
228+ stdout : "hello from cli" ,
229+ stderr : "" ,
230+ timedOut : false ,
231+ noOutputTimedOut : false ,
232+ } ) ,
233+ ) ;
234+
235+ const result = await runPreparedCliAgent ( {
236+ ...buildPreparedContext ( ) ,
237+ backendResolved : {
238+ ...buildPreparedContext ( ) . backendResolved ,
239+ textTransforms : {
240+ output : [ { from : "hello" , to : "goodbye" } ] ,
241+ } ,
242+ } ,
243+ } ) ;
244+
245+ expect ( result . payloads ) . toEqual ( [ { text : "goodbye from cli" } ] ) ;
246+ expect ( result . meta . finalAssistantVisibleText ) . toBe ( "goodbye from cli" ) ;
247+ expect ( result . meta . finalAssistantRawText ) . toBe ( "hello from cli" ) ;
248+ } ) ;
180249} ) ;
181250
182251describe ( "resolveCliNoOutputTimeoutMs" , ( ) => {
0 commit comments