Skip to content

Commit 2f57f08

Browse files
fix(workflows): restore variables on deployment revert
1 parent 556b67e commit 2f57f08

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

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

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,73 @@ describe('Workflow deployment version revert route', () => {
155155
})
156156
)
157157
})
158+
159+
it('restores variables from the deployment snapshot', async () => {
160+
mockDbLimit.mockResolvedValue([
161+
{
162+
state: {
163+
blocks: { 'block-1': { id: 'block-1', type: 'start_trigger', name: 'Start' } },
164+
edges: [],
165+
loops: {},
166+
parallels: {},
167+
variables: {
168+
var1: { id: 'var1', name: 'API Token', type: 'string', value: 'secret' },
169+
},
170+
},
171+
},
172+
])
173+
mockValidateWorkflowAccess.mockResolvedValue({
174+
workflow: { id: 'wf-1', name: 'Test Workflow', workspaceId: 'ws-1' },
175+
auth: {
176+
success: true,
177+
userId: 'api-user',
178+
userName: 'API Key Actor',
179+
userEmail: 'api@example.com',
180+
authType: 'api_key',
181+
},
182+
})
183+
184+
const req = new NextRequest('http://localhost:3000/api/workflows/wf-1/deployments/3/revert', {
185+
method: 'POST',
186+
headers: { 'x-api-key': 'test-key' },
187+
})
188+
189+
await POST(req, { params: Promise.resolve({ id: 'wf-1', version: '3' }) })
190+
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+
)
199+
})
200+
201+
it('defaults variables safely when missing from the deployment snapshot', async () => {
202+
mockValidateWorkflowAccess.mockResolvedValue({
203+
workflow: { id: 'wf-1', name: 'Test Workflow', workspaceId: 'ws-1' },
204+
auth: {
205+
success: true,
206+
userId: 'api-user',
207+
userName: 'API Key Actor',
208+
userEmail: 'api@example.com',
209+
authType: 'api_key',
210+
},
211+
})
212+
213+
const req = new NextRequest('http://localhost:3000/api/workflows/wf-1/deployments/3/revert', {
214+
method: 'POST',
215+
headers: { 'x-api-key': 'test-key' },
216+
})
217+
218+
await POST(req, { params: Promise.resolve({ id: 'wf-1', version: '3' }) })
219+
220+
expect(mockSaveWorkflowToNormalizedTables).toHaveBeenCalledWith(
221+
'wf-1',
222+
expect.objectContaining({
223+
variables: {},
224+
})
225+
)
226+
})
158227
})

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export async function POST(
8989
edges: deployedState.edges,
9090
loops: deployedState.loops || {},
9191
parallels: deployedState.parallels || {},
92+
variables: deployedState.variables || {},
9293
lastSaved: Date.now(),
9394
deploymentStatuses: deployedState.deploymentStatuses || {},
9495
})

0 commit comments

Comments
 (0)