Skip to content

Commit 83b209d

Browse files
committed
fix(lint): defer reference fields past the placeholder search bound
Above the search bound an all-string or all-list fallback cannot tell a literal error from a reference type mismatch, so leave the reference-bearing fields out and keep checking the other inputs instead of ending the table check.
1 parent 69cde75 commit 83b209d

2 files changed

Lines changed: 45 additions & 18 deletions

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,29 @@ describe('standalone table diagnostics against the actual Table block', () => {
307307
).toEqual([expect.objectContaining({ field: 'data', value: ['missing'] })])
308308
})
309309

310+
it('defers a filter with more mixed references than the placeholder search covers', async () => {
311+
const conditions = [
312+
...['a', 'b', 'c', 'd'].map((name) => `{"field":"name","op":"eq","value":<start.${name}>}`),
313+
...['e', 'f', 'g'].map((name) => `{"field":"name","op":"in","value":<start.${name}>}`),
314+
]
315+
setGraph(
316+
block('write', {
317+
operation: 'update_rows_by_filter',
318+
bulkFilterMode: 'json',
319+
filter: `{"all":[${conditions.join(',')}]}`,
320+
data: '{"name":"Ada","missing":1}',
321+
})
322+
)
323+
const result = await lint()
324+
expect(result.notes.filter((note) => note.includes('could not complete'))).toEqual([])
325+
expect(result.notes).toContain(
326+
'Table inputs in block "write" depend on references resolved at runtime and were not checked: filterInput.'
327+
)
328+
expect(
329+
result.unresolvedReferences.filter((reference) => reference.kind === 'resource')
330+
).toEqual([expect.objectContaining({ field: 'data', value: ['missing'] })])
331+
})
332+
310333
it('still reports an invalid literal condition beside a reference', async () => {
311334
setGraph(
312335
block('query', {

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -260,31 +260,33 @@ function hasRuntimeReference(value: string): boolean {
260260
* `{"name": <start.name>}` or a whole-field `<start.row>` is valid JSON at runtime but not before.
261261
* Each reference written outside a JSON string is replaced by a placeholder so the Table block's
262262
* own transform reads the literal parts: a quoted string, or a one-item list for slots such as a
263-
* filter `in`. Every combination is tried while there are few references (otherwise all-string
264-
* and all-list). A field that is a single whole reference has no literal part, so if no
265-
* combination fits it is left out and returned in `runtimeFields`. Any other failure, such as
266-
* malformed JSON or an invalid literal condition, is rethrown. Only this lint-local copy is
267-
* rewritten; references to string outputs left unquoted are reported by
263+
* filter `in`, trying every combination. A field that is a single whole reference has no literal
264+
* part, so if no combination fits it is left out and returned in `runtimeFields`. When the search
265+
* is exhaustive and still fails, the error comes from the literal parts (malformed JSON, an
266+
* invalid literal condition) and is rethrown. Past the search bound that cannot be told apart, so
267+
* every reference-bearing field is left out instead and the other inputs are still checked. Only
268+
* this lint-local copy is rewritten; references to string outputs left unquoted are reported by
268269
* `collectUnquotedJsonStringReferences`.
269270
*/
270271
function normalizeTableInputs(
271272
transform: (params: Record<string, unknown>) => Record<string, unknown>,
272273
params: Record<string, unknown>
273274
): { normalized: Record<string, unknown>; runtimeFields: string[] } {
274-
let hasReference = false
275+
const referenceFields: string[] = []
275276
const wholeReferenceFields: string[] = []
276277
for (const [key, value] of Object.entries(params)) {
277278
if (typeof value !== 'string') continue
278279
const trimmed = value.trim()
279280
const tokens = findWorkflowReferenceTokens(trimmed)
280281
if (tokens.length === 0) continue
281-
hasReference = true
282+
referenceFields.push(key)
282283
if (tokens.length === 1 && tokens[0].start === 0 && tokens[0].end === trimmed.length) {
283284
wholeReferenceFields.push(key)
284285
}
285286
}
286-
if (!hasReference) return { normalized: transform(params), runtimeFields: [] }
287+
if (referenceFields.length === 0) return { normalized: transform(params), runtimeFields: [] }
287288
const tiers = wholeReferenceFields.length > 0 ? [[], wholeReferenceFields] : [[]]
289+
let searchBounded = false
288290
let firstError: unknown
289291
for (const runtimeFields of tiers) {
290292
const withPlaceholders = (asList: (ordinal: number) => boolean) => {
@@ -302,22 +304,24 @@ function normalizeTableInputs(
302304
return { candidate, count: ordinal }
303305
}
304306
const { count } = withPlaceholders(() => false)
305-
const assignments: Array<(ordinal: number) => boolean> =
306-
count <= MAX_PLACEHOLDER_SEARCH_REFERENCES
307-
? Array.from(
308-
{ length: 2 ** count },
309-
(_, mask) => (ordinal) => ((mask >> ordinal) & 1) === 1
310-
)
311-
: [() => false, () => true]
312-
for (const asList of assignments) {
307+
if (count > MAX_PLACEHOLDER_SEARCH_REFERENCES) {
308+
searchBounded = true
309+
continue
310+
}
311+
for (let mask = 0; mask < 2 ** count; mask++) {
313312
try {
314-
return { normalized: transform(withPlaceholders(asList).candidate), runtimeFields }
313+
const { candidate } = withPlaceholders((ordinal) => ((mask >> ordinal) & 1) === 1)
314+
return { normalized: transform(candidate), runtimeFields }
315315
} catch (error) {
316316
firstError ??= error
317317
}
318318
}
319319
}
320-
throw firstError
320+
if (!searchBounded) throw firstError
321+
const literal = Object.fromEntries(
322+
Object.entries(params).filter(([key]) => !referenceFields.includes(key))
323+
)
324+
return { normalized: transform(literal), runtimeFields: referenceFields }
321325
}
322326

323327
/** Bounds the placeholder search to 2^6 pure transform calls per Table block. */

0 commit comments

Comments
 (0)