Skip to content

Commit 1d85f0c

Browse files
author
Waleed Latif
committed
test(github): evaluate subblock visibility with the block's own evaluator
The reachability guard hand-rolled its condition match and only looked at the top-level `operation` field, so it silently ignored `and:`. A compound-gated subBlock — `github_comment`'s `path` and `line`, which also need `commentType: 'file_comment'` — was therefore counted as visible under states where the editor does not render it, and the cast's type omitted `and`, so TypeScript could not flag the gap. That defect only ever over-reports available inputs, which is exactly the false confidence this file exists to remove: the guard could pass while a required param had no reachable field. Uses `evaluateSubBlockCondition` instead, satisfying the secondary gate before evaluating. "Can be rendered" is the right question for a reachability guard — whether an operation has any way to supply a required param, not whether one particular editor state happens to show it — and the helper now says so.
1 parent 5040596 commit 1d85f0c

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

apps/sim/blocks/blocks/github.test.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { describe, expect, it, vi } from 'vitest'
33
vi.unmock('@/blocks/registry')
44
vi.unmock('@/tools/registry')
55

6+
import { evaluateSubBlockCondition } from '@/lib/workflows/subblocks/visibility'
67
import { GitHubBlock } from '@/blocks/blocks/github'
78
import type { SubBlockConfig } from '@/blocks/types'
89
import { tools as toolRegistry } from '@/tools/registry'
@@ -25,14 +26,34 @@ const operations: string[] = (
2526
(subBlocks.find((sb) => sb.id === 'operation')?.options as { id: string }[] | undefined) ?? []
2627
).map((option) => option.id)
2728

28-
/** The subBlocks the editor renders once `operation` is chosen. */
29+
/**
30+
* The subBlocks that can be rendered for an operation, evaluated with the
31+
* block's own condition evaluator rather than a reimplementation of it.
32+
*
33+
* "Can be" rather than "are": a compound condition gates a subBlock on a second
34+
* field as well as the operation — `github_comment`'s `path` and `line` need
35+
* `commentType: 'file_comment'` — so the secondary gate is satisfied here
36+
* before evaluating. That is the right question for a reachability guard, which
37+
* asks whether an operation has *any* way to supply a required param, not
38+
* whether one particular editor state happens to show it. Hand-rolling the
39+
* match instead would silently ignore `and:` and over-report, which is the same
40+
* false confidence this file exists to remove.
41+
*/
2942
function visibleSubBlocks(operation: string): SubBlockConfig[] {
3043
return subBlocks.filter((sb) => {
31-
const condition = sb.condition as { field: string; value: unknown; not?: boolean } | undefined
44+
const condition = sb.condition
3245
if (!condition) return true
33-
if (condition.field !== 'operation') return false
34-
const allowed = Array.isArray(condition.value) ? condition.value : [condition.value]
35-
return condition.not ? !allowed.includes(operation) : allowed.includes(operation)
46+
if (typeof condition === 'function') return false
47+
48+
const values: AnyRecord = { operation }
49+
const secondary = (condition as { and?: { field: string; value: unknown } }).and
50+
if (secondary) {
51+
values[secondary.field] = Array.isArray(secondary.value)
52+
? secondary.value[0]
53+
: secondary.value
54+
}
55+
56+
return condition.field === 'operation' && evaluateSubBlockCondition(condition, values)
3657
})
3758
}
3859

0 commit comments

Comments
 (0)