Skip to content

Commit 74d1658

Browse files
fix(workflows): persist variables on revert
1 parent f94df25 commit 74d1658

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

apps/sim/app/api/workflows/[id]/deployments/[version]/revert/route.test.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const {
1515
mockDbWhereUpdate,
1616
mockRecordAudit,
1717
mockSaveWorkflowToNormalizedTables,
18+
mockSetWorkflowVariables,
1819
mockSyncMcpToolsForWorkflow,
1920
mockValidateWorkflowAccess,
2021
} = vi.hoisted(() => ({
@@ -27,6 +28,7 @@ const {
2728
mockDbWhereUpdate: vi.fn(),
2829
mockRecordAudit: vi.fn(),
2930
mockSaveWorkflowToNormalizedTables: vi.fn(),
31+
mockSetWorkflowVariables: vi.fn(),
3032
mockSyncMcpToolsForWorkflow: vi.fn(),
3133
mockValidateWorkflowAccess: vi.fn(),
3234
}))
@@ -91,6 +93,10 @@ vi.mock('@/lib/mcp/workflow-mcp-sync', () => ({
9193
syncMcpToolsForWorkflow: (...args: unknown[]) => mockSyncMcpToolsForWorkflow(...args),
9294
}))
9395

96+
vi.mock('@/lib/workflows/utils', () => ({
97+
setWorkflowVariables: (...args: unknown[]) => mockSetWorkflowVariables(...args),
98+
}))
99+
94100
vi.mock('@/lib/audit/log', () => ({
95101
AuditAction: { WORKFLOW_DEPLOYMENT_REVERTED: 'WORKFLOW_DEPLOYMENT_REVERTED' },
96102
AuditResourceType: { WORKFLOW: 'WORKFLOW' },
@@ -119,6 +125,7 @@ describe('Workflow deployment version revert route', () => {
119125
mockDbSet.mockReturnValue({ where: mockDbWhereUpdate })
120126
mockDbWhereUpdate.mockResolvedValue(undefined)
121127
mockSaveWorkflowToNormalizedTables.mockResolvedValue({ success: true })
128+
mockSetWorkflowVariables.mockResolvedValue(undefined)
122129
mockFetch.mockResolvedValue({ ok: true })
123130
})
124131

@@ -188,14 +195,9 @@ describe('Workflow deployment version revert route', () => {
188195

189196
await POST(req, { params: Promise.resolve({ id: 'wf-1', version: '3' }) })
190197

191-
expect(mockSaveWorkflowToNormalizedTables).toHaveBeenCalledWith(
192-
'wf-1',
193-
expect.objectContaining({
194-
variables: {
195-
var1: { id: 'var1', name: 'API Token', type: 'string', value: 'secret' },
196-
},
197-
})
198-
)
198+
expect(mockSetWorkflowVariables).toHaveBeenCalledWith('wf-1', {
199+
var1: { id: 'var1', name: 'API Token', type: 'string', value: 'secret' },
200+
})
199201
})
200202

201203
it('defaults variables safely when missing from the deployment snapshot', async () => {
@@ -217,12 +219,7 @@ describe('Workflow deployment version revert route', () => {
217219

218220
await POST(req, { params: Promise.resolve({ id: 'wf-1', version: '3' }) })
219221

220-
expect(mockSaveWorkflowToNormalizedTables).toHaveBeenCalledWith(
221-
'wf-1',
222-
expect.objectContaining({
223-
variables: {},
224-
})
225-
)
222+
expect(mockSetWorkflowVariables).toHaveBeenCalledWith('wf-1', {})
226223
})
227224

228225
it('returns success when MCP sync throws after revert succeeds', async () => {

apps/sim/app/api/workflows/[id]/deployments/[version]/revert/route.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { env } from '@/lib/core/config/env'
88
import { generateRequestId } from '@/lib/core/utils/request'
99
import { syncMcpToolsForWorkflow } from '@/lib/mcp/workflow-mcp-sync'
1010
import { saveWorkflowToNormalizedTables } from '@/lib/workflows/persistence/utils'
11+
import { setWorkflowVariables } from '@/lib/workflows/utils'
1112
import { validateWorkflowAccess } from '@/app/api/workflows/middleware'
1213
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
1314

@@ -98,6 +99,8 @@ export async function POST(
9899
return createErrorResponse(saveResult.error || 'Failed to save deployed state', 500)
99100
}
100101

102+
await setWorkflowVariables(id, deployedState.variables || {})
103+
101104
await db
102105
.update(workflow)
103106
.set({ lastSynced: new Date(), updatedAt: new Date() })

0 commit comments

Comments
 (0)