mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
fix(copilot): align principal lifetime with orchestration (#6649)
* fix(copilot): align principal lifetime with orchestration * fix(copilot): align workflow lifetime expectation
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
executeCopilotWorkflowUseCase,
|
||||
messageForCopilotWorkflowError,
|
||||
} from '@/lib/copilot/application/execute-workflow-use-case'
|
||||
import { ORCHESTRATION_TIMEOUT_MS } from '@/lib/copilot/constants'
|
||||
import { OrchestrationError } from '@/lib/core/orchestration/types'
|
||||
import { workflowOperations } from '@/lib/workflows/application/operations'
|
||||
|
||||
@@ -57,7 +58,7 @@ describe('Copilot Workflow application adapter', () => {
|
||||
delegationId: 'copilot-tool:tool-call-1',
|
||||
audience: 'sim:workflows',
|
||||
issuedAt: new Date('2026-01-01T00:00:00Z'),
|
||||
expiresAt: new Date('2026-01-01T00:05:00Z'),
|
||||
expiresAt: new Date(Date.now() + ORCHESTRATION_TIMEOUT_MS),
|
||||
resourceScope: { chatId: 'chat-1', executionId: 'execution-1' },
|
||||
},
|
||||
input: { workflowId: 'workflow-1', assertedWorkspaceId: 'workspace-1' },
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { DelegatedPrincipal } from '@sim/auth/principal'
|
||||
import { ORCHESTRATION_TIMEOUT_MS } from '@/lib/copilot/constants'
|
||||
|
||||
export const COPILOT_APPLICATION_DELEGATION_TTL_MS = 5 * 60 * 1000
|
||||
/** Keeps delegated authority valid for the full bounded Copilot orchestration lifetime. */
|
||||
export const COPILOT_APPLICATION_DELEGATION_TTL_MS = ORCHESTRATION_TIMEOUT_MS
|
||||
|
||||
export interface CopilotExecutionContext {
|
||||
userId?: string
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
messageForCopilotFileError,
|
||||
resolveCopilotFilePrincipal,
|
||||
} from '@/lib/copilot/auth/file-delegation'
|
||||
import { ORCHESTRATION_TIMEOUT_MS } from '@/lib/copilot/constants'
|
||||
import { OrchestrationError } from '@/lib/core/orchestration/types'
|
||||
|
||||
const trustedContext = {
|
||||
@@ -20,7 +21,7 @@ const trustedContext = {
|
||||
}
|
||||
|
||||
describe('Copilot file delegation', () => {
|
||||
it('creates a short-lived principal scoped to the trusted workspace and file', () => {
|
||||
it('creates an orchestration-bounded principal scoped to the trusted workspace and file', () => {
|
||||
const principal = resolveCopilotFilePrincipal(trustedContext, 'file-1')
|
||||
|
||||
expect(principal).toMatchObject({
|
||||
@@ -36,7 +37,9 @@ describe('Copilot file delegation', () => {
|
||||
executionId: 'execution-1',
|
||||
},
|
||||
})
|
||||
expect(principal.expiresAt.getTime()).toBeGreaterThan(principal.issuedAt.getTime())
|
||||
expect(principal.expiresAt.getTime() - principal.issuedAt.getTime()).toBe(
|
||||
ORCHESTRATION_TIMEOUT_MS
|
||||
)
|
||||
})
|
||||
|
||||
it('creates a workspace-scoped principal for file creation', () => {
|
||||
|
||||
Reference in New Issue
Block a user