@@ -582,6 +582,11 @@ describe('WorkflowBlockHandler', () => {
582582 expect ( executorOptions [ 0 ] . contextExtensions . billingAttribution ) . toBe ( sourceAttribution )
583583 expect ( executorOptions [ 0 ] . contextExtensions . userId ) . toBe ( 'owner-9' )
584584 expect ( executorOptions [ 0 ] . contextExtensions . workspaceId ) . toBe ( 'workspace-source' )
585+ expect ( executorOptions [ 0 ] . contextExtensions . executorDelegationOrigin ) . toEqual ( {
586+ subjectUserId : 'owner-9' ,
587+ workflowId : 'source-workflow-id' ,
588+ executionId : loggingSessionArgs [ 0 ] [ 1 ] ,
589+ } )
585590 } )
586591
587592 it ( 'builds trusted caller metadata for custom block children with the toggle on' , async ( ) => {
@@ -1225,6 +1230,15 @@ describe('WorkflowBlockHandler', () => {
12251230 expect ( loggingSessionArgs ) . toHaveLength ( 0 )
12261231 } )
12271232
1233+ it ( 'fails before execution when the source child log row cannot be opened' , async ( ) => {
1234+ mockSafeStart . mockResolvedValue ( false )
1235+
1236+ await expect ( handler . execute ( customBlockContext ( ) , customBlock ( ) , { } ) ) . rejects . toThrow ( )
1237+
1238+ expect ( mockExecutorExecute ) . not . toHaveBeenCalled ( )
1239+ expect ( executorOptions ) . toHaveLength ( 0 )
1240+ } )
1241+
12281242 it ( 'runs the child under its own execution id but keeps the parent readable' , async ( ) => {
12291243 const ctx = customBlockContext ( )
12301244 await handler . execute ( ctx , customBlock ( ) , { } )
@@ -1235,6 +1249,24 @@ describe('WorkflowBlockHandler', () => {
12351249 expect ( ctx . largeValueExecutionIds ) . toContain ( extensions . executionId )
12361250 } )
12371251
1252+ it ( 'replaces the consumer delegation origin with the source child execution' , async ( ) => {
1253+ const ctx = customBlockContext ( {
1254+ executorDelegationOrigin : {
1255+ subjectUserId : 'consumer-1' ,
1256+ workflowId : 'consumer-workflow' ,
1257+ executionId : 'parent-execution-id' ,
1258+ } ,
1259+ } )
1260+
1261+ await handler . execute ( ctx , customBlock ( ) , { } )
1262+
1263+ expect ( executorOptions [ 0 ] . contextExtensions . executorDelegationOrigin ) . toEqual ( {
1264+ subjectUserId : 'owner-9' ,
1265+ workflowId : 'source-workflow-id' ,
1266+ executionId : executorOptions [ 0 ] . contextExtensions . executionId ,
1267+ } )
1268+ } )
1269+
12381270 it ( 'shares one large-value id list so nested custom blocks propagate upward' , async ( ) => {
12391271 const ctx = customBlockContext ( )
12401272 await handler . execute ( ctx , customBlock ( ) , { } )
@@ -1604,9 +1636,49 @@ describe('WorkflowBlockHandler', () => {
16041636 const extensions = executorOptions [ 0 ] . contextExtensions
16051637 expect ( extensions . executionId ) . toBe ( 'parent-execution-id' )
16061638 expect ( extensions . resolvedSecretTraceRegistry ) . toBe ( registry )
1639+ expect ( extensions . executorDelegationOrigin ) . toEqual ( {
1640+ subjectUserId : 'user-1' ,
1641+ workflowId : 'parent-workflow-id' ,
1642+ executionId : 'parent-execution-id' ,
1643+ } )
1644+ expect ( mockBuildExecutorDelegationHeaders ) . toHaveBeenCalledWith (
1645+ extensions . executorDelegationOrigin
1646+ )
16071647 expect ( extensions . onStream ) . toBe ( ctx . onStream )
16081648 expect ( extensions . childWorkflowContext ) . toBeDefined ( )
16091649 } )
1650+
1651+ it ( 'preserves the canonical parent origin through deeper regular children' , async ( ) => {
1652+ const ctx = {
1653+ ...mockContext ,
1654+ workspaceId : 'workspace-1' ,
1655+ workflowId : 'intermediate-workflow-id' ,
1656+ executionId : 'parent-execution-id' ,
1657+ executorDelegationOrigin : {
1658+ subjectUserId : 'user-1' ,
1659+ workflowId : 'root-workflow-id' ,
1660+ executionId : 'parent-execution-id' ,
1661+ } ,
1662+ } as ExecutionContext
1663+ mockFetch . mockResolvedValue ( {
1664+ ok : true ,
1665+ json : ( ) =>
1666+ Promise . resolve ( {
1667+ data : {
1668+ name : 'Grandchild Workflow' ,
1669+ workspaceId : 'workspace-1' ,
1670+ state : { blocks : [ ] , edges : [ ] , loops : { } , parallels : { } } ,
1671+ } ,
1672+ } ) ,
1673+ } )
1674+
1675+ await handler . execute ( ctx , mockBlock , { workflowId : 'grandchild-workflow-id' } )
1676+
1677+ expect ( mockBuildExecutorDelegationHeaders ) . toHaveBeenCalledWith ( ctx . executorDelegationOrigin )
1678+ expect ( executorOptions [ 0 ] . contextExtensions . executorDelegationOrigin ) . toBe (
1679+ ctx . executorDelegationOrigin
1680+ )
1681+ } )
16101682 } )
16111683
16121684 describe ( 'projectCustomBlockOutput' , ( ) => {
0 commit comments