Skip to content

Commit a560d00

Browse files
committed
fix(lint): defer table inputs whose quoted references fail predicate shape checks
A quoted reference can still fail the Table block's shape validation, for example a filter in-list or a whole-field filter. Retry the transform without those runtime-only fields and note them as runtime-resolved, so the remaining literal inputs are still checked. Filter cases now run against the registered TableV2Block.
1 parent 78456fd commit a560d00

2 files changed

Lines changed: 84 additions & 18 deletions

File tree

‎apps/sim/lib/workflows/application/read-workflow-lint-tables.test.ts‎

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ vi.mock('@/lib/workflows/editing/validation', () => ({
4141
import { OrchestrationError } from '@/lib/core/orchestration/types'
4242
import { readWorkflowLint } from '@/lib/workflows/application/read-workflow-lint'
4343
import { TableBlock } from '@/blocks/blocks/table'
44+
import { TableV2Block } from '@/blocks/blocks/table_v2'
4445

4546
const mocks = {
4647
snapshot: workflowsQueriesMockFns.mockLoadWorkflowReadSnapshot,
@@ -256,11 +257,49 @@ describe('standalone table diagnostics against the actual Table block', () => {
256257
])
257258
})
258259

259-
it('checks literal filter fields around a bare reference value', async () => {
260-
setGraph(block('query', { filter: '{"name": <start.name>, "other": {"$gt": <start.n>}}' }))
261-
const result = await lint()
262-
expect(result.notes.filter((note) => note.includes('could not complete'))).toEqual([])
263-
expect(result.tableFieldIssues.map(({ field }) => field)).toEqual(['other'])
260+
describe('with the registered TableV2Block predicate grammar', () => {
261+
beforeEach(() => {
262+
mockGetBlock.mockImplementation((type: string) =>
263+
type === 'table_v2' ? TableV2Block : undefined
264+
)
265+
})
266+
267+
it('checks literal predicate fields around a bare reference value', async () => {
268+
setGraph(
269+
block('query', {
270+
filter:
271+
'{"all":[{"field":"name","op":"eq","value":<start.name>},{"field":"other","op":"gt","value":<start.n>}]}',
272+
})
273+
)
274+
const result = await lint()
275+
expect(result.notes.filter((note) => note.includes('could not complete'))).toEqual([])
276+
expect(result.tableFieldIssues.map(({ field }) => field)).toEqual(['other'])
277+
})
278+
279+
it.each([
280+
['an in-list', '{"field":"name","op":"in","value":<start.names>}'],
281+
['a whole-field', '<start.filter>'],
282+
])(
283+
'notes %s filter reference as runtime-resolved and still checks literal row data',
284+
async (_shape, filter) => {
285+
setGraph(
286+
block('write', {
287+
operation: 'update_rows_by_filter',
288+
bulkFilterMode: 'json',
289+
filter,
290+
data: '{"name":"Ada","missing":1}',
291+
})
292+
)
293+
const result = await lint()
294+
expect(result.notes.filter((note) => note.includes('could not complete'))).toEqual([])
295+
expect(result.notes).toContain(
296+
'Table inputs in block "write" depend on references resolved at runtime and were not checked: filterInput.'
297+
)
298+
expect(
299+
result.unresolvedReferences.filter((reference) => reference.kind === 'resource')
300+
).toEqual([expect.objectContaining({ field: 'data', value: ['missing'] })])
301+
}
302+
)
264303
})
265304

266305
it.each([

‎apps/sim/lib/workflows/application/read-workflow-lint.ts‎

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -256,20 +256,41 @@ function hasRuntimeReference(value: string): boolean {
256256
}
257257

258258
/**
259-
* Outside Function code a reference resolves to JSON text (objects, numbers, booleans), so
259+
* Outside Function code a reference resolves to JSON text (objects, arrays, numbers, booleans), so
260260
* `{"name": <start.name>}` or a whole-field `<start.row>` is valid JSON at runtime but not before.
261-
* Quoting each reference written outside a JSON string lets the Table block's own parser read the
262-
* literal parts, and the quoted references then reach the existing runtime-resolution notes.
263-
* Only this lint-local copy is rewritten; references to string outputs left unquoted are reported
264-
* separately by `collectUnquotedJsonStringReferences`.
261+
* Quoting each reference written outside a JSON string lets the Table block's own transform read
262+
* the literal parts, and the quoted references then reach the existing runtime-resolution notes.
263+
* When the transform's shape validation rejects a quoted reference (a filter `in` list, a
264+
* whole-field filter), the fields that only parse once quoted are left out and returned as
265+
* `runtimeFields`; malformed literal JSON still throws. Only this lint-local copy is rewritten;
266+
* references to string outputs left unquoted are reported by `collectUnquotedJsonStringReferences`.
265267
*/
266-
function quoteBareReferenceParams(params: Record<string, unknown>): Record<string, unknown> {
267-
return Object.fromEntries(
268-
Object.entries(params).map(([key, value]) => [
269-
key,
270-
typeof value === 'string' ? quoteBareReferences(value) : value,
271-
])
272-
)
268+
function normalizeTableInputs(
269+
transform: (params: Record<string, unknown>) => Record<string, unknown>,
270+
params: Record<string, unknown>
271+
): { normalized: Record<string, unknown>; runtimeFields: string[] } {
272+
const quoted: Record<string, unknown> = {}
273+
const runtimeFields: string[] = []
274+
for (const [key, value] of Object.entries(params)) {
275+
quoted[key] = typeof value === 'string' ? quoteBareReferences(value) : value
276+
if (quoted[key] !== value && parsesAsJson(quoted[key])) runtimeFields.push(key)
277+
}
278+
try {
279+
return { normalized: transform(quoted), runtimeFields: [] }
280+
} catch (error) {
281+
if (runtimeFields.length === 0) throw error
282+
for (const key of runtimeFields) delete quoted[key]
283+
return { normalized: transform(quoted), runtimeFields }
284+
}
285+
}
286+
287+
function parsesAsJson(value: unknown): boolean {
288+
try {
289+
JSON.parse(String(value))
290+
return true
291+
} catch {
292+
return false
293+
}
273294
}
274295

275296
function quoteBareReferences(json: string): string {
@@ -357,7 +378,13 @@ async function readTableDiagnostics(
357378
if (!transform) throw new Error('Table input normalization is unavailable')
358379
let normalized: Record<string, unknown>
359380
try {
360-
normalized = transform(quoteBareReferenceParams(params))
381+
const inputs = normalizeTableInputs(transform, params)
382+
normalized = inputs.normalized
383+
if (inputs.runtimeFields.length > 0) {
384+
result.notes.push(
385+
`Table inputs in block "${block.name || blockId}" depend on references resolved at runtime and were not checked: ${inputs.runtimeFields.join(', ')}.`
386+
)
387+
}
361388
} catch (error) {
362389
result.notes.push(
363390
`Table input checks in block "${block.name || blockId}" could not complete before runtime: ${getErrorMessage(error)}`

0 commit comments

Comments
 (0)