fix(mothership): scope mothership block tool permissions to the executing user (#4843)

This commit is contained in:
Theodore Li
2026-06-01 22:08:04 -04:00
committed by GitHub
parent c786adac2c
commit 590e502a38
2 changed files with 36 additions and 0 deletions
@@ -222,4 +222,37 @@ describe('runCopilotLifecycle', () => {
})
)
})
it('propagates payload userPermission into the generated execution context', async () => {
let capturedExecContext: ExecutionContext | undefined
mockGetEffectiveDecryptedEnv.mockResolvedValueOnce({})
mockRunStreamLoop.mockImplementationOnce(
async (
_fetchUrl: string,
_fetchOptions: RequestInit,
_context: StreamingContext,
execContext: ExecutionContext
): Promise<void> => {
capturedExecContext = execContext
}
)
await runCopilotLifecycle(
{ message: 'hello', messageId: 'stream-1', userPermission: 'write' },
{
userId: 'user-1',
workspaceId: 'ws-1',
chatId: 'chat-1',
}
)
expect(capturedExecContext).toEqual(
expect.objectContaining({
userId: 'user-1',
workspaceId: 'ws-1',
chatId: 'chat-1',
userPermission: 'write',
})
)
})
})
@@ -472,6 +472,8 @@ async function buildExecutionContext(
const userTimezone =
typeof requestPayload?.userTimezone === 'string' ? requestPayload.userTimezone : undefined
const requestMode = typeof requestPayload?.mode === 'string' ? requestPayload.mode : undefined
const userPermission =
typeof requestPayload?.userPermission === 'string' ? requestPayload.userPermission : undefined
let execContext: ExecutionContext
if (workflowId) {
@@ -490,6 +492,7 @@ async function buildExecutionContext(
if (userTimezone) execContext.userTimezone = userTimezone
execContext.copilotToolExecution = true
if (requestMode) execContext.requestMode = requestMode
if (userPermission) execContext.userPermission = userPermission
execContext.messageId =
typeof requestPayload?.messageId === 'string' ? requestPayload.messageId : undefined
execContext.executionId = executionId