@@ -176,7 +176,71 @@ describe('run_workflow model-facing result budget', () => {
176176 expect ( output . output ) . toEqual ( finalOutput )
177177 const presented = output . logs as Array < Record < string , unknown > >
178178 expect ( presented . map ( ( log ) => log . blockName ) ) . toEqual ( logs . map ( ( log ) => log . blockName ) )
179- expect ( presented [ 3 ] ) . toMatchObject ( { success : false , error : 'SMTP refused' } )
179+ // The failing block keeps its name and status; its error is the run error, said once.
180+ expect ( presented [ 3 ] ) . toMatchObject ( { success : false , error : '…[same as the run error]' } )
181+ } )
182+
183+ /**
184+ * An HTTP block that fails with a whole HTML page as its error carried it twice, in the run error
185+ * and the block entry. The entry now defers to the run error, which keeps its head, cut after
186+ * projection so a secret straddling the cut leaves no fragment.
187+ */
188+ it ( 'cuts a page-sized block error once, after secret projection' , async ( ) => {
189+ const page = `<html>${ 'a' . repeat ( 1_480 ) } ${ SECRET } ${ 'b' . repeat ( 30_000 ) } </html>`
190+ mocks . executeWorkflowUseCase . mockResolvedValue ( {
191+ success : false ,
192+ output : { } ,
193+ logs : [
194+ { blockId : 'start' , blockName : 'Start' , success : true , output : { ok : true } } ,
195+ { blockId : 'http' , blockName : 'HTTP' , success : false , error : page , output : { } } ,
196+ ] ,
197+ metadata : { executionId : EXECUTION_ID } ,
198+ } )
199+
200+ const settled = await executeRunWorkflow ( { workflowId : 'wf-1' } , context )
201+ const projection = inspectToolResultForCopilot ( settled , registry , 'run_workflow' )
202+
203+ expect ( projection . safe ) . toBe ( true )
204+ const serialized = JSON . stringify ( projection . result )
205+ expect ( serialized . length ) . toBeLessThanOrEqual ( 24_000 )
206+ for ( let length = 4 ; length <= SECRET . length ; length += 1 ) {
207+ expect ( serialized ) . not . toContain ( SECRET . slice ( 0 , length ) )
208+ }
209+ expect ( projection . result . error ) . toMatch ( / ^ H T T P : < h t m l > a + / )
210+ expect ( projection . result . error ) . toContain ( `logs get ${ EXECUTION_ID } --trace` )
211+ const logs = ( projection . result . output as { logs : Array < Record < string , unknown > > } ) . logs
212+ expect ( logs [ 1 ] ) . toMatchObject ( { blockName : 'HTTP' , success : false } )
213+ expect ( String ( logs [ 1 ] ?. error ) . length ) . toBeLessThan ( 100 )
214+ } )
215+
216+ /** A loop's iterations each log a block entry; past the window the middle ones give way. */
217+ it ( 'keeps the failed iteration and the ends of a long loop run' , async ( ) => {
218+ const logs = Array . from ( { length : 400 } , ( _ , index ) => ( {
219+ blockId : `iteration-${ index } ` ,
220+ blockName : `Fetch page (iteration ${ index } )` ,
221+ success : index !== 250 ,
222+ ...( index === 250 ? { error : 'Rate limited' } : { } ) ,
223+ output : { ok : index !== 250 } ,
224+ } ) )
225+ mocks . executeWorkflowUseCase . mockResolvedValue ( {
226+ success : false ,
227+ output : { } ,
228+ logs,
229+ metadata : { executionId : EXECUTION_ID } ,
230+ } )
231+ const inactive = secretRegistry ( { active : false } )
232+
233+ const settled = await executeRunWorkflow ( { workflowId : 'wf-1' } , callContext ( inactive ) )
234+ const output = settled . output as { logs : unknown [ ] }
235+
236+ expect ( JSON . stringify ( { output, error : settled . error } ) . length ) . toBeLessThanOrEqual ( 16_000 )
237+ expect ( settled . error ) . toBe ( 'Fetch page (iteration 250): Rate limited' )
238+ expect ( output . logs ) . toContainEqual ( expect . objectContaining ( { blockId : 'iteration-250' } ) )
239+ expect ( output . logs [ 0 ] ) . toEqual ( logs [ 0 ] )
240+ expect ( output . logs . at ( - 1 ) ) . toEqual ( logs [ 399 ] )
241+ expect ( output . logs ) . toContainEqual (
242+ expect . stringMatching ( / ^ … \[ \d + b l o c k e n t r i e s o m i t t e d ; i n s p e c t w i t h l o g s g e t / )
243+ )
180244 } )
181245
182246 /** A short secret under a long name grows when projected, so the window is measured after it. */
@@ -211,13 +275,17 @@ describe('run_workflow model-facing result budget', () => {
211275 expect ( output . logs [ 0 ] ?. output ) . toEqual ( expect . stringContaining ( `logs get ${ EXECUTION_ID } ` ) )
212276 } )
213277
214- /** Many small block entries leave less room than a full preview, so the preview shrinks to fit. */
278+ /**
279+ * Failed block entries are never dropped, so many of them (blocks that routed into error paths)
280+ * leave less room than a full preview, and the preview shrinks to fit.
281+ */
215282 it ( 'shrinks the final output preview to the room the block entries leave' , async ( ) => {
216- const logs = Array . from ( { length : 150 } , ( _ , index ) => ( {
283+ const logs = Array . from ( { length : 120 } , ( _ , index ) => ( {
217284 blockId : `step-${ index } ` ,
218285 blockName : `Step ${ index } of the nightly import` ,
219- success : true ,
220- output : { ok : true } ,
286+ success : false ,
287+ error : `retry ${ index } ` ,
288+ output : { ok : false } ,
221289 } ) )
222290 mocks . executeWorkflowUseCase . mockResolvedValue ( {
223291 success : true ,
@@ -602,7 +670,7 @@ describe('run_workflow model-facing result budget', () => {
602670 const projection = inspectToolResultForCopilot ( settled , registry , 'run_workflow' )
603671
604672 expect ( projection . safe ) . toBe ( true )
605- expect ( projection . result . error ) . toBe ( error )
673+ expect ( projection . result . error ) . toMatch ( / ^ R e p o r t f a i l e d : e + … \[ e r r o r c u t a t 1 5 0 0 o f / )
606674 expect (
607675 ( projection . result . output as { logs : Array < { output : unknown } > } ) . logs [ 0 ] ?. output
608676 ) . toEqual ( expect . stringContaining ( `logs get ${ EXECUTION_ID } --trace` ) )
0 commit comments