Skip to content

Commit 112fa04

Browse files
committed
fix(realtime): reject locked-block tool updates and tighten new types
1 parent d2306ad commit 112fa04

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

apps/realtime/src/database/operations.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ describe('subblock update with canonical modes persistence', () => {
164164
)
165165
})
166166

167-
it('skips a locked block without writing either field', async () => {
168-
await expect(updateTools({ locked: true })).resolves.toBeUndefined()
167+
it('rejects a locked block without writing either field', async () => {
168+
await expect(updateTools({ locked: true })).rejects.toThrow('is locked')
169169
expect(mockSet).toHaveBeenCalledTimes(1)
170170
})
171171
})

apps/realtime/src/database/operations.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,10 +1998,10 @@ interface SubblockUpdateBlockRecord {
19981998

19991999
/** Every block in the workflow by id, for the locked-container check subblock writes need. */
20002000
async function loadSubblockUpdateBlocks(
2001-
tx: any,
2001+
tx: Pick<typeof db, 'select'>,
20022002
workflowId: string
20032003
): Promise<Record<string, SubblockUpdateBlockRecord>> {
2004-
const allBlocks: SubblockUpdateBlockRecord[] = await tx
2004+
const allBlocks = await tx
20052005
.select({
20062006
id: workflowBlocks.id,
20072007
subBlocks: workflowBlocks.subBlocks,
@@ -2083,11 +2083,12 @@ async function handleSubblockOperationTx(
20832083
throw new Error(`Block ${blockId} not found`)
20842084
}
20852085
if (isWorkflowBlockProtected(blockId, blocksById)) {
2086-
logger.info(`Skipping subblock update of locked block ${blockId}`)
2087-
break
2086+
throw new Error(`Block ${blockId} is locked or inside a locked container`)
20882087
}
20892088

2090-
const subBlocks = { ...((block.subBlocks as Record<string, any>) || {}) }
2089+
const subBlocks = {
2090+
...((block.subBlocks as Record<string, Record<string, unknown>> | null) || {}),
2091+
}
20912092
const currentSubBlock = subBlocks[subblockId]
20922093
subBlocks[subblockId] = currentSubBlock
20932094
? { ...currentSubBlock, value }

apps/sim/lib/workflows/editing/engine.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,10 @@ export function applyOperationsToWorkflowState(
261261
// blocks that are both being moved into the same subflow in one batch.
262262
removeInvalidScopeEdges(modifiedState, skippedItems)
263263

264-
reindexToolCanonicalModesAfterEdits((workflowState as any).blocks, (modifiedState as any).blocks)
264+
reindexToolCanonicalModesAfterEdits(
265+
workflowState.blocks as Record<string, BlockState> | undefined,
266+
modifiedState.blocks as Record<string, BlockState> | undefined
267+
)
265268

266269
// Regenerate loops and parallels after modifications
267270
;(modifiedState as any).loops = generateLoopBlocks((modifiedState as any).blocks)

0 commit comments

Comments
 (0)