From e6d37043e1a692a0e9666fca0ce82a2016f17600 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 08:34:08 +0000 Subject: [PATCH 1/5] wip(lint): flow-condition-option-label reads filters, edges and decision branches Claude-Session: https://claude.ai/code/session_01Utp6CY2uhJ1AYNPw5TUSVS Co-authored-by: Claude --- packages/lint/src/flow-select-options.ts | 118 ++++++++- .../src/validate-flow-trigger-readiness.ts | 242 +++++++++++++++++- 2 files changed, 348 insertions(+), 12 deletions(-) diff --git a/packages/lint/src/flow-select-options.ts b/packages/lint/src/flow-select-options.ts index b32710a3bdf..a9200ab0817 100644 --- a/packages/lint/src/flow-select-options.ts +++ b/packages/lint/src/flow-select-options.ts @@ -8,8 +8,9 @@ * `invalid_option`. * * Two rules read it: `flow-condition-option-label` - * (`validate-flow-trigger-readiness.ts`, a start condition comparing an - * option's label) and `flow-node-write-unknown-option` + * (`validate-flow-trigger-readiness.ts`, an option's label compared where the + * row holds its value: a start condition, an edge condition, a `decision` + * branch, a query filter's operand) and `flow-node-write-unknown-option` * (`validate-flow-node-writes.ts`, a CRUD write of a literal no option * carries). One reading, so the two cannot disagree about what an option is. * @@ -19,6 +20,7 @@ * extensions tie on (which definition wins is registration order). */ +import { flowFilterOperands } from '@objectstack/spec/automation'; import { isMultiValueField } from '@objectstack/spec/data'; import { objectsAsServed, objectsWithoutTiedFields, recordsOf } from './object-graph.js'; @@ -97,10 +99,36 @@ export interface OptionLabelComparison { /** One quoted literal, either quote (no escapes: a label with a quote in it is not judged). */ const QUOTED = String.raw`(?:'([^'\\]*)'|"([^"\\]*)")`; -/** A read of `field`: `record.F`, `previous.F` or bare `F`, not a member of something else. */ -function readOf(field: string): string { - const escaped = field.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); - return String.raw`(?:(?:record|previous)\.)?${escaped}(?![\w.])`; +const escapeRegExp = (text: string): string => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + +/** + * [#36964] How a condition reaches one object's fields: the variable roots a + * read is spelled under (`record.F`, `deal.F`), and whether a bare `F` reads + * the field too. + */ +export interface FieldReads { + /** Roots a read may be spelled under, each followed by `.F`. */ + readonly roots: readonly string[]; + /** Whether a bare `F` reads the field (the flattened trigger record). */ + readonly bare: boolean; + /** + * Names a bare read does NOT reach the field by: a flow variable, node id + * or screen field bound under the same name wins over the flattened field + * (`seedRunVariables`), so a bare read of one is a read of that binding. + */ + readonly shadowed?: ReadonlySet; +} + +/** The trigger record, as a start condition reads it: `record.F`, `previous.F` or bare `F`. */ +export const TRIGGER_RECORD_READS: FieldReads = Object.freeze({ roots: ['record', 'previous'], bare: true }); + +/** A read of `field` under `reads`, not a member of something else. */ +function readOf(field: string, reads: FieldReads): string { + const roots = reads.roots.map(escapeRegExp).join('|'); + const bare = reads.bare && !reads.shadowed?.has(field); + const root = roots ? String.raw`(?:(?:${roots})\.)${bare ? '?' : ''}` : ''; + if (!root && !bare) return String.raw`(?!)`; + return String.raw`${root}${escapeRegExp(field)}(?![\w.])`; } /** @@ -108,8 +136,8 @@ function readOf(field: string): string { * `'L' == F`, `'L' != F`, and each member of `F in [...]`. A literal that sits * elsewhere in the source (the comparand of another field) is not one. */ -function comparandsOf(src: string, field: string): string[] { - const read = readOf(field); +function comparandsOf(src: string, field: string, reads: FieldReads): string[] { + const read = readOf(field, reads); const lead = String.raw`(?:^|[^\w.])`; const out: string[] = []; const pick = (m: RegExpExecArray, at: number) => { @@ -133,17 +161,20 @@ function comparandsOf(src: string, field: string): string[] { * holds that option's value: the label must be the comparand of that field * (`F == 'L'`, `'L' != F`, `F in ['L', ...]`), not merely quoted somewhere in * the source. A label that is also some option's value is never reported - * (the literal may be that value). + * (the literal may be that value). `reads` says how the source reaches the + * object's fields: the trigger record by default, a record variable + * (`deal.F`) for a row a `get_record` step bound [#36964]. */ export function optionLabelComparisons( src: string, options: ReadonlyMap, + reads: FieldReads = TRIGGER_RECORD_READS, ): OptionLabelComparison[] { const out: OptionLabelComparison[] = []; for (const [field, opts] of options) { if (opts.labels.size === 0) continue; const seen = new Set(); - for (const literal of comparandsOf(src, field)) { + for (const literal of comparandsOf(src, field, reads)) { const value = opts.labels.get(literal); if (value === undefined || seen.has(literal)) continue; seen.add(literal); @@ -152,3 +183,70 @@ export function optionLabelComparisons( } return out; } + +/** [#36964] One label written as a query filter's operand where the value was meant. */ +export interface OptionLabelOperand extends OptionLabelComparison { + /** Where the operand sits inside the filter, as `flowFilterOperands` spells it. */ + readonly path: readonly (string | number)[]; + /** + * Whether the operand excludes (`$ne`, `$nin`, or under an odd number of + * `$not`), so the label excludes no record instead of matching none. + */ + readonly negated: boolean; +} + +/** The operators whose operand is compared with the field for (in)equality. */ +const EQUALITY_OPERATORS: ReadonlySet = new Set(['$eq', '$ne', '$in', '$nin']); +const EXCLUDING_OPERATORS: ReadonlySet = new Set(['$ne', '$nin']); + +/** + * [#36964] The option labels a query filter (`get_record` / `update_record` / + * `delete_record` `filter`, a time-relative sweep's `filter`) matches a select + * field of its object against, where the row holds that option's value. The + * filter is read the way the filter grammar reads it ({@link flowFilterOperands}, + * the spec's one walk of it): an operand counts when it is a field's implicit + * equality, its `$eq` / `$ne` comparand or a member of its `$in` / `$nin` + * list, at the top level or under `$and` / `$or` / `$not`. Not judged: a + * nested-relation condition (the field is another object's), an ordering or + * text operator, and any operand that is not a plain string — a CEL value + * envelope is evaluated before the query, and a string carrying a brace is a + * template or a query placeholder (`{current_user_id}`) resolved at run time. + * A label that is also some option's value is never reported. + */ +export function optionLabelOperands( + filter: unknown, + options: ReadonlyMap, +): OptionLabelOperand[] { + const out: OptionLabelOperand[] = []; + for (const { path, value } of flowFilterOperands(filter)) { + if (typeof value !== 'string' || value.includes('{')) continue; + let at = 0; + let negated = false; + while (at < path.length) { + const segment = path[at]; + if ((segment === '$and' || segment === '$or') && typeof path[at + 1] === 'number') at += 2; + else if (segment === '$not') { + negated = !negated; + at += 1; + } else break; + } + const field = path[at]; + if (typeof field !== 'string' || field.startsWith('$')) continue; + const opts = options.get(field); + const meant = opts?.labels.get(value); + if (meant === undefined) continue; + const rest = path.slice(at + 1); + const operator = rest.length === 0 ? '$eq' : rest[0]; + if (typeof operator !== 'string' || !EQUALITY_OPERATORS.has(operator)) continue; + // A list element is a member of `$in` / `$nin`; any deeper path is no operand of this field's. + if (rest.length > 2 || (rest.length === 2 && (typeof rest[1] !== 'number' || !operator.endsWith('in')))) continue; + out.push({ + field, + label: value, + value: meant, + path, + negated: negated !== EXCLUDING_OPERATORS.has(operator), + }); + } + return out; +} diff --git a/packages/lint/src/validate-flow-trigger-readiness.ts b/packages/lint/src/validate-flow-trigger-readiness.ts index 39ac4cadd7e..a8aad609456 100644 --- a/packages/lint/src/validate-flow-trigger-readiness.ts +++ b/packages/lint/src/validate-flow-trigger-readiness.ts @@ -211,14 +211,19 @@ import { API_TRIGGER_SECRET_REF_KEY, + FLOW_NODE_EXPRESSION_PATHS, TimeRelativeTriggerSchema, apiTriggerSecretRefOf, apiTriggerSignatureRefusals, apiTriggerVerifierOf, + collectFlowGraphs, resolveFlowTriggerKind, + type FlowEdgeParsed, + type FlowNodeParsed, } from '@objectstack/spec/automation'; import { resolvePackageClosure } from '@objectstack/metadata-core'; -import { walkFlowNodes } from './flow-walk.js'; +import { flowNodeLabel, walkFlowNodes } from './flow-walk.js'; +import { collectFlowVariableNames, collectScreenFieldNames } from './flow-variable-scope.js'; import { closureDependencyRemedy, indexServedObjectGraph, @@ -227,7 +232,14 @@ import { suggestName, type ObjectGraph, } from './object-graph.js'; -import { indexSelectOptions, optionLabelComparisons, type SelectOptions } from './flow-select-options.js'; +import { + TRIGGER_RECORD_READS, + indexSelectOptions, + optionLabelComparisons, + optionLabelOperands, + type FieldReads, + type SelectOptions, +} from './flow-select-options.js'; import type { UserTextParams } from './finding-user-text.js'; export type FlowTriggerReadinessSeverity = 'error' | 'warning'; @@ -413,6 +425,25 @@ export const FLOW_TRIGGER_OBJECT_MISSING = 'flow-trigger-object-missing'; * where the field stores the option's VALUE (`closed_lost`). The row holds * the value, so the comparison is always false (or always true for `!=`) and * the condition never tells one record from another. + * + * [#36964] One id for the one mistake wherever the flow compares the field, + * read by {@link optionLabelsBeyondStart}: an edge condition and a `decision` + * branch (on the trigger record, or on a row a `get_record` step bound to a + * variable), and a query filter's operand (`get_record` / `update_record` / + * `delete_record` `filter`, a time-relative sweep's `filter`). A flow filter + * is handed to the data engine as written, never resolved label → value + * (ADR-0061 D4 resolves labels for the query surfaces, not for an authored + * flow), so the label matches no row: the read finds nothing, the update or + * delete acts on nothing, the branch is never taken, and the run still + * reports success. Not the write rule's id (`flow-node-write-unknown-option`): + * that one's verdict is a write the record validator refuses, and a filter + * operand is refused by nothing. + * + * `error` at every position, the start condition's severity, on #5762's + * question: the label, the field's inline options and the object are all in + * this stack, and nothing installed changes what the row stores. A filter + * that means to find rows still holding a label (a clean-up after an options + * change) spells the operand as a CEL value envelope, which is not judged. */ export const FLOW_CONDITION_OPTION_LABEL = 'flow-condition-option-label'; /** @@ -688,6 +719,205 @@ function conditionSourceOf(raw: unknown): string { return ''; } +/** + * [#36964] The node types whose `config.filter` is a query filter of the + * node's own object — read off the spec's expression ledger (the entries that + * declare `filterOperands`), so a node type that gains the filter shape there + * is read here without a second list. + */ +const FILTER_NODE_TYPES: ReadonlySet = new Set( + FLOW_NODE_EXPRESSION_PATHS.filter((entry) => entry.filterOperands && entry.path === 'filter').map((entry) => entry.nodeType), +); + +/** A literal, non-empty object name; a templated one (`{…}`) is resolved at run time. */ +function literalObjectName(raw: unknown): string | undefined { + return typeof raw === 'string' && raw.trim() !== '' && !raw.includes('{') ? raw : undefined; +} + +/** A graph's key path in this file's path spelling: `['nodes', 1, 'config', 'body']` → `.nodes[1].config.body`. */ +function graphPathText(path: readonly (string | number)[]): string { + return path.map((segment) => (typeof segment === 'number' ? `[${segment}]` : `.${segment}`)).join(''); +} + +/** The object holding a graph's `nodes` / `edges` as AUTHORED, so an index names the author's list. */ +function graphHolder(flow: AnyRec, path: readonly (string | number)[]): AnyRec | undefined { + let at: unknown = flow; + for (const segment of path) { + if (!at || typeof at !== 'object') return undefined; + at = (at as Record)[segment]; + } + return at && typeof at === 'object' && !Array.isArray(at) ? (at as AnyRec) : undefined; +} + +/** + * [#36964] `flow-condition-option-label` past the start condition (1-iii): + * + * - a query FILTER's operand — every node in {@link FILTER_NODE_TYPES}, at any + * region depth, against its own literal `objectName`, and a time-relative + * start's `timeRelative.filter` against the swept object; + * - an EDGE condition and a `decision` node's `conditions[].expression`, in + * every graph of the flow, against the rows the condition can name: the + * trigger record (`record.F`, `previous.F`, bare `F` unless a binding of the + * same name shadows it) on a record-change or time-relative flow, and the + * row a single-row `get_record` step bound to its `outputVariable` + * (`deal.F`). A variable bound by anything else as well — another step, a + * declared variable, a node id, a screen field — is not judged: which value + * it holds when the condition runs is the run's. + */ +function optionLabelsBeyondStart( + flow: AnyRec, + flowIndex: number, + flowName: string, + start: { node: AnyRec; index: number } | undefined, + startConfig: AnyRec, + optionsIndex: () => ReadonlyMap>, +): FlowTriggerReadinessFinding[] { + const findings: FlowTriggerReadinessFinding[] = []; + + const filterFindings = (filter: unknown, objectName: string, where: string, path: string): void => { + const options = optionsIndex().get(objectName); + if (!options) return; + for (const hit of optionLabelOperands(filter, options)) { + findings.push({ + severity: 'error', + rule: FLOW_CONDITION_OPTION_LABEL, + where, + path: path + graphPathText(hit.path), + message: + `filters '${objectName}.${hit.field}' on '${hit.label}', which is that option's label; the field stores ` + + `the value '${hit.value}', so no record holds '${hit.label}' and the filter ` + + (hit.negated ? 'excludes no record' : 'matches no record'), + hint: `Filter on the option's value: write '${hit.value}' in place of '${hit.label}'`, + }); + } + }; + + // Query filters: the CRUD nodes, nested regions included. + for (const { node, path, regionTrail } of walkFlowNodes(flow, `flows[${flowIndex}]`)) { + if (typeof node.type !== 'string' || !FILTER_NODE_TYPES.has(node.type)) continue; + const cfg = node.config; + if (!cfg || typeof cfg !== 'object' || Array.isArray(cfg)) continue; + const objectName = literalObjectName((cfg as AnyRec).objectName); + if (!objectName || (cfg as AnyRec).filter === undefined) continue; + const label = flowNodeLabel(node, Number(path.slice(path.lastIndexOf('[') + 1, -1))); + const where = `flow "${flowName}" › ${regionTrail ? `${regionTrail} › ` : ''}node "${label}"`; + filterFindings((cfg as AnyRec).filter, objectName, where, `${path}.config.filter`); + } + + // The sweep's own filter, on the swept object. + const timeRelative = startConfig.timeRelative; + const sweptObject = + timeRelative && typeof timeRelative === 'object' && !Array.isArray(timeRelative) + ? literalObjectName((timeRelative as AnyRec).object) + : undefined; + if (start && sweptObject && (timeRelative as AnyRec).filter !== undefined) { + filterFindings( + (timeRelative as AnyRec).filter, + sweptObject, + `flow "${flowName}" › start node`, + `flows[${flowIndex}].nodes[${start.index}].config.timeRelative.filter`, + ); + } + + // Conditions: which rows they can name, then every edge and decision branch. + const graphs = collectFlowGraphs({ + ...flow, + nodes: recordsOf(flow.nodes) as unknown as FlowNodeParsed[], + edges: recordsOf(flow.edges) as unknown as FlowEdgeParsed[], + }); + const triggerType = typeof startConfig.triggerType === 'string' ? startConfig.triggerType : undefined; + const triggerObject = triggerType?.startsWith('record-') + ? literalObjectName(startConfig.objectName) + : sweptObject; + + // A single-row `get_record` binds its row to `outputVariable` (the `findOne` + // branch: `limit` absent or 1); a name bound by anything else as well is + // ambiguous and dropped. + const rowVariables = new Map(); + const rowReaders = new Set(); + for (const graph of graphs) { + for (const node of graph.nodes as unknown as AnyRec[]) { + if (node.type !== 'get_record' || !node.config || typeof node.config !== 'object') continue; + const cfg = node.config as AnyRec; + const variable = typeof cfg.outputVariable === 'string' && cfg.outputVariable ? cfg.outputVariable : undefined; + const objectName = literalObjectName(cfg.objectName); + if (!variable || !objectName || variable === 'record' || variable === 'previous') continue; + if (cfg.limit !== undefined && cfg.limit !== 1) continue; + rowReaders.add(node); + const prior = rowVariables.get(variable); + rowVariables.set(variable, prior === undefined || prior === objectName ? objectName : null); + } + } + const screenNames = collectScreenFieldNames(graphs); + const boundElsewhere = collectFlowVariableNames( + flow, + graphs.map((graph) => ({ nodes: graph.nodes.filter((node) => !rowReaders.has(node)) })), + ); + const readers: Array<{ objectName: string; reads: FieldReads }> = []; + if (triggerObject) { + const shadowed = new Set([...collectFlowVariableNames(flow, graphs), ...screenNames]); + readers.push({ objectName: triggerObject, reads: { ...TRIGGER_RECORD_READS, shadowed } }); + } + for (const [variable, objectName] of rowVariables) { + if (objectName === null || boundElsewhere.has(variable) || screenNames.has(variable)) continue; + readers.push({ objectName, reads: { roots: [variable], bare: false } }); + } + if (readers.length === 0) return findings; + + const conditionFindings = (raw: unknown, where: string, path: string): void => { + const src = conditionSourceOf(raw); + if (!src) return; + for (const { objectName, reads } of readers) { + const options = optionsIndex().get(objectName); + if (!options) continue; + for (const hit of optionLabelComparisons(src, options, reads)) { + findings.push({ + severity: 'error', + rule: FLOW_CONDITION_OPTION_LABEL, + where, + path, + message: + `compares '${objectName}.${hit.field}' with '${hit.label}', which is that option's label; the ` + + `field stores the value '${hit.value}', so the comparison never matches a record`, + hint: `Compare with the option's value: write '${hit.value}' in place of '${hit.label}'`, + }); + } + } + }; + + for (const graph of graphs) { + const holder = graphHolder(flow, graph.path); + if (!holder) continue; + const base = `flows[${flowIndex}]${graphPathText(graph.path)}`; + const scope = graph.scope ? `${graph.scope} › ` : ''; + if (Array.isArray(holder.edges)) { + holder.edges.forEach((edge: unknown, edgeIndex: number) => { + if (!edge || typeof edge !== 'object' || Array.isArray(edge)) return; + const e = edge as AnyRec; + const id = typeof e.id === 'string' && e.id ? e.id : `#${edgeIndex}`; + conditionFindings(e.condition, `flow "${flowName}" › ${scope}edge "${id}"`, `${base}.edges[${edgeIndex}].condition`); + }); + } + if (Array.isArray(holder.nodes)) { + holder.nodes.forEach((node: unknown, nodeIndex: number) => { + if (!node || typeof node !== 'object' || Array.isArray(node)) return; + const n = node as AnyRec; + const cfg = n.config as AnyRec | undefined; + if (n.type !== 'decision' || !cfg || typeof cfg !== 'object' || !Array.isArray(cfg.conditions)) return; + cfg.conditions.forEach((branch: unknown, branchIndex: number) => { + if (!branch || typeof branch !== 'object' || Array.isArray(branch)) return; + conditionFindings( + (branch as AnyRec).expression, + `flow "${flowName}" › ${scope}node "${flowNodeLabel(n, nodeIndex)}"`, + `${base}.nodes[${nodeIndex}].config.conditions[${branchIndex}].expression`, + ); + }); + }); + } + } + return findings; +} + /** * [#35143] The cron expression of a `config.schedule` that names no * `timezone`, read in the shapes the schedule trigger's `normalizeSchedule` @@ -881,6 +1111,14 @@ export function validateFlowTriggerReadiness( } } + // 1-iv. [#36964] The same label, compared everywhere else the flow + // compares a select field: a query filter's operand, an edge + // condition, a `decision` branch. Built lazily: a flow with none of + // them never pays for the options index. + findings.push( + ...optionLabelsBeyondStart(flow, flowIndex, flowName, start, config, () => (selectOptions ??= indexSelectOptions(stack))), + ); + // 1b. Two facts about the same `config.timeRelative` descriptor, from the two // places that can decide them. The split is what keeps them from // reporting the same thing twice: From 09c0e2300d64c8f651ffbcf4397ce81a5f5267ed Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 08:41:43 +0000 Subject: [PATCH 2/5] test(lint): pin flow-condition-option-label on filters, edges and decision branches Claude-Session: https://claude.ai/code/session_01Utp6CY2uhJ1AYNPw5TUSVS Co-authored-by: Claude --- .../flow-publish-checks-second-batch.test.ts | 158 ++++++++++++++++++ 1 file changed, 158 insertions(+) diff --git a/packages/lint/src/flow-publish-checks-second-batch.test.ts b/packages/lint/src/flow-publish-checks-second-batch.test.ts index 3e330f03131..a7350dea1ba 100644 --- a/packages/lint/src/flow-publish-checks-second-batch.test.ts +++ b/packages/lint/src/flow-publish-checks-second-batch.test.ts @@ -206,6 +206,164 @@ describe('flow-condition-option-label', () => { }); }); +describe('flow-condition-option-label past the start condition (#36964)', () => { + const labelHits = (findings: readonly { rule: string }[]) => + findings.filter((f) => f.rule === FLOW_CONDITION_OPTION_LABEL) as AnyRec[]; + + /** A manual flow: no trigger record, so every hit below is the filter's or a bound row's. */ + const manual = (nodes: AnyRec[], extra: AnyRec = {}) => stack(flow('sweep', {}, nodes, extra)); + const crud = (type: string, filter: unknown, extra: AnyRec = {}) => ({ + id: 'step', + type, + label: 'Step', + config: { objectName: 'deal', filter, ...extra }, + }); + + it('refuses a label in a get_record filter, at the operand, naming the value', () => { + const hit = labelHits(validateFlowTriggerReadiness(manual([crud('get_record', { stage: 'Closed Lost' }, { outputVariable: 'deal' })]))); + expect(hit).toHaveLength(1); + expect(hit[0]).toMatchObject({ severity: 'error', path: 'flows[0].nodes[1].config.filter.stage' }); + expect(hit[0].message).toContain('matches no record'); + expect(hit[0].hint).toBe("Filter on the option's value: write 'closed_lost' in place of 'Closed Lost'"); + }); + + it('refuses a label in an update_record and a delete_record filter, operator, list and combinator forms included', () => { + const update = labelHits( + validateFlowTriggerReadiness(manual([crud('update_record', { stage: { $eq: 'Closed Lost' } }, { multi: true, fields: { name: 'x' } })])), + ); + expect(update.map((f) => f.path)).toEqual(['flows[0].nodes[1].config.filter.stage.$eq']); + + const remove = labelHits( + validateFlowTriggerReadiness( + manual([crud('delete_record', { $or: [{ stage: { $in: ['open', 'Closed Lost'] } }, { tags: 'Hot' }] })]), + ), + ); + expect(remove.map((f) => f.path)).toEqual([ + 'flows[0].nodes[1].config.filter.$or[0].stage.$in[1]', + 'flows[0].nodes[1].config.filter.$or[1].tags', + ]); + }); + + it('says an excluding operand excludes no record', () => { + const hit = labelHits(validateFlowTriggerReadiness(manual([crud('get_record', { stage: { $ne: 'Closed Lost' } })]))); + expect(hit).toHaveLength(1); + expect(hit[0].message).toContain('excludes no record'); + }); + + it('reads a filter inside a region, and a time-relative sweep filter', () => { + const loop = { + id: 'each', + type: 'loop', + label: 'Each', + config: { collection: { dialect: 'cel', source: '[1]' }, iteratorVariable: 'i', body: { nodes: [crud('get_record', { stage: 'Closed Lost' })], edges: [] } }, + }; + expect(labelHits(validateFlowTriggerReadiness(manual([loop]))).map((f) => f.path)).toEqual([ + 'flows[0].nodes[1].config.body.nodes[0].config.filter.stage', + ]); + const sweep = labelHits( + validateFlowTriggerReadiness(stack(flow('remind', { objectName: 'deal', timeRelative: { ...SWEEP, filter: { stage: 'Closed Lost' } } }))), + ); + expect(sweep.map((f) => f.path)).toEqual(['flows[0].nodes[0].config.timeRelative.filter.stage']); + }); + + it('is silent on the value, an expression operand, a template string, a picklist field and a nested relation', () => { + for (const filter of [ + { stage: 'closed_lost' }, + { stage: { dialect: 'cel', source: "'Closed Lost'" } }, + { stage: '{{wanted_stage}}' }, + { stage: { $in: [{ dialect: 'cel', source: 'wanted' }] } }, + { region: 'Anywhere' }, + { account: { stage: 'Closed Lost' } }, + { stage: { $gt: 'Closed Lost' } }, + ]) { + expect(rulesOf(validateFlowTriggerReadiness(manual([crud('get_record', filter)]))), JSON.stringify(filter)).not.toContain( + FLOW_CONDITION_OPTION_LABEL, + ); + } + }); + + /** A get_record binding `deal`, then a decision whose out-edges compare. */ + const branching = (condition: unknown, getConfig: AnyRec = {}, extra: AnyRec = {}): AnyRec => + stack({ + ...flow('route', {}, [], extra), + nodes: [ + startNode({}), + { id: 'load', type: 'get_record', label: 'Load', config: { objectName: 'deal', filter: { id: 'd1' }, outputVariable: 'deal', ...getConfig } }, + { id: 'check', type: 'decision', label: 'Check', config: {} }, + { id: 'lost', type: 'end', label: 'Lost', config: {} }, + { id: 'other', type: 'end', label: 'Other', config: {} }, + ], + edges: [ + { id: 'e0', source: 'start', target: 'load' }, + { id: 'e1', source: 'load', target: 'check' }, + { id: 'e2', source: 'check', target: 'lost', condition }, + { id: 'e3', source: 'check', target: 'other', isDefault: true }, + ], + }); + + it('refuses a decision edge condition comparing a row a get_record bound with a label', () => { + const hit = labelHits(validateFlowTriggerReadiness(branching("deal.stage == 'Closed Lost'"))); + expect(hit).toHaveLength(1); + expect(hit[0]).toMatchObject({ severity: 'error', path: 'flows[0].edges[2].condition' }); + expect(hit[0].hint).toContain("'closed_lost'"); + expect(rulesOf(validateFlowTriggerReadiness(branching({ dialect: 'cel', source: "deal.stage in ['Closed Lost']" })))).toContain( + FLOW_CONDITION_OPTION_LABEL, + ); + }); + + it("refuses an edge on a record-change flow comparing the trigger record, and a decision node's branch", () => { + const onRecord = stack( + flow('lost', { triggerType: 'record-after-update', objectName: 'deal' }, [{ id: 'tell', type: 'end', label: 'Tell', config: {} }]), + ); + onRecord.flows[0].edges[0].condition = "record.stage == 'Closed Lost'"; + expect(labelHits(validateFlowTriggerReadiness(onRecord)).map((f) => f.path)).toEqual(['flows[0].edges[0].condition']); + + const branched = branching(undefined); + branched.flows[0].nodes[2].config = { conditions: [{ label: 'lost', expression: "deal.stage == 'Closed Lost'" }] }; + expect(labelHits(validateFlowTriggerReadiness(branched)).map((f) => f.path)).toEqual([ + 'flows[0].nodes[2].config.conditions[0].expression', + ]); + }); + + it('is silent on the value, an expression comparand, and a row the condition cannot be sure of', () => { + const cases: Array<[string, AnyRec]> = [ + ['the value', branching("deal.stage == 'closed_lost'")], + ['a variable comparand', branching('deal.stage == wanted_stage')], + ['a template comparand', branching("deal.stage == '{{wanted_stage}}'")], + ['a list read (limit > 1)', branching("deal.stage == 'Closed Lost'", { limit: 5 })], + ['a templated object', branching("deal.stage == 'Closed Lost'", { objectName: '{object}' })], + [ + 'a name also declared as a flow variable', + branching("deal.stage == 'Closed Lost'", {}, { variables: [{ name: 'deal', type: 'object' }] }), + ], + ['a manual flow reading a bare field (no trigger record)', branching("stage == 'Closed Lost'")], + ]; + for (const [label, s] of cases) { + expect(rulesOf(validateFlowTriggerReadiness(s)), label).not.toContain(FLOW_CONDITION_OPTION_LABEL); + } + // A bare read on a record-change flow is the trigger field — unless a variable of that name shadows it. + const bare = (extra: AnyRec) => { + const s = stack( + flow('lost', { triggerType: 'record-after-update', objectName: 'deal' }, [{ id: 'tell', type: 'end', label: 'Tell', config: {} }], extra), + ); + s.flows[0].edges[0].condition = "stage == 'Closed Lost'"; + return rulesOf(validateFlowTriggerReadiness(s)); + }; + expect(bare({})).toContain(FLOW_CONDITION_OPTION_LABEL); + expect(bare({ variables: [{ name: 'stage', type: 'text' }] })).not.toContain(FLOW_CONDITION_OPTION_LABEL); + }); + + it('os validate reports it, and the runtime publish gate refuses the flow write', () => { + const s = branching("deal.stage == 'Closed Lost'"); + expect(rulesOf(runAuthoringRules('validate', { normalized: s } as never))).toContain(FLOW_CONDITION_OPTION_LABEL); + const verdict = runRuntimeAuthoringRules({ type: 'flow', item: s.flows[0], context: { objects: [DEAL] } }); + expect(rulesOf(verdict.errors)).toContain(FLOW_CONDITION_OPTION_LABEL); + const filtered = manual([crud('update_record', { stage: 'Closed Lost' }, { fields: { name: 'x' } })]); + const filterVerdict = runRuntimeAuthoringRules({ type: 'flow', item: filtered.flows[0], context: { objects: [DEAL] } }); + expect(rulesOf(filterVerdict.errors)).toContain(FLOW_CONDITION_OPTION_LABEL); + }); +}); + describe('flow-time-relative-shadowed', () => { it('refuses a record-* token beside a sweep descriptor', () => { const findings = validateFlowTriggerReadiness( From 4e9c077b1cf03c0573b5509b1bfef517fb6fea92 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 08:48:12 +0000 Subject: [PATCH 3/5] fix(lint): flow-condition-option-label reads query filters, edge conditions and decision branches Claude-Session: https://claude.ai/code/session_01Utp6CY2uhJ1AYNPw5TUSVS Co-authored-by: Claude --- .changeset/36964-flow-option-label-filters.md | 17 +++++++++++++++++ packages/lint/src/validate-flow-node-writes.ts | 5 +++++ 2 files changed, 22 insertions(+) create mode 100644 .changeset/36964-flow-option-label-filters.md diff --git a/.changeset/36964-flow-option-label-filters.md b/.changeset/36964-flow-option-label-filters.md new file mode 100644 index 00000000000..5e75b68989d --- /dev/null +++ b/.changeset/36964-flow-option-label-filters.md @@ -0,0 +1,17 @@ +--- +'@objectstack/lint': patch +--- + +fix(lint): `os validate` refuses an option label in a flow's query filter, edge condition or decision branch + +Clause-②: no +Metadata-protocol: none + +A select field stores the option's value, never its label, and a flow hands its filters and conditions to the data engine and the expression engine as written: nothing resolves a label to its value there. So `filter: { stage: 'Closed Lost' }` on a `get_record`, `update_record` or `delete_record` step matched no row, and the step reported success having read, updated or deleted nothing; an edge condition or `decision` branch `deal.stage == 'Closed Lost'` was never taken. `os validate` said nothing, because `flow-condition-option-label` read only the start condition. + +`flow-condition-option-label` (`error`, as on the start condition) now also reads: + +- each operand of a `get_record` / `update_record` / `delete_record` `filter`, and of a time-relative sweep's `timeRelative.filter`: a field's implicit equality, its `$eq` / `$ne` comparand and each member of its `$in` / `$nin` list, at the top level or under `$and` / `$or` / `$not`, at any region depth; +- every edge condition and every `decision` node's `conditions[].expression`, where it compares a select field of the trigger record (`record.F`, `previous.F`, a bare `F` no flow variable shadows) on a record-change or time-relative flow, or of the row a single-row `get_record` step bound to its `outputVariable` (`deal.F`). + +The finding names the field, the label and the value to write in its place. A CEL value envelope, a variable or a template is not judged; neither is a field whose options come from a shared picklist, nor a variable that anything else in the flow also binds. A filter that is meant to find rows still holding a label (a clean-up after the options changed) writes the operand as a CEL value envelope, `{ dialect: 'cel', source: "'Closed Lost'" }`. The runtime publish gate runs the same rule, so an active flow write carrying one of these is refused there too. diff --git a/packages/lint/src/validate-flow-node-writes.ts b/packages/lint/src/validate-flow-node-writes.ts index 0c3bfc6ca44..00797b8ae0d 100644 --- a/packages/lint/src/validate-flow-node-writes.ts +++ b/packages/lint/src/validate-flow-node-writes.ts @@ -154,6 +154,11 @@ export const FLOW_NODE_WRITE_UNPROVISIONED_ANCHOR = 'flow-node-write-unprovision * run. `error`, at the certainty the unknown-field verdict gates on: a * literal value against the literal options of a literal object. The options * read is `flow-select-options.ts`'s, shared with the start-condition rule. + * + * [#36964] A label in the same node's `filter` is not this id's: a filter + * operand is refused by nothing, it matches no row and the step succeeds on + * nothing. That is `flow-condition-option-label` (`validate-flow-trigger-readiness.ts`), + * the id for a label compared where the row holds the value. */ export const FLOW_NODE_WRITE_UNKNOWN_OPTION = 'flow-node-write-unknown-option'; From 1dfcca5c006976eebbaf4818589e38fc52efc071 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 09:36:41 +0000 Subject: [PATCH 4/5] fix(lint): a rebound record / previous root is not read as the trigger row; pin regions, operators and shadows Claude-Session: https://claude.ai/code/session_01Utp6CY2uhJ1AYNPw5TUSVS Co-authored-by: Claude --- .../flow-publish-checks-second-batch.test.ts | 126 ++++++++++++++++++ .../src/validate-flow-trigger-readiness.ts | 11 +- 2 files changed, 134 insertions(+), 3 deletions(-) diff --git a/packages/lint/src/flow-publish-checks-second-batch.test.ts b/packages/lint/src/flow-publish-checks-second-batch.test.ts index a7350dea1ba..eb201d9bf03 100644 --- a/packages/lint/src/flow-publish-checks-second-batch.test.ts +++ b/packages/lint/src/flow-publish-checks-second-batch.test.ts @@ -353,6 +353,132 @@ describe('flow-condition-option-label past the start condition (#36964)', () => expect(bare({ variables: [{ name: 'stage', type: 'text' }] })).not.toContain(FLOW_CONDITION_OPTION_LABEL); }); + it('reads $not, $nin and $and, and says which way an excluding operand cuts', () => { + const run = (filter: unknown) => labelHits(validateFlowTriggerReadiness(manual([crud('get_record', filter)]))); + // `$not` over `$ne` excludes twice over: the filter still matches no record. + const notNe = run({ $not: { stage: { $ne: 'Closed Lost' } } }); + expect(notNe.map((f) => f.path)).toEqual(['flows[0].nodes[1].config.filter.$not.stage.$ne']); + expect(notNe[0].message).toContain('matches no record'); + const nin = run({ stage: { $nin: ['open', 'Closed Lost'] } }); + expect(nin.map((f) => f.path)).toEqual(['flows[0].nodes[1].config.filter.stage.$nin[1]']); + expect(nin[0].message).toContain('excludes no record'); + const and = run({ $and: [{ name: 'x' }, { stage: 'Closed Lost' }] }); + expect(and.map((f) => f.path)).toEqual(['flows[0].nodes[1].config.filter.$and[1].stage']); + expect(and[0].message).toContain('matches no record'); + }); + + it('reads an edge inside a loop body and a decision branch inside a parallel branch', () => { + const inLoop = branching(undefined); + inLoop.flows[0].nodes.push({ + id: 'each', + type: 'loop', + label: 'Each', + config: { + collection: { dialect: 'cel', source: '[1]' }, + iteratorVariable: 'i', + body: { + nodes: [ + { id: 'a', type: 'assignment', label: 'A', config: { assignments: { n: 1 } } }, + { id: 'b', type: 'assignment', label: 'B', config: { assignments: { m: 1 } } }, + ], + edges: [{ id: 'inner', source: 'a', target: 'b', condition: "deal.stage == 'Closed Lost'" }], + }, + }, + }); + expect(labelHits(validateFlowTriggerReadiness(inLoop)).map((f) => f.path)).toEqual([ + 'flows[0].nodes[5].config.body.edges[0].condition', + ]); + + const inBranch = branching(undefined); + inBranch.flows[0].nodes.push({ + id: 'fan', + type: 'parallel', + label: 'Fan', + config: { + branches: [ + { + name: 'left', + nodes: [{ id: 'pick', type: 'decision', label: 'Pick', config: { conditions: [{ label: 'lost', expression: "deal.stage == 'Closed Lost'" }] } }], + edges: [], + }, + ], + }, + }); + expect(labelHits(validateFlowTriggerReadiness(inBranch)).map((f) => f.path)).toEqual([ + 'flows[0].nodes[5].config.branches[0].nodes[0].config.conditions[0].expression', + ]); + }); + + it("reads a time-relative flow's trigger record, and previous.F on a record-change flow", () => { + const sweep = stack(flow('remind', { objectName: 'deal', timeRelative: SWEEP }, [{ id: 'tell', type: 'end', label: 'Tell', config: {} }])); + sweep.flows[0].edges[0].condition = "record.stage == 'Closed Lost'"; + expect(labelHits(validateFlowTriggerReadiness(sweep)).map((f) => f.path)).toEqual(['flows[0].edges[0].condition']); + + const onUpdate = stack( + flow('lost', { triggerType: 'record-after-update', objectName: 'deal' }, [{ id: 'tell', type: 'end', label: 'Tell', config: {} }]), + ); + onUpdate.flows[0].edges[0].condition = "previous.stage != 'Closed Lost'"; + expect(labelHits(validateFlowTriggerReadiness(onUpdate)).map((f) => f.path)).toEqual(['flows[0].edges[0].condition']); + }); + + /** A second object whose `stage` stores the words the deal's `stage` uses as labels. */ + const LEAD = { + name: 'lead', + label: 'Lead', + fields: { stage: { type: 'select', label: 'Stage', options: ['Open', 'Closed Lost'] } }, + }; + + it('is silent when the flow rebinds `record` to another row (get_record, loop iterator, assignment)', () => { + const rebinding = (binder: AnyRec) => { + const f = flow('lost', { triggerType: 'record-after-update', objectName: 'deal' }, [ + binder, + { id: 'tell', type: 'end', label: 'Tell', config: {} }, + ]); + f.edges[1].condition = "record.stage == 'Closed Lost'"; + return { objects: [DEAL, LEAD], flows: [f] }; + }; + const binders: AnyRec[] = [ + { id: 'load', type: 'get_record', label: 'Load', config: { objectName: 'lead', filter: { id: 'l1' }, outputVariable: 'record' } }, + { id: 'set', type: 'assignment', label: 'Set', config: { assignments: { record: { dialect: 'cel', source: 'lead_row' } } } }, + { id: 'each', type: 'loop', label: 'Each', config: { collection: { dialect: 'cel', source: 'leads' }, iteratorVariable: 'record', body: { nodes: [], edges: [] } } }, + ]; + for (const binder of binders) { + expect(rulesOf(validateFlowTriggerReadiness(rebinding(binder))), binder.type).not.toContain(FLOW_CONDITION_OPTION_LABEL); + } + // Control: the same flow with a binder that does not touch `record` is reported. + const control = rebinding({ id: 'set', type: 'assignment', label: 'Set', config: { assignments: { other: 1 } } }); + expect(rulesOf(validateFlowTriggerReadiness(control))).toContain(FLOW_CONDITION_OPTION_LABEL); + }); + + it('drops a variable two get_record steps bind to different objects, and one a node id or a screen field shadows', () => { + const twoObjects = branching("deal.stage == 'Closed Lost'"); + twoObjects.objects = [DEAL, LEAD]; + twoObjects.flows[0].nodes.push({ id: 'load2', type: 'get_record', label: 'Load 2', config: { objectName: 'lead', filter: { id: 'l1' }, outputVariable: 'deal' } }); + expect(rulesOf(validateFlowTriggerReadiness(twoObjects))).not.toContain(FLOW_CONDITION_OPTION_LABEL); + + const nodeId = branching("deal.stage == 'Closed Lost'"); + nodeId.flows[0].nodes.push({ id: 'deal', type: 'end', label: 'Deal end', config: {} }); + expect(rulesOf(validateFlowTriggerReadiness(nodeId))).not.toContain(FLOW_CONDITION_OPTION_LABEL); + + const screenField = branching("deal.stage == 'Closed Lost'"); + screenField.flows[0].nodes.push({ id: 'ask', type: 'screen', label: 'Ask', config: { fields: [{ name: 'deal', label: 'Deal', type: 'text' }] } }); + expect(rulesOf(validateFlowTriggerReadiness(screenField))).not.toContain(FLOW_CONDITION_OPTION_LABEL); + + // The bare read of the trigger field, shadowed by a node id and by a screen field. + const bare = (node: AnyRec) => { + const s = stack( + flow('lost', { triggerType: 'record-after-update', objectName: 'deal' }, [node, { id: 'tell', type: 'end', label: 'Tell', config: {} }]), + ); + s.flows[0].edges[1].condition = "stage == 'Closed Lost'"; + return rulesOf(validateFlowTriggerReadiness(s)); + }; + expect(bare({ id: 'stage', type: 'assignment', label: 'S', config: { assignments: { n: 1 } } })).not.toContain(FLOW_CONDITION_OPTION_LABEL); + expect(bare({ id: 'ask', type: 'screen', label: 'Ask', config: { fields: [{ name: 'stage', label: 'Stage', type: 'text' }] } })).not.toContain( + FLOW_CONDITION_OPTION_LABEL, + ); + expect(bare({ id: 'other', type: 'assignment', label: 'O', config: { assignments: { n: 1 } } })).toContain(FLOW_CONDITION_OPTION_LABEL); + }); + it('os validate reports it, and the runtime publish gate refuses the flow write', () => { const s = branching("deal.stage == 'Closed Lost'"); expect(rulesOf(runAuthoringRules('validate', { normalized: s } as never))).toContain(FLOW_CONDITION_OPTION_LABEL); diff --git a/packages/lint/src/validate-flow-trigger-readiness.ts b/packages/lint/src/validate-flow-trigger-readiness.ts index a8aad609456..1fced8487bd 100644 --- a/packages/lint/src/validate-flow-trigger-readiness.ts +++ b/packages/lint/src/validate-flow-trigger-readiness.ts @@ -750,7 +750,7 @@ function graphHolder(flow: AnyRec, path: readonly (string | number)[]): AnyRec | } /** - * [#36964] `flow-condition-option-label` past the start condition (1-iii): + * [#36964] `flow-condition-option-label` past the start condition (1-iv): * * - a query FILTER's operand — every node in {@link FILTER_NODE_TYPES}, at any * region depth, against its own literal `objectName`, and a time-relative @@ -762,7 +762,10 @@ function graphHolder(flow: AnyRec, path: readonly (string | number)[]): AnyRec | * row a single-row `get_record` step bound to its `outputVariable` * (`deal.F`). A variable bound by anything else as well — another step, a * declared variable, a node id, a screen field — is not judged: which value - * it holds when the condition runs is the run's. + * it holds when the condition runs is the run's. Likewise a `record` / + * `previous` root the flow itself binds (a step's `outputVariable`, a loop's + * `iteratorVariable`, an assignment target): after that binding `record.F` + * is another row's field, so the root is not read as the trigger record. */ function optionLabelsBeyondStart( flow: AnyRec, @@ -856,7 +859,9 @@ function optionLabelsBeyondStart( const readers: Array<{ objectName: string; reads: FieldReads }> = []; if (triggerObject) { const shadowed = new Set([...collectFlowVariableNames(flow, graphs), ...screenNames]); - readers.push({ objectName: triggerObject, reads: { ...TRIGGER_RECORD_READS, shadowed } }); + // A trigger root the flow rebinds names another row from then on: drop it. + const roots = TRIGGER_RECORD_READS.roots.filter((root) => !shadowed.has(root)); + readers.push({ objectName: triggerObject, reads: { roots, bare: TRIGGER_RECORD_READS.bare, shadowed } }); } for (const [variable, objectName] of rowVariables) { if (objectName === null || boundElsewhere.has(variable) || screenNames.has(variable)) continue; From 7093e465ece700be57375a8a77bb37deec69cb5c Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 09:37:21 +0000 Subject: [PATCH 5/5] fix(lint)!: declare the narrowing; the ADR-0087 entry names the new positions Claude-Session: https://claude.ai/code/session_01Utp6CY2uhJ1AYNPw5TUSVS Co-authored-by: Claude --- .changeset/36964-flow-option-label-filters.md | 31 +++++++++++++------ ...-refuses-flows-that-save-and-do-not-run.ts | 6 ++-- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/.changeset/36964-flow-option-label-filters.md b/.changeset/36964-flow-option-label-filters.md index 5e75b68989d..cb3433bb64b 100644 --- a/.changeset/36964-flow-option-label-filters.md +++ b/.changeset/36964-flow-option-label-filters.md @@ -1,17 +1,30 @@ --- -'@objectstack/lint': patch +'@objectstack/lint': minor +'@objectstack/spec': patch --- -fix(lint): `os validate` refuses an option label in a flow's query filter, edge condition or decision branch +fix(lint)!: `os validate` and the publish gate refuse an option label in a flow's query filter, edge condition or decision branch -Clause-②: no -Metadata-protocol: none +Clause-②: no (narrowing) +Metadata-protocol: narrowed +Skills-docs: follow-up #37504 -A select field stores the option's value, never its label, and a flow hands its filters and conditions to the data engine and the expression engine as written: nothing resolves a label to its value there. So `filter: { stage: 'Closed Lost' }` on a `get_record`, `update_record` or `delete_record` step matched no row, and the step reported success having read, updated or deleted nothing; an edge condition or `decision` branch `deal.stage == 'Closed Lost'` was never taken. `os validate` said nothing, because `flow-condition-option-label` read only the start condition. + -`flow-condition-option-label` (`error`, as on the start condition) now also reads: +**BREAKING** accept-set narrowing, shipped as `minor`: a flow carrying one of the shapes below was accepted before and is refused now, with the fix named in the finding. The schema is unchanged and stored flows are not rewritten or refused at boot; the refusal comes at the next publish of the flow, and from `os validate` / `lint` / `compile` / `build`. No export is added or removed. -- each operand of a `get_record` / `update_record` / `delete_record` `filter`, and of a time-relative sweep's `timeRelative.filter`: a field's implicit equality, its `$eq` / `$ne` comparand and each member of its `$in` / `$nin` list, at the top level or under `$and` / `$or` / `$not`, at any region depth; -- every edge condition and every `decision` node's `conditions[].expression`, where it compares a select field of the trigger record (`record.F`, `previous.F`, a bare `F` no flow variable shadows) on a record-change or time-relative flow, or of the row a single-row `get_record` step bound to its `outputVariable` (`deal.F`). +A select field stores the option's value, never its label, and a flow hands its filters and conditions to the data engine and the expression engine as written: nothing resolves a label to its value there. So `filter: { stage: 'Closed Lost' }` on a `get_record`, `update_record` or `delete_record` step matched no row, and the step reported success having read, updated or deleted nothing; an edge condition or `decision` branch `deal.stage == 'Closed Lost'` was never taken. `flow-condition-option-label` read only the start condition, so nothing said so. -The finding names the field, the label and the value to write in its place. A CEL value envelope, a variable or a template is not judged; neither is a field whose options come from a shared picklist, nor a variable that anything else in the flow also binds. A filter that is meant to find rows still holding a label (a clean-up after the options changed) writes the operand as a CEL value envelope, `{ dialect: 'cel', source: "'Closed Lost'" }`. The runtime publish gate runs the same rule, so an active flow write carrying one of these is refused there too. +- **The refusal.** `flow-condition-option-label` (`error`, as on the start condition) now also reads: + - each operand of a `get_record` / `update_record` / `delete_record` `filter`, and of a time-relative sweep's `timeRelative.filter`: a field's implicit equality, its `$eq` / `$ne` comparand and each member of its `$in` / `$nin` list, at the top level or under `$and` / `$or` / `$not`, at any region depth; + - every edge condition and every `decision` node's `conditions[].expression`, at any region depth, where it compares a select field of the trigger record (`record.F`, `previous.F`, or a bare `F`) on a record-change or time-relative flow, or of the row a single-row `get_record` step (`limit` absent or 1) bound to its `outputVariable` (`deal.F`). +- **Not judged.** A CEL value envelope, a variable or a template operand or comparand; a field whose options come from a shared picklist; a variable that anything else in the flow also binds (another step, a declared variable, a node id, a screen field); a `record` / `previous` root the flow rebinds itself; a bare `F` that such a binding shadows. A `readonly` select is still judged, as the start condition already judges it. +- **Escape, filters only.** A filter that is meant to find rows still holding a label (a clean-up after the options changed) writes the operand as a CEL value envelope, `{ dialect: 'cel', source: "'Closed Lost'" }`, which is evaluated before the query and not judged. An edge condition or a `decision` branch has no such escape: compare the value. +- **What carries it.** The ADR-0087 entry `publish-refuses-flows-that-save-and-do-not-run` now names the edge condition, the `decision` branch and the filter operand beside the start condition. + +FROM → TO: + +- `filter: { stage: 'Closed Lost' }` → `filter: { stage: 'closed_lost' }` +- `deal.stage == 'Closed Lost'` (an edge condition or a `decision` branch) → `deal.stage == 'closed_lost'` + +One-line fix: write the option's value where the label is, as the finding names it. diff --git a/packages/spec/src/migrations/entries/semantic/18.publish-refuses-flows-that-save-and-do-not-run.ts b/packages/spec/src/migrations/entries/semantic/18.publish-refuses-flows-that-save-and-do-not-run.ts index 17c5c57eab6..356e9b40829 100644 --- a/packages/spec/src/migrations/entries/semantic/18.publish-refuses-flows-that-save-and-do-not-run.ts +++ b/packages/spec/src/migrations/entries/semantic/18.publish-refuses-flows-that-save-and-do-not-run.ts @@ -12,8 +12,10 @@ export const entry: SemanticMigration = { id: 'publish-refuses-flows-that-save-and-do-not-run', surface: 'Seven author-time flow errors, run by the runtime publish gate and by `os validate` / `lint` / `compile` / `build`: ' - + 'a record-triggered flow with no `objectName` (`flow-trigger-object-missing`); a start condition that compares a ' - + 'select field with one of its option labels where the row holds the option value (`flow-condition-option-label`); ' + + 'a record-triggered flow with no `objectName` (`flow-trigger-object-missing`); a start condition, an edge ' + + 'condition or a `decision` branch that compares a select field with one of its option labels, or a ' + + '`get_record` / `update_record` / `delete_record` or `timeRelative` `filter` operand that is one, where the row ' + + 'holds the option value (`flow-condition-option-label`); ' + 'a `timeRelative` block under a record `triggerType`, which wins (`flow-time-relative-shadowed`); `filter` or ' + '`maxRecords` beside `timeRelative` instead of inside it (`flow-time-relative-key-misplaced`); a `timeRelative.dateField` ' + 'that is not a `date` / `datetime` field of the object (`flow-time-relative-date-field-invalid`); a create / update '