Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions apps/sim/lib/copilot/request/lifecycle/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})
)
})
})
3 changes: 3 additions & 0 deletions apps/sim/lib/copilot/request/lifecycle/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
Loading