|
| 1 | +import { |
| 2 | + V2_OPERATION_RATE_LIMIT_ALLOWED, |
| 3 | + V2_PREAUTH_RATE_LIMIT_ALLOWED, |
| 4 | + v2ApiKeyAuthModuleMock, |
| 5 | + v2RateLimiterModuleMock, |
| 6 | + v2RouteMocks, |
| 7 | +} from '@sim/testing' |
| 8 | +import { createPersonalApiKeyPrincipal } from '@sim/testing/factories/principal.factory' |
| 9 | +import { createRouteContext } from '@sim/testing/helpers/http' |
| 10 | +import { auditMock } from '@sim/testing/mocks/audit.mock' |
| 11 | +import { createMockRequest } from '@sim/testing/mocks/request.mock' |
| 12 | +import { |
| 13 | + workflowContextMock, |
| 14 | + workflowContextMockFns, |
| 15 | +} from '@sim/testing/mocks/workflow-context.mock' |
| 16 | +import { |
| 17 | + workflowsOrchestrationMock, |
| 18 | + workflowsOrchestrationMockFns, |
| 19 | +} from '@sim/testing/mocks/workflows-orchestration.mock' |
| 20 | +import { |
| 21 | + workflowsPersistenceUtilsMock, |
| 22 | + workflowsPersistenceUtilsMockFns, |
| 23 | +} from '@sim/testing/mocks/workflows-persistence-utils.mock' |
| 24 | +import { workspaceAuthzMock, workspaceAuthzMockFns } from '@sim/testing/mocks/workspace-authz.mock' |
| 25 | +import { beforeEach, describe, expect, it, vi } from 'vitest' |
| 26 | + |
| 27 | +const mocks = vi.hoisted(() => ({ buildWorkflowLintReport: vi.fn() })) |
| 28 | + |
| 29 | +vi.mock('@sim/audit', () => auditMock) |
| 30 | +vi.mock('@sim/platform-authz/workspace', () => workspaceAuthzMock) |
| 31 | +vi.mock('@/lib/workflows/application/context', () => workflowContextMock) |
| 32 | +vi.mock('@/lib/workflows/orchestration', () => workflowsOrchestrationMock) |
| 33 | +vi.mock('@/lib/workflows/persistence/utils', () => workflowsPersistenceUtilsMock) |
| 34 | +vi.mock('@/lib/workflows/editing/lint-report', () => ({ |
| 35 | + buildWorkflowLintReport: mocks.buildWorkflowLintReport, |
| 36 | +})) |
| 37 | +vi.mock('@/lib/api/server/routes/v2-api-key-auth', () => v2ApiKeyAuthModuleMock) |
| 38 | +vi.mock('@/lib/core/rate-limiter', () => v2RateLimiterModuleMock) |
| 39 | + |
| 40 | +import { POST } from '@/app/api/v2/workflows/[workflowId]/deploy/route' |
| 41 | + |
| 42 | +const sideEffectWarning = |
| 43 | + 'Deployment activation completed, and post-activation notifications are queued.' |
| 44 | + |
| 45 | +const unquotedRowJson = { |
| 46 | + sources: [], |
| 47 | + sinks: [], |
| 48 | + orphanBlocks: [], |
| 49 | + emptyOutgoingPorts: [], |
| 50 | + invalidBranchPorts: [], |
| 51 | + invalidConnectionTargets: [], |
| 52 | + fieldIssues: [], |
| 53 | + unresolvedReferences: [ |
| 54 | + { |
| 55 | + blockId: 'insert', |
| 56 | + blockName: 'Insert Order', |
| 57 | + field: 'data', |
| 58 | + value: ['<start.order_id>'], |
| 59 | + kind: 'block-output' as const, |
| 60 | + reason: 'unquoted-json-string: quote it', |
| 61 | + }, |
| 62 | + ], |
| 63 | + tableFieldIssues: [], |
| 64 | + notes: [], |
| 65 | +} |
| 66 | + |
| 67 | +describe('POST /api/v2/workflows/[workflowId]/deploy', () => { |
| 68 | + beforeEach(() => { |
| 69 | + v2RouteMocks.authenticate.mockResolvedValue({ |
| 70 | + principal: createPersonalApiKeyPrincipal({ userId: 'user-1', keyId: 'personal-key-1' }), |
| 71 | + rateLimitSubjectIds: ['api-key:personal-key-1', 'user:user-1'], |
| 72 | + rateLimitSubscription: null, |
| 73 | + keyType: 'personal', |
| 74 | + }) |
| 75 | + v2RouteMocks.preauthRate.mockResolvedValue(V2_PREAUTH_RATE_LIMIT_ALLOWED) |
| 76 | + v2RouteMocks.operationRate.mockResolvedValue(V2_OPERATION_RATE_LIMIT_ALLOWED) |
| 77 | + workspaceAuthzMockFns.mockResolveEffectiveWorkspacePermission.mockResolvedValue('admin') |
| 78 | + workflowContextMockFns.mockResolveActiveWorkflowApplicationContext.mockResolvedValue({ |
| 79 | + workspaceId: 'workspace-1', |
| 80 | + workspaceOrganizationId: null, |
| 81 | + allowPersonalApiKeys: true, |
| 82 | + billedAccountUserId: 'billing-owner-1', |
| 83 | + workflowId: 'workflow-1', |
| 84 | + workflow: { id: 'workflow-1', workspaceId: 'workspace-1', isDeployed: true }, |
| 85 | + }) |
| 86 | + workflowsOrchestrationMockFns.mockPerformFullDeploy.mockResolvedValue({ |
| 87 | + success: true, |
| 88 | + version: 4, |
| 89 | + deploymentVersionId: 'version-4', |
| 90 | + activeDeployment: null, |
| 91 | + latestDeploymentAttempt: null, |
| 92 | + warnings: [sideEffectWarning], |
| 93 | + }) |
| 94 | + workflowsPersistenceUtilsMockFns.mockLoadWorkflowDeploymentVersionState.mockResolvedValue({ |
| 95 | + blocks: {}, |
| 96 | + edges: [], |
| 97 | + }) |
| 98 | + mocks.buildWorkflowLintReport.mockResolvedValue(unquotedRowJson) |
| 99 | + }) |
| 100 | + |
| 101 | + /** |
| 102 | + * Chat, the CLI, and API callers learn a deployed block cannot run from this |
| 103 | + * response. Mixed into `warnings`, the findings were indistinguishable from |
| 104 | + * failed side effects, so no surface could present them deliberately. |
| 105 | + */ |
| 106 | + it('publishes the deployed version lint apart from side-effect warnings', async () => { |
| 107 | + const response = await POST( |
| 108 | + createMockRequest('POST', {}, {}, 'http://localhost/api/v2/workflows/workflow-1/deploy'), |
| 109 | + createRouteContext({ workflowId: 'workflow-1' }) |
| 110 | + ) |
| 111 | + const body = await response.json() |
| 112 | + |
| 113 | + expect(response.status).toBe(200) |
| 114 | + expect(body.data.warnings).toEqual([sideEffectWarning]) |
| 115 | + expect(body.data.lint.unresolvedReferences).toEqual([ |
| 116 | + { |
| 117 | + blockId: 'insert', |
| 118 | + blockName: 'Insert Order', |
| 119 | + blockType: null, |
| 120 | + field: 'data', |
| 121 | + value: ['<start.order_id>'], |
| 122 | + kind: 'block-output', |
| 123 | + reason: 'unquoted-json-string: quote it', |
| 124 | + }, |
| 125 | + ]) |
| 126 | + }) |
| 127 | +}) |
0 commit comments