@@ -102,6 +102,41 @@ describe('bindInternalExecutorDelegation', () => {
102102 } )
103103 } )
104104
105+ it ( 'binds the trusted legacy execution actor only for an actorless principal' , async ( ) => {
106+ const principal = await bindInternalExecutorDelegation (
107+ {
108+ ...claims ,
109+ subjectUserId : undefined ,
110+ principal : {
111+ kind : 'system' ,
112+ serviceId : 'schedule' ,
113+ workspaceId : 'workspace-1' ,
114+ workflowId : 'workflow-1' ,
115+ } ,
116+ } ,
117+ {
118+ audience : 'sim:workspace-files' ,
119+ compatibilityActorUserId : 'execution-actor' ,
120+ }
121+ )
122+
123+ expect ( principal . subjectUserId ) . toBeUndefined ( )
124+ expect ( principal . delegationContext . compatibilityActor ) . toEqual ( {
125+ kind : 'legacy_execution_user' ,
126+ userId : 'execution-actor' ,
127+ } )
128+ } )
129+
130+ it ( 'rejects a compatibility actor when the delegation has a user subject' , async ( ) => {
131+ await expect (
132+ bindInternalExecutorDelegation ( claims , {
133+ audience : 'sim:workspace-files' ,
134+ compatibilityActorUserId : 'execution-actor' ,
135+ } )
136+ ) . rejects . toThrow ( 'cannot bind a compatibility actor to a user subject' )
137+ expect ( mockResolveWorkflow ) . not . toHaveBeenCalled ( )
138+ } )
139+
105140 it ( 'binds deployed child authority to its exact historical deployment version' , async ( ) => {
106141 const currentWorkflow = {
107142 workflowId : 'child-workflow' ,
@@ -260,6 +295,16 @@ describe('bindInternalExecutorDelegation', () => {
260295 expect ( mockResolveWorkflow ) . not . toHaveBeenCalled ( )
261296 } )
262297
298+ it ( 'fails before canonical loading when the compatibility actor is empty' , async ( ) => {
299+ await expect (
300+ bindInternalExecutorDelegation ( claims , {
301+ audience : 'sim:workspace-files' ,
302+ compatibilityActorUserId : ' ' ,
303+ } )
304+ ) . rejects . toThrow ( 'Internal delegation execution actor must not be empty' )
305+ expect ( mockResolveWorkflow ) . not . toHaveBeenCalled ( )
306+ } )
307+
263308 it ( 'classifies a missing canonical execution as an invalid delegation binding' , async ( ) => {
264309 mockResolveRun . mockRejectedValue ( new OrchestrationError ( 'not_found' , 'Workflow run not found' ) )
265310
0 commit comments