@@ -151,6 +151,41 @@ describe('LoggingSession terminal provenance', () => {
151151 } )
152152 )
153153 } )
154+
155+ it . each ( [ 'cancellation' , 'pause' ] as const ) (
156+ 'preserves raw execution state on %s finalization' ,
157+ async ( finalization ) => {
158+ const session = new LoggingSession ( 'workflow-1' , `execution-state-${ finalization } ` , 'manual' )
159+ session . setResolvedSecretTraceRegistry ( createSecretRegistry ( [ ] ) )
160+ const executionState = {
161+ blockStates : { 'function-1' : { output : { result : 'raw-secret-value' } } } ,
162+ executedBlocks : [ 'function-1' ] ,
163+ blockLogs : [ ] ,
164+ decisions : { router : { } , condition : { } } ,
165+ completedLoops : [ ] ,
166+ activeExecutionPath : [ 'function-1' ] ,
167+ }
168+
169+ if ( finalization === 'cancellation' ) {
170+ await session . completeWithCancellation ( { executionState } )
171+ } else {
172+ await session . completeWithPause ( { executionState } )
173+ }
174+
175+ expect ( completeWorkflowExecutionMock ) . toHaveBeenCalledWith (
176+ expect . objectContaining ( {
177+ executionState : expect . objectContaining ( {
178+ blockStates : executionState . blockStates ,
179+ resolvedSecretTraceProvenance : {
180+ version : 1 ,
181+ complete : true ,
182+ entries : [ ] ,
183+ } ,
184+ } ) ,
185+ } )
186+ )
187+ }
188+ )
154189} )
155190
156191beforeEach ( ( ) => {
@@ -596,15 +631,25 @@ describe('LoggingSession completion retries', () => {
596631 completeWorkflowExecutionMock
597632 . mockRejectedValueOnce ( new Error ( 'primary persistence failed' ) )
598633 . mockResolvedValueOnce ( { } )
634+ const executionState = {
635+ blockStates : { 'function-1' : { output : { result : secret } } } ,
636+ executedBlocks : [ 'function-1' ] ,
637+ blockLogs : [ ] ,
638+ decisions : { router : { } , condition : { } } ,
639+ completedLoops : [ ] ,
640+ activeExecutionPath : [ 'function-1' ] ,
641+ }
599642
600643 await session . safeComplete ( {
601644 finalOutput : { echoed : secret } ,
645+ executionState,
602646 } )
603647
604648 expect ( completeWorkflowExecutionMock ) . toHaveBeenLastCalledWith (
605649 expect . objectContaining ( {
606650 finalOutput : { echoed : secret } ,
607651 finalizationPath : 'fallback_completed' ,
652+ executionState : expect . objectContaining ( { blockStates : executionState . blockStates } ) ,
608653 } )
609654 )
610655 } )
@@ -944,18 +989,33 @@ describe('LoggingSession completion retries', () => {
944989 completeWorkflowExecutionMock
945990 . mockRejectedValueOnce ( new Error ( 'pause finalize failed' ) )
946991 . mockResolvedValueOnce ( { } )
992+ const executionState = {
993+ blockStates : { 'function-1' : { output : { result : 'raw-secret-value' } } } ,
994+ executedBlocks : [ 'function-1' ] ,
995+ blockLogs : [ ] ,
996+ decisions : { router : { } , condition : { } } ,
997+ completedLoops : [ ] ,
998+ activeExecutionPath : [ 'function-1' ] ,
999+ }
9471000
9481001 await expect (
9491002 session . safeCompleteWithPause ( {
9501003 endedAt : new Date ( ) . toISOString ( ) ,
9511004 totalDurationMs : 10 ,
9521005 traceSpans : [ ] ,
9531006 workflowInput : { hello : 'world' } ,
1007+ executionState,
9541008 } )
9551009 ) . resolves . toBeUndefined ( )
9561010
9571011 expect ( session . hasCompleted ( ) ) . toBe ( true )
9581012 expect ( completeWorkflowExecutionMock ) . toHaveBeenCalledTimes ( 2 )
1013+ expect ( completeWorkflowExecutionMock ) . toHaveBeenLastCalledWith (
1014+ expect . objectContaining ( {
1015+ finalizationPath : 'paused' ,
1016+ executionState : expect . objectContaining ( { blockStates : executionState . blockStates } ) ,
1017+ } )
1018+ )
9591019 } )
9601020
9611021 it ( 'persists last started block independently from cost accumulation' , async ( ) => {
0 commit comments