Skip to content

Commit 54e16a0

Browse files
fix(tables): preserve workflow group scheduling
1 parent 5688be3 commit 54e16a0

2 files changed

Lines changed: 75 additions & 12 deletions

File tree

apps/sim/lib/table/application/groups.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ describe('workflow and enrichment Table application commands', () => {
201201
id: 'generated-id',
202202
workflowId: 'workflow-1',
203203
name: 'Scoring',
204+
autoRun: false,
204205
outputs: [{ blockId: 'block-2', path: 'score', columnName: 'score' }],
205206
}),
206207
outputColumns: [
@@ -218,6 +219,28 @@ describe('workflow and enrichment Table application commands', () => {
218219
expect(mocks.signal).toHaveBeenCalledWith(table.id)
219220
})
220221

222+
it('persists disabled auto-run on a newly created workflow group', async () => {
223+
const result = await createWorkflowTableGroup.execute({
224+
principal,
225+
input: {
226+
tableId: table.id,
227+
workspaceId: table.workspaceId,
228+
workflowId: 'workflow-1',
229+
outputs: [{ blockId: 'block-2', path: 'score' }],
230+
autoRun: false,
231+
},
232+
})
233+
234+
expect(result.group.autoRun).toBe(false)
235+
expect(mocks.addGroup).toHaveBeenCalledWith(
236+
expect.objectContaining({
237+
group: expect.objectContaining({ autoRun: false }),
238+
autoRun: false,
239+
}),
240+
'request-1'
241+
)
242+
})
243+
221244
it('conceals a cross-workspace workflow before group mutation or effects', async () => {
222245
mocks.resolveWorkflowContext.mockRejectedValueOnce(
223246
Object.assign(new Error('Workflow not found'), { code: 'not_found' })
@@ -295,6 +318,32 @@ describe('workflow and enrichment Table application commands', () => {
295318
expect(mocks.signal).toHaveBeenCalledWith(table.id)
296319
})
297320

321+
it('allows a replacement output to reuse the removed output column name', async () => {
322+
await updateWorkflowTableGroup.execute({
323+
principal,
324+
input: {
325+
tableId: table.id,
326+
workspaceId: table.workspaceId,
327+
groupId: group.id,
328+
outputs: [{ blockId: 'block-2', path: 'score', columnName: 'result' }],
329+
},
330+
})
331+
332+
expect(mocks.updateGroup).toHaveBeenCalledWith(
333+
expect.objectContaining({
334+
outputs: [{ blockId: 'block-2', path: 'score', columnName: 'result' }],
335+
newOutputColumns: [
336+
expect.objectContaining({
337+
name: 'result',
338+
type: 'number',
339+
workflowGroupId: group.id,
340+
}),
341+
],
342+
}),
343+
'request-1'
344+
)
345+
})
346+
298347
it('propagates a concurrent schema conflict without audit or effects', async () => {
299348
const conflict = Object.assign(new Error('retry the update'), { code: 'conflict' })
300349
mocks.updateGroup.mockRejectedValueOnce(conflict)

apps/sim/lib/table/application/groups.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@ import type { V2AddWorkflowGroupBody } from '@/lib/api/contracts/v2/tables'
66
import { OrchestrationError } from '@/lib/core/orchestration/types'
77
import { runDetached } from '@/lib/core/utils/background'
88
import { generateRequestId } from '@/lib/core/utils/request'
9-
import type {
10-
ColumnDefinition,
11-
DeleteWorkflowGroupData,
12-
TableDefinition,
13-
TableSchema,
14-
UpdateWorkflowGroupData,
15-
WorkflowGroup,
16-
WorkflowGroupDependencies,
17-
WorkflowGroupDeploymentMode,
18-
WorkflowGroupInputMapping,
19-
WorkflowGroupOutput,
9+
import {
10+
type ColumnDefinition,
11+
type DeleteWorkflowGroupData,
12+
getColumnId,
13+
type TableDefinition,
14+
type TableSchema,
15+
type UpdateWorkflowGroupData,
16+
type WorkflowGroup,
17+
type WorkflowGroupDependencies,
18+
type WorkflowGroupDeploymentMode,
19+
type WorkflowGroupInputMapping,
20+
type WorkflowGroupOutput,
2021
} from '@/lib/table'
2122
import { defineAuthorizedTableUseCase } from '@/lib/table/application/authorized-table-use-case'
2223
import { resolveActiveTableContext } from '@/lib/table/application/context'
@@ -298,6 +299,7 @@ export const createWorkflowTableGroup = defineAuthorizedTableUseCase({
298299
...(input.name ? { name: input.name } : {}),
299300
...(input.dependencies ? { dependencies: input.dependencies } : {}),
300301
...(input.deploymentMode ? { deploymentMode: input.deploymentMode } : {}),
302+
autoRun: input.autoRun ?? false,
301303
outputs,
302304
}
303305
const actorUserId = attributedUserId(principal, context.billedAccountUserId)
@@ -678,7 +680,19 @@ export const updateWorkflowTableGroup = defineAuthorizedTableUseCase({
678680
const existingByKey = new Map(
679681
previousGroup.outputs.map((output) => [`${output.blockId}::${output.path}`, output])
680682
)
681-
const taken = new Set(context.table.schema.columns.map((column) => column.name))
683+
const requestedKeys = new Set(
684+
input.outputs.map((output) => `${output.blockId}::${output.path}`)
685+
)
686+
const releasedColumnIds = new Set(
687+
previousGroup.outputs
688+
.filter((output) => !requestedKeys.has(`${output.blockId}::${output.path}`))
689+
.map((output) => output.columnName)
690+
)
691+
const taken = new Set(
692+
context.table.schema.columns
693+
.filter((column) => !releasedColumnIds.has(getColumnId(column)))
694+
.map((column) => column.name)
695+
)
682696
outputs = []
683697
newOutputColumns = []
684698
for (const requested of input.outputs) {

0 commit comments

Comments
 (0)