Skip to content

Commit 590e502

Browse files
fix(mothership): scope mothership block tool permissions to the executing user (#4843)
1 parent c786ada commit 590e502

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

apps/sim/lib/copilot/request/lifecycle/run.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,37 @@ describe('runCopilotLifecycle', () => {
222222
})
223223
)
224224
})
225+
226+
it('propagates payload userPermission into the generated execution context', async () => {
227+
let capturedExecContext: ExecutionContext | undefined
228+
mockGetEffectiveDecryptedEnv.mockResolvedValueOnce({})
229+
mockRunStreamLoop.mockImplementationOnce(
230+
async (
231+
_fetchUrl: string,
232+
_fetchOptions: RequestInit,
233+
_context: StreamingContext,
234+
execContext: ExecutionContext
235+
): Promise<void> => {
236+
capturedExecContext = execContext
237+
}
238+
)
239+
240+
await runCopilotLifecycle(
241+
{ message: 'hello', messageId: 'stream-1', userPermission: 'write' },
242+
{
243+
userId: 'user-1',
244+
workspaceId: 'ws-1',
245+
chatId: 'chat-1',
246+
}
247+
)
248+
249+
expect(capturedExecContext).toEqual(
250+
expect.objectContaining({
251+
userId: 'user-1',
252+
workspaceId: 'ws-1',
253+
chatId: 'chat-1',
254+
userPermission: 'write',
255+
})
256+
)
257+
})
225258
})

apps/sim/lib/copilot/request/lifecycle/run.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ async function buildExecutionContext(
472472
const userTimezone =
473473
typeof requestPayload?.userTimezone === 'string' ? requestPayload.userTimezone : undefined
474474
const requestMode = typeof requestPayload?.mode === 'string' ? requestPayload.mode : undefined
475+
const userPermission =
476+
typeof requestPayload?.userPermission === 'string' ? requestPayload.userPermission : undefined
475477

476478
let execContext: ExecutionContext
477479
if (workflowId) {
@@ -490,6 +492,7 @@ async function buildExecutionContext(
490492
if (userTimezone) execContext.userTimezone = userTimezone
491493
execContext.copilotToolExecution = true
492494
if (requestMode) execContext.requestMode = requestMode
495+
if (userPermission) execContext.userPermission = userPermission
493496
execContext.messageId =
494497
typeof requestPayload?.messageId === 'string' ? requestPayload.messageId : undefined
495498
execContext.executionId = executionId

0 commit comments

Comments
 (0)