@@ -81,16 +81,47 @@ describe('createExecutorPrincipalFromExecutionContext', () => {
8181 )
8282 } )
8383
84- it ( 'binds MCP policy provenance from the trusted execution context' , async ( ) => {
84+ it . each ( [ 'sim:mcp-servers' , 'sim:managed-mcp-credentials' ] ) (
85+ 'binds MCP policy provenance from the trusted execution context for %s' ,
86+ async ( audience ) => {
87+ const principal = await createExecutorPrincipalFromExecutionContext ( {
88+ context : executionContext ( {
89+ mcpBlockId : 'saved-block' ,
90+ executorDelegationOrigin : { subjectUserId : 'user-origin' , workflowId : 'workflow-origin' } ,
91+ } ) ,
92+ audience,
93+ resourceScope : { mcpServerId : 'server-1' } ,
94+ } )
95+ expect ( principal . resourceScope ) . toEqual ( {
96+ mcpBlockId : 'saved-block' ,
97+ mcpServerId : 'server-1' ,
98+ } )
99+ }
100+ )
101+
102+ it ( 'keeps credential lookup unscoped when its block has MCP provenance metadata' , async ( ) => {
85103 const principal = await createExecutorPrincipalFromExecutionContext ( {
86104 context : executionContext ( {
87- mcpBlockId : 'saved -block' ,
105+ mcpBlockId : 'credential -block' ,
88106 executorDelegationOrigin : { subjectUserId : 'user-origin' , workflowId : 'workflow-origin' } ,
89107 } ) ,
90- audience : 'sim:mcp-servers' ,
91- resourceScope : { mcpServerId : 'server-1' } ,
108+ audience : 'sim:credential-groups' ,
109+ } )
110+ expect ( principal . resourceScope ) . toBeUndefined ( )
111+ expect ( principal . subjectUserId ) . toBe ( 'user-origin' )
112+ expect ( principal . delegationContext ?. workflowId ) . toBe ( 'workflow-origin' )
113+ } )
114+
115+ it ( 'preserves another operation’s resource scope without adding MCP policy metadata' , async ( ) => {
116+ const principal = await createExecutorPrincipalFromExecutionContext ( {
117+ context : executionContext ( {
118+ mcpBlockId : 'agent-block' ,
119+ executorDelegationOrigin : { subjectUserId : 'user-origin' , workflowId : 'workflow-origin' } ,
120+ } ) ,
121+ audience : 'sim:tables' ,
122+ resourceScope : { tableId : 'table-1' } ,
92123 } )
93- expect ( principal . resourceScope ) . toEqual ( { mcpBlockId : 'saved-block' , mcpServerId : 'server -1' } )
124+ expect ( principal . resourceScope ) . toEqual ( { tableId : 'table -1' } )
94125 } )
95126
96127 it ( 'uses an explicit trusted execution deadline as the delegation expiry' , async ( ) => {
0 commit comments