From 5a29954a2b5944bfddd387305c37383c4a0e79f4 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 04:37:54 +0000 Subject: [PATCH 1/2] fix(formula): list-equality prescribes a rewrite that works where it is read; flattened sites judged only on a proven row The `list-equality` refusal now spells its membership rewrite for the site and parenthesises it whole: - a `record.` / `previous.` read evaluated as CEL: has()-guarded `in`, which answers on a sparse row and a null `previous` instead of faulting; - a bare name at a flow condition: `!= null`-guarded `in`; - a sharing rule condition (new `ExprSchemaHint.filterCompiled`, filled by the publish lint): `.contains(...)`, which lowers to `$contains`; the CEL `in` form does not lower there (`in` needs a field on its left). At a flattened site the verdict needs `faultOutcome: 'run-fails'` (a record-triggered flow or a time-relative sweep of the typed object): an API, scheduled or trigger-less flow holds what its entrance handed it, where `labels == 'frontend'` can be correct code. registerFlow's advisory pass now declares that outcome on the same flows os validate does. Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01FEkQ5miLqNucRZevceHwNh --- .../36167-list-equality-site-rewrites.md | 35 ++++ .../src/expression-refusal-codes.test.ts | 57 ++++++- packages/formula/src/expression-refusal.ts | 11 +- .../src/validate-list-equality-36167.test.ts | 156 +++++++++++++++++- packages/formula/src/validate.ts | 124 +++++++++++--- ...te-expressions.list-equality-36167.test.ts | 90 +++++++++- packages/lint/src/validate-expressions.ts | 13 +- ...ate-expression.list-equality-36167.test.ts | 18 ++ .../src/flow-registration-checks.ts | 21 ++- .../src/list-equality-advisory-36167.test.ts | 44 ++++- .../semantic/18.cel-list-equality-refused.ts | 25 ++- 11 files changed, 530 insertions(+), 64 deletions(-) create mode 100644 .changeset/36167-list-equality-site-rewrites.md diff --git a/.changeset/36167-list-equality-site-rewrites.md b/.changeset/36167-list-equality-site-rewrites.md new file mode 100644 index 00000000000..551d9e4dadd --- /dev/null +++ b/.changeset/36167-list-equality-site-rewrites.md @@ -0,0 +1,35 @@ +--- +'@objectstack/formula': minor +'@objectstack/lint': minor +'@objectstack/service-automation': minor +'@objectstack/spec': minor +--- + +fix(formula): the `list-equality` refusal prescribes a rewrite that works where it is read, and a flow condition is judged only where the run binds a row of the typed object + +Clause-②: yes (widening) +Metadata-protocol: added +Skills-docs: follow-up #36217 + +The two widenings. A flow condition in a flow that no record write or sweep starts (an API, scheduled or trigger-less flow) is no longer refused as `list-equality`, bare or `record.`: that run holds what its entrance handed it, so `labels == 'frontend'` can be correct code there. And `ExprSchemaHint` gains the optional key `filterCompiled`, which tells the validator that the site's source compiles to a query filter. + +The rewrite the refusal prescribes now depends on the site, and is parenthesised whole so it can stand where the comparison stood (`A && (…)`): + +- **A `record.` / `previous.` read evaluated as CEL** (a validation rule, a field rule, a formula, an action's `visible` / `disabled` / `pressed`, a hook condition): + - FROM `record.labels != null && "frontend" in record.labels` + - TO `(has(record.labels) && record.labels != null && "frontend" in record.labels)` + - `has()` answers on a sparse row or a null `previous`, where the old form faulted. + - For `!=` the TO form is `(!has(record.labels) || record.labels == null || !("frontend" in record.labels))`. The old `!=` form, with no parentheses, split under a leading `&&`. +- **A bare name at a flow condition:** + - FROM `labels == null || !("frontend" in labels)` + - TO `(labels == null || !("frontend" in labels))` + - For `==` the TO form is `(labels != null && "frontend" in labels)`. +- **A sharing rule `condition`**, which compiles to a query filter: + - FROM `record.labels != null && "frontend" in record.labels`, which does not lower (`in` needs a field on its left), so the rule was dropped as `sharing-rule-unlowerable-condition`. + - TO `(record.labels != null && record.labels.contains("frontend"))`, which lowers to a membership filter (`$contains`). + - For `!=` the TO form is `(record.labels == null || !record.labels.contains("frontend"))`. + - A number or boolean operand is passed as its text (`contains("3")`). + +One-line fix: write the rewrite the refusal names. + +`registerFlow`'s advisory pass now hands the validator `faultOutcome: 'run-fails'` on a record-triggered flow and on a time-relative sweep of the typed object, the same flows `os validate` declares it on. On those flows its logged type-mismatch lines now use the wording `os validate` prints. It still only logs and never throws. diff --git a/packages/formula/src/expression-refusal-codes.test.ts b/packages/formula/src/expression-refusal-codes.test.ts index 715468e4bf8..a89f611ebae 100644 --- a/packages/formula/src/expression-refusal-codes.test.ts +++ b/packages/formula/src/expression-refusal-codes.test.ts @@ -854,12 +854,13 @@ const PINS: { readonly [C in ExpressionRefusalCode]: readonly [Pin, ...Pin operator: '==', operand: '"frontend"', answer: 'false', - rewrite: 'record.labels != null && "frontend" in record.labels', + rewrite: '(has(record.labels) && record.labels != null && "frontend" in record.labels)', }, message: 'list compared with a scalar — `record.labels` holds a list (a multi-value field), and `==` compares the whole ' + 'list with `"frontend"`, so the expression answers `false` on every row whatever the list holds: the condition ' + - 'never changes. Test membership with `in`: write `record.labels != null && "frontend" in record.labels`. ' + + 'never changes. Test membership with `in`: write ' + + '`(has(record.labels) && record.labels != null && "frontend" in record.labels)`. ' + 'To test whether the list is set, compare it with `null`.', }, { @@ -875,14 +876,62 @@ const PINS: { readonly [C in ExpressionRefusalCode]: readonly [Pin, ...Pin operator: '!=', operand: '"u1"', answer: 'true', - rewrite: 'previous.owners == null || !("u1" in previous.owners)', + rewrite: '(!has(previous.owners) || previous.owners == null || !("u1" in previous.owners))', }, message: 'list compared with a scalar — `previous.owners` holds a list (a multi-value field), and `!=` compares the whole ' + 'list with `"u1"`, so the expression answers `true` on every row whatever the list holds: the condition ' + - 'never changes. Test membership with `in`: write `previous.owners == null || !("u1" in previous.owners)`. ' + + 'never changes. Test membership with `in`: write ' + + '`(!has(previous.owners) || previous.owners == null || !("u1" in previous.owners))`. ' + 'To test whether the list is set, compare it with `null`.', }, + { + // A bare field name at a flattened site proven to bind the typed row. + produce: () => + onlyError('predicate', "owners != 'u1'", { + scope: 'flattened', + faultOutcome: 'run-fails', + fields: ['owners'], + fieldTypes: { owners: 'user' }, + multiValueFields: ['owners'], + }), + params: { + reference: 'owners', + operator: '!=', + operand: '"u1"', + answer: 'true', + rewrite: '(owners == null || !("u1" in owners))', + }, + message: + 'list compared with a scalar — `owners` holds a list (a multi-value field), and `!=` compares the whole ' + + 'list with `"u1"`, so the expression answers `true` on every row whatever the list holds: the condition ' + + 'never changes. Test membership with `in`: write `(owners == null || !("u1" in owners))`. ' + + 'To test whether the list is set, compare it with `null`.', + }, + { + // A source compiled to a query filter (a sharing rule's condition). + produce: () => + onlyError('predicate', "record.labels == 'frontend'", { + scope: 'record', + filterCompiled: true, + fields: ['labels'], + fieldTypes: { labels: 'multiselect' }, + }), + params: { + reference: 'record.labels', + operator: '==', + operand: '"frontend"', + answer: 'false', + rewrite: '(record.labels != null && record.labels.contains("frontend"))', + }, + message: + 'list compared with a scalar — `record.labels` holds a list (a multi-value field), and `==` compares the whole ' + + 'list with `"frontend"`: as CEL it answers `false` on every row, and this condition compiles to a query ' + + 'filter, where `==` against a list column is refused, so it never tests membership. Test membership with ' + + '`contains`, which compiles to a membership filter: write ' + + '`(record.labels != null && record.labels.contains("frontend"))`. To test whether the list is set, compare ' + + 'it with `null`.', + }, ], 'empty-expression': [ { diff --git a/packages/formula/src/expression-refusal.ts b/packages/formula/src/expression-refusal.ts index c9dc67400ff..e303e141c39 100644 --- a/packages/formula/src/expression-refusal.ts +++ b/packages/formula/src/expression-refusal.ts @@ -329,9 +329,14 @@ export interface ExpressionRefusalParams { * or a `fieldTypes` type that is inherently multi) and a non-null scalar * literal: CEL compares the whole list with the scalar, so the expression * answers the same constant on every row. `reference` is the read as - * `.`, `operand` the literal as CEL prints it, `answer` the - * constant (`false` for `==`, `true` for `!=`), and `rewrite` the - * null-guarded membership test that replaces the comparison. + * `.` (`record['f']` renders `record.f`), or the bare + * `` at a flattened (flow) site, `operand` the literal as CEL prints + * it, `answer` the constant CEL answers (`false` for `==`, `true` for + * `!=`), and `rewrite` the guarded membership test that replaces the + * comparison, parenthesised whole and spelled for the site: `has()`-guarded + * `in` for a `.` read, `!= null`-guarded `in` for a bare name, + * `.contains(…)` where the source compiles to a query filter + * (`ExprSchemaHint.filterCompiled`). */ 'list-equality': { readonly reference: string; diff --git a/packages/formula/src/validate-list-equality-36167.test.ts b/packages/formula/src/validate-list-equality-36167.test.ts index 3f1fdd0aeed..e09f90a3cf0 100644 --- a/packages/formula/src/validate-list-equality-36167.test.ts +++ b/packages/formula/src/validate-list-equality-36167.test.ts @@ -18,6 +18,8 @@ import { describe, it, expect } from 'vitest'; import { celEngine } from './cel-engine'; +import { compileCelToFilter } from './cel-to-filter'; +import { matchesFilterCondition } from './matches-filter'; import { validateExpression, type ExprSchemaHint } from './validate'; const MULTI_TYPES = ['multiselect', 'checkboxes', 'tags'] as const; @@ -31,6 +33,9 @@ function hintFor(type: string, multi = false, scope: 'record' | 'flattened' = 'r fieldTypes: { f: type, name: 'text' }, ...(multi ? { multiValueFields: ['f'] } : {}), scope, + // A flattened site is judged only where the run is proven to bind a row + // of the typed object; the unproven case is pinned on its own below. + ...(scope === 'flattened' ? { faultOutcome: 'run-fails' as const } : {}), }; } @@ -58,7 +63,7 @@ describe('the premise — on the evaluator, a list compared with a scalar is a c expect(run("record.labels == 'frontend'", labels)).toEqual({ ok: true, value: false }); expect(run("record.labels != 'frontend'", labels)).toEqual({ ok: true, value: true }); }); - it('CONTROL — the prescribed membership test answers per row', () => { + it('CONTROL — a membership test answers per row', () => { const src = "record.labels != null && 'frontend' in record.labels"; expect(run(src, ['frontend', 'qa'])).toEqual({ ok: true, value: true }); expect(run(src, ['qa'])).toEqual({ ok: true, value: false }); @@ -80,7 +85,7 @@ describe('list-equality — refused on an inherently multi-value type', () => { expect(e.code === 'list-equality' && e.params.answer).toBe(op === '==' ? 'false' : 'true'); expect(e.message).toContain(`\`${root}.f\``); expect(e.message).toContain(' in '); - expect(e.message).toContain(op === '==' ? `in ${root}.f\`` : `!(`); + expect(e.message).toContain(op === '==' ? `in ${root}.f)\`` : `!(`); }); } } @@ -220,6 +225,7 @@ describe('list-equality — a name a comprehension macro binds is an item of the fieldTypes: { items: 'tags', labels: 'multiselect', owners: 'user' }, multiValueFields: ['owners'], scope, + ...(scope === 'flattened' ? { faultOutcome: 'run-fails' as const } : {}), }); const refusedReferences = (source: string, scope: 'record' | 'flattened') => refusalsOf(source, hint(scope)).filter((e) => e.code === 'list-equality').map((e) => e.params.reference); @@ -263,3 +269,149 @@ describe('list-equality — a name a comprehension macro binds is an item of the expect(refusedReferences("record.items.exists(labels, labels == 'a')", 'record')).toEqual([]); }); }); + +describe('list-equality — the prescribed rewrite tests membership where it is read', () => { + /** The one `list-equality` refusal of `source` under `hint`, and its prescribed rewrite. */ + const rewriteOf = (source: string, hint: ExprSchemaHint): string => { + const errors = refusalsOf(source, hint).filter((e) => e.code === 'list-equality'); + expect(errors).toHaveLength(1); + const [e] = errors; + if (e.code !== 'list-equality') throw new Error('unreachable'); + expect(e.message).toContain(`write \`${e.params.rewrite}\``); + return e.params.rewrite; + }; + /** Rows a list field can hold, and whether `'a'` is a member. */ + const ROWS: readonly (readonly [string, Record, boolean])[] = [ + ['[a, b]', { f: ['a', 'b'], name: 'x' }, true], + ['[b]', { f: ['b'], name: 'x' }, false], + ['[]', { f: [], name: 'x' }, false], + ['null', { f: null, name: 'x' }, false], + ['absent', { name: 'x' }, false], + ]; + const evaluate = (source: string, vars: Record) => + celEngine.evaluate({ dialect: 'cel', source }, vars); + + describe('a `record.` / `previous.` read evaluated as CEL', () => { + it('pins the text: has()-guarded and parenthesised whole', () => { + expect(rewriteOf("record.f == 'a'", hintFor('tags'))).toBe( + '(has(record.f) && record.f != null && "a" in record.f)', + ); + expect(rewriteOf("record.f != 'a'", hintFor('tags'))).toBe( + '(!has(record.f) || record.f == null || !("a" in record.f))', + ); + }); + for (const op of ['==', '!='] as const) { + for (const [label, row, member] of ROWS) { + it(`\`${op}\` on row ${label}: answers ${op === '==' ? member : !member}, and stands inside \`&&\` / \`||\``, () => { + const rewrite = rewriteOf(`record.f ${op} 'a'`, hintFor('tags')); + const want = op === '==' ? member : !member; + expect(evaluate(rewrite, { record: row })).toEqual({ ok: true, value: want }); + // Parenthesised whole: a conjunct before it does not split it. + expect(evaluate(`record.name == 'x' && ${rewrite}`, { record: row })).toEqual({ ok: true, value: want }); + expect(evaluate(`record.name == 'y' && ${rewrite}`, { record: row })).toEqual({ ok: true, value: false }); + expect(evaluate(`false || ${rewrite}`, { record: row })).toEqual({ ok: true, value: want }); + }); + } + } + it('on `previous`, which is null on a create, answers without faulting', () => { + expect(evaluate(rewriteOf("previous.f == 'a'", hintFor('tags')), { previous: null })).toEqual({ ok: true, value: false }); + expect(evaluate(rewriteOf("previous.f != 'a'", hintFor('tags')), { previous: null })).toEqual({ ok: true, value: true }); + }); + it('the rewrite itself is accepted at the site', () => { + for (const op of ['==', '!='] as const) { + const rewrite = rewriteOf(`record.f ${op} 'a'`, hintFor('tags')); + expect(validateExpression('predicate', rewrite, hintFor('tags')).ok).toBe(true); + } + }); + }); + + describe('a bare name at a flattened site proven to bind the typed row', () => { + const flat = hintFor('tags', false, 'flattened'); + it('pins the text: null-guarded and parenthesised whole', () => { + expect(rewriteOf("f == 'a'", flat)).toBe('(f != null && "a" in f)'); + expect(rewriteOf("f != 'a'", flat)).toBe('(f == null || !("a" in f))'); + }); + // The run binds every declared field (null when empty), so no row lacks `f`. + for (const op of ['==', '!='] as const) { + for (const [label, row, member] of ROWS.filter(([label]) => label !== 'absent')) { + it(`\`${op}\` on row ${label}: answers ${op === '==' ? member : !member}, inside \`&&\` too`, () => { + const rewrite = rewriteOf(`f ${op} 'a'`, flat); + const want = op === '==' ? member : !member; + // `extra` binds the row's fields as top-level names, as a flow run does. + expect(evaluate(rewrite, { extra: row })).toEqual({ ok: true, value: want }); + expect(evaluate(`name == 'x' && ${rewrite}`, { extra: row })).toEqual({ ok: true, value: want }); + expect(evaluate(`name == 'y' && ${rewrite}`, { extra: row })).toEqual({ ok: true, value: false }); + }); + } + } + it('the rewrite itself is accepted at the site', () => { + for (const op of ['==', '!='] as const) { + expect(validateExpression('predicate', rewriteOf(`f ${op} 'a'`, flat), flat).ok).toBe(true); + } + }); + }); + + describe('a source compiled to a query filter (`filterCompiled`: a sharing rule condition)', () => { + const filtered: ExprSchemaHint = { ...hintFor('tags'), filterCompiled: true }; + const FIELDS = { f: { type: 'tags' }, name: { type: 'text' } } as const; + /** Lower `source` as the sharing-rule path does, then match it against `row`. */ + const matches = (source: string, row: Record): boolean => { + const lowered = compileCelToFilter(source); + if (!lowered.ok) throw new Error(`not lowered: ${lowered.reason} — ${lowered.detail}`); + return matchesFilterCondition(row, lowered.filter, { fields: FIELDS }); + }; + it('pins the text: `contains`, null-guarded, parenthesised whole', () => { + expect(rewriteOf("record.f == 'a'", filtered)).toBe('(record.f != null && record.f.contains("a"))'); + expect(rewriteOf("record.f != 'a'", filtered)).toBe('(record.f == null || !record.f.contains("a"))'); + }); + it('a number literal is passed as its text (`$contains` compares text)', () => { + expect(rewriteOf('record.f == 3', filtered)).toBe('(record.f != null && record.f.contains("3"))'); + }); + it('the CEL `in` spelling does not lower: the reason the site gets its own', () => { + const lowered = compileCelToFilter('record.f != null && "a" in record.f'); + expect(lowered.ok).toBe(false); + }); + for (const op of ['==', '!='] as const) { + for (const [label, row, member] of ROWS) { + it(`\`${op}\` on row ${label}: the lowered filter matches ${op === '==' ? member : !member}, inside \`&&\` too`, () => { + const rewrite = rewriteOf(`record.f ${op} 'a'`, filtered); + const want = op === '==' ? member : !member; + expect(matches(rewrite, row)).toBe(want); + expect(matches(`record.name == 'x' && ${rewrite}`, row)).toBe(want); + expect(matches(`record.name == 'y' && ${rewrite}`, row)).toBe(false); + }); + } + } + it('the rewrite itself is accepted at the site', () => { + for (const op of ['==', '!='] as const) { + expect(validateExpression('predicate', rewriteOf(`record.f ${op} 'a'`, filtered), filtered).ok).toBe(true); + } + }); + it('CONTROL — without `filterCompiled` the same comparison gets the CEL spelling', () => { + expect(rewriteOf("record.f == 'a'", hintFor('tags'))).toContain(' in record.f'); + }); + }); +}); + +describe('list-equality — a flattened site with no proven row binding gets no verdict', () => { + // An API, scheduled or trigger-less flow runs on what its entrance handed + // it: `record` / the bare names are not proven to be the typed object's + // fields, so `labels == 'frontend'` can be correct code there. + const unproven: ExprSchemaHint = { ...hintFor('tags', false, 'flattened') }; + delete (unproven as { faultOutcome?: unknown }).faultOutcome; + for (const source of ["f == 'a'", "record.f == 'a'", "'a' != f", "previous.f != 'a'"]) { + it(`accepts \`${source}\` (no list-equality)`, () => { + expect(refusalsOf(source, unproven).filter((e) => e.code === 'list-equality')).toEqual([]); + }); + } + it(`a faultOutcome other than 'run-fails' is no proof either`, () => { + for (const faultOutcome of ['fail-closed', 'fail-open'] as const) { + expect(refusalsOf("f == 'a'", { ...unproven, faultOutcome }).filter((e) => e.code === 'list-equality')).toEqual([]); + } + }); + it('CONTROL — the same sources at a proven site are refused', () => { + for (const source of ["f == 'a'", "record.f == 'a'"]) { + expect(refusalsOf(source, hintFor('tags', false, 'flattened')).map((e) => e.code)).toContain('list-equality'); + } + }); +}); diff --git a/packages/formula/src/validate.ts b/packages/formula/src/validate.ts index b0692e1423e..a94a68a59f8 100644 --- a/packages/formula/src/validate.ts +++ b/packages/formula/src/validate.ts @@ -121,16 +121,32 @@ export interface ExprSchemaHint { * key is what makes a `multiple: true` field a list here, since a field * type does not say whether it was declared multiple. A field either names * as multi-valued is a LIST SUBJECT, and a `==` / `!=` between a read of it - * (`record.` / `previous.`, in every member spelling the - * field-existence pass reads) and a non-null scalar literal is refused - * under `list-equality`: CEL compares the whole list with the scalar, so - * the expression answers the same constant on every row. ` == null` - * / `!= null` stays accepted. Absent ⇒ only {@link fieldTypes}' inherently + * and a non-null scalar literal is refused under `list-equality`: CEL + * compares the whole list with the scalar, so the expression answers the + * same constant on every row. A read is `record.` / `previous.` + * (`record['']` too; the optional spellings are refused as + * `invalid-cel` first), and, at a `'flattened'` site whose + * {@link faultOutcome} is `'run-fails'` (a run proven to bind a row of the + * typed object), the bare `` — not a name {@link flowVariables} + * holds, nor any bare name under {@link bareNamesUnproven}. At a flattened + * site with no proven row, nothing is judged. A name a comprehension macro + * binds is never the field inside that macro's body. ` == null` / + * `!= null` stays accepted. Absent ⇒ only {@link fieldTypes}' inherently * multi types are list subjects: a `select` / `lookup` / `user` field * declared `multiple: true` is then judged as it was before this key, not * at all. */ multiValueFields?: readonly string[]; + /** + * [#36167] The site's source is COMPILED TO A QUERY FILTER + * (`compileCelToFilter`), not evaluated as CEL per row: a sharing rule's + * `condition`. Only the `list-equality` prescription reads it: there `in` + * lowers only with a field on its left, so the membership test prescribed + * is `record..contains(…)` (`$contains`, membership on a list + * column), not `… in record.`, which the lowering refuses. Absent ⇒ + * the CEL spelling, every other caller's behaviour. + */ + filterCompiled?: boolean; /** * Evaluation scope of the authoring site — determines whether a bare top-level * identifier is legal (#1928): @@ -1486,6 +1502,11 @@ function scalarLiteralOf(node: unknown): string | undefined { * another list subject, which is a real whole-list comparison; and an operand * that is not a literal ({@link scalarLiteralOf}). * + * At a `'flattened'` site nothing is judged unless the caller declares the run + * proven to bind a row of the typed object ({@link ExprSchemaHint.faultOutcome} + * `'run-fails'`); elsewhere the names hold what the entrance handed the run. + * The prescription is spelled for the site ({@link listMembershipRewrite}). + * * The subject is read through `rootMemberOf`, the field-existence pass's own * member reader, so `record.f` and `record['f']` (and `previous.…`) are * judged alike, and the refusal renders the read as `.`. The @@ -1509,6 +1530,13 @@ function checkListEquality( ): void { const subjects = listSubjectsOf(schema); if (subjects.size === 0) return; + // A flattened (flow) site binds a row of the typed object only where the + // caller declares the run's outcome proven (`faultOutcome: 'run-fails'`: a + // record-triggered flow, or a time-relative sweep of the typed object). + // Anywhere else `record` and the bare names hold what the entrance handed + // the run — an API body, a parent's record, nothing — so a read is not + // proven to be the list field, and gets no verdict. + if (schema?.scope === 'flattened' && schema.faultOutcome !== 'run-fails') return; // CEL has no comments: a source that spells neither operator holds no comparison. if (!source.includes('==') && !source.includes('!=')) return; const tree = ast(); @@ -1522,16 +1550,19 @@ function checkListEquality( ? new Set([...subjects].filter((name) => !(schema.flowVariables ?? []).includes(name))) : undefined; // `bound`: the names the enclosing comprehension macros bind here. - const subjectOf = (node: unknown, bound: ReadonlySet): { reference: string } | undefined => { + const subjectOf = (node: unknown, bound: ReadonlySet): ListSubjectRead | undefined => { const read = rootMemberOf(node, FIELD_EXISTENCE_ROOTS); if (read) { - return subjects.has(read.field) && !bound.has(read.root) ? { reference: `${read.root}.${read.field}` } : undefined; + return subjects.has(read.field) && !bound.has(read.root) + ? { reference: `${read.root}.${read.field}`, bare: false } + : undefined; } const { op, args } = (node ?? {}) as { op?: unknown; args?: unknown }; return op === 'id' && typeof args === 'string' && bareSubjects?.has(args) && !bound.has(args) - ? { reference: args } + ? { reference: args, bare: true } : undefined; }; + const filterCompiled = schema?.filterCompiled === true; const walk = (node: unknown, bound: ReadonlySet): void => { if (!node || typeof node !== 'object') return; if (Array.isArray(node)) { @@ -1557,7 +1588,7 @@ function checkListEquality( const read = subjectOf(args[side], bound); const operand = read ? scalarLiteralOf(args[1 - side]) : undefined; if (!read || operand === undefined) continue; - errors.push(listEqualityRefusal(source, read.reference, op, operand)); + errors.push(listEqualityRefusal(source, read, op, operand, filterCompiled)); break; } } @@ -1566,26 +1597,75 @@ function checkListEquality( walk(tree, new Set()); } +/** A read {@link checkListEquality} judges: `.`, or a bare field name at a flattened site. */ +interface ListSubjectRead { + readonly reference: string; + readonly bare: boolean; +} + +/** + * The membership test that replaces ` `, in + * the spelling that works where the source is read, parenthesised whole so it + * can stand where the comparison stood (`A && (…)`): + * + * - a `.` read evaluated as CEL: `has()`-guarded, because an + * action's `visible` / `disabled` / `pressed` binds a sparse row (a key + * absent from it faults on `record.f != null`) and `previous` is `null` on + * a create; `has()` answers `false` there instead of faulting; + * - a bare name at a flattened (flow) site: the run binds every declared + * field, `null` when empty, so the `!= null` guard is enough (`has()` takes + * no bare name); + * - a site whose source compiles to a query filter (`filterCompiled`, a + * sharing rule's `condition`): `in` lowers only with a field on its LEFT, + * so membership is `.contains(…)`, which lowers to `$contains`, membership + * on a list column; its comparand is text, so a number or boolean literal + * is passed as its text (`$contains` names a stored `3` by `"3"`). + */ +function listMembershipRewrite( + read: ListSubjectRead, + operator: '==' | '!=', + operand: string, + filterCompiled: boolean, +): string { + const r = read.reference; + if (filterCompiled && !read.bare) { + const text = operand.startsWith('"') || operand.startsWith("'") ? operand : JSON.stringify(operand); + return operator === '==' + ? `(${r} != null && ${r}.contains(${text}))` + : `(${r} == null || !${r}.contains(${text}))`; + } + if (read.bare) { + return operator === '==' + ? `(${r} != null && ${operand} in ${r})` + : `(${r} == null || !(${operand} in ${r}))`; + } + return operator === '==' + ? `(has(${r}) && ${r} != null && ${operand} in ${r})` + : `(!has(${r}) || ${r} == null || !(${operand} in ${r}))`; +} + /** The `list-equality` refusal for ` `. */ function listEqualityRefusal( source: string, - reference: string, + read: ListSubjectRead, operator: '==' | '!=', operand: string, + filterCompiled: boolean, ): ExprValidationError { + const { reference } = read; const answer = operator === '==' ? 'false' : 'true'; - const rewrite = operator === '==' - ? `${reference} != null && ${operand} in ${reference}` - : `${reference} == null || !(${operand} in ${reference})`; - return refusal( - 'list-equality', - { reference, operator, operand, answer, rewrite }, - source, - `list compared with a scalar — \`${reference}\` holds a list (a multi-value field), and \`${operator}\` ` + - `compares the whole list with \`${operand}\`, so the expression answers \`${answer}\` on every row ` + - `whatever the list holds: the condition never changes. Test membership with \`in\`: write ` + - `\`${rewrite}\`. To test whether the list is set, compare it with \`null\`.`, - ); + const rewrite = listMembershipRewrite(read, operator, operand, filterCompiled); + const head = `list compared with a scalar — \`${reference}\` holds a list (a multi-value field), and \`${operator}\` ` + + `compares the whole list with \`${operand}\``; + const message = filterCompiled && !read.bare + ? `${head}: as CEL it answers \`${answer}\` on every row, and this condition compiles to a query filter, ` + + `where \`${operator}\` against a list column is refused, so it never tests membership. Test membership with ` + + `\`contains\`, which compiles to a membership filter: write \`${rewrite}\`. To test whether the list is set, ` + + `compare it with \`null\`.` + : `${head}, so the expression answers \`${answer}\` on every row whatever the list holds: the condition never ` + + `changes. Test membership with \`in\`: write \`${rewrite}\`. To test whether the list is set, compare it with ` + + `\`null\`.`; + return refusal('list-equality', { reference, operator, operand, answer, rewrite }, source, message); } /** diff --git a/packages/lint/src/validate-expressions.list-equality-36167.test.ts b/packages/lint/src/validate-expressions.list-equality-36167.test.ts index 69cb781bed8..04b2664545a 100644 --- a/packages/lint/src/validate-expressions.list-equality-36167.test.ts +++ b/packages/lint/src/validate-expressions.list-equality-36167.test.ts @@ -17,6 +17,10 @@ import { describe, it, expect } from 'vitest'; import { ObjectStackSchema } from '@objectstack/spec'; import { validateStackExpressions } from './validate-expressions.js'; +import { + validateSharingRuleEnforceability, + SHARING_RULE_UNLOWERABLE_CONDITION, +} from './validate-sharing-rule-enforceability.js'; const MANIFEST = { id: 'com.example.list-equality', name: 'list_equality_probe', version: '1.0.0', type: 'app' } as const; @@ -60,14 +64,16 @@ function visibleErrors(visible: string) { describe('publish lint — list-equality at a CEL site', () => { it.each([ - ["record.labels == 'frontend'", 'record.labels', 'record.labels != null && "frontend" in record.labels'], - ["record.labels != 'frontend'", 'record.labels', 'record.labels == null || !("frontend" in record.labels)'], - ["'u1' == record.watchers", 'record.watchers', 'record.watchers != null && "u1" in record.watchers'], + ["record.labels == 'frontend'", 'record.labels', '(has(record.labels) && record.labels != null && "frontend" in record.labels)'], + ["record.labels != 'frontend'", 'record.labels', '(!has(record.labels) || record.labels == null || !("frontend" in record.labels))'], + ["'u1' == record.watchers", 'record.watchers', '(has(record.watchers) && record.watchers != null && "u1" in record.watchers)'], ])('refuses %s, naming the field and the `in` rewrite', (source, reference, rewrite) => { const errors = visibleErrors(source); expect(errors).toHaveLength(1); expect(errors[0].message).toContain(`\`${reference}\` holds a list`); - expect(errors[0].message).toContain(rewrite); + expect(errors[0].message).toContain(`write \`${rewrite}\``); + // The prescribed text is itself accepted where it was prescribed. + expect(visibleErrors(rewrite)).toEqual([]); }); it.each([ @@ -109,7 +115,11 @@ describe('publish lint — list-equality at a CEL site', () => { // A record-triggered flow's condition reads the trigger record flattened: // a bare `labels` is `record.labels`, as the type pass reads it. - function flowErrors(condition: string, variables?: Array>) { + function flowErrors( + condition: string, + variables?: Array>, + entrance: { type: string; triggerType?: string } = { type: 'autolaunched', triggerType: 'record-after-update' }, + ) { return validateStackExpressions( specValid({ objects: [ticket], @@ -117,10 +127,19 @@ describe('publish lint — list-equality at a CEL site', () => { { name: 'ticket_flow', label: 'Ticket flow', - type: 'autolaunched', + type: entrance.type, ...(variables ? { variables } : {}), nodes: [ - { id: 'start', type: 'start', label: 'Start', config: { objectName: 'ticket_probe', triggerType: 'record-after-update', condition } }, + { + id: 'start', + type: 'start', + label: 'Start', + config: { + objectName: 'ticket_probe', + ...(entrance.triggerType ? { triggerType: entrance.triggerType } : {}), + condition, + }, + }, { id: 'end', type: 'end', label: 'End' }, ], edges: [{ id: 'e1', source: 'start', target: 'end' }], @@ -153,9 +172,66 @@ describe('publish lint — list-equality at a CEL site', () => { }, ); + it('the prescribed bare-name rewrite is parenthesised whole and accepted at the flow condition', () => { + const [refusal] = flowErrors("stage == 'qa' && labels != 'frontend'"); + expect(refusal.message).toContain('write `(labels == null || !("frontend" in labels))`'); + expect(flowErrors("stage == 'qa' && (labels == null || !(\"frontend\" in labels))")).toEqual([]); + }); + + // A flow no record write fires runs on what its entrance handed it (an API + // body, nothing): `labels` there is not proven to be the list field, and + // `labels == 'frontend'` can be correct code. No verdict. + it.each([ + ['an API flow', { type: 'api' }], + ['a trigger-less autolaunched flow', { type: 'autolaunched' }], + ['a scheduled flow', { type: 'schedule' }], + ])('CONTROL — %s: no list-equality, bare or record.', (_label, entrance) => { + expect(flowErrors("labels == 'frontend'", undefined, entrance)).toEqual([]); + expect(flowErrors("record.labels == 'frontend'", undefined, entrance)).toEqual([]); + }); + it('CONTROL — a bare name a declared flow variable holds is not the field', () => { const variables = [{ name: 'labels', type: 'text', isInput: true, isOutput: false }]; expect(flowErrors("labels == 'frontend'", variables)).toEqual([]); expect(flowErrors("record.labels == 'frontend'", variables)).toHaveLength(1); }); }); + +// A sharing rule's `condition` is compiled to a query filter, not evaluated as +// CEL: the CEL `in` rewrite does not lower there (`in` needs a field on its +// left), so the prescription is `contains`, which lowers to `$contains`. +describe('publish lint — list-equality at a sharing rule condition', () => { + const stackWith = (condition: string) => + specValid({ + objects: [ticket], + sharingRules: [ + { name: 'sr', object: 'ticket_probe', condition, sharedWith: { type: 'role', value: 'r' }, accessLevel: 'read' }, + ], + }); + /** The expression lint's findings and the enforceability pass's (which lowers the condition) together. */ + function sharingIssues(condition: string) { + const stack = stackWith(condition); + return [ + ...validateStackExpressions(stack).map((i) => ({ rule: 'expression', severity: i.severity, message: i.message })), + ...validateSharingRuleEnforceability(stack).map((f) => ({ rule: f.rule, severity: 'error', message: f.message })), + ]; + } + + it.each([ + ["record.labels == 'frontend'", '(record.labels != null && record.labels.contains("frontend"))'], + ["record.watchers != 'u1'", '(record.watchers == null || !record.watchers.contains("u1"))'], + ])('refuses %s, prescribing the `contains` rewrite that lowers', (condition, rewrite) => { + const errors = sharingIssues(condition).filter((i) => i.severity === 'error' && i.message.includes('holds a list')); + expect(errors).toHaveLength(1); + expect(errors[0].message).toContain(`write \`${rewrite}\``); + // The prescribed text draws no finding at the same site: it lowers. + expect(sharingIssues(rewrite)).toEqual([]); + }); + + it('CONTROL — the CEL `in` rewrite the other sites get does not lower here', () => { + const issues = sharingIssues('(has(record.labels) && record.labels != null && "frontend" in record.labels)'); + expect(issues.map((i) => i.rule)).toContain(SHARING_RULE_UNLOWERABLE_CONDITION); + expect(sharingIssues('record.labels != null && "frontend" in record.labels').map((i) => i.rule)) + .toContain(SHARING_RULE_UNLOWERABLE_CONDITION); + }); +}); diff --git a/packages/lint/src/validate-expressions.ts b/packages/lint/src/validate-expressions.ts index 43ceea1163c..c10ac8bb787 100644 --- a/packages/lint/src/validate-expressions.ts +++ b/packages/lint/src/validate-expressions.ts @@ -3006,6 +3006,14 @@ export function runStackExpressionPasses(stack: AnyRec, options: StackExpression * for byte what it was. */ flowBare?: FlowBareNames, + /** + * [#36167] The source compiles to a query filter rather than being + * evaluated as CEL (a sharing rule's `condition`), handed to the shared + * validator as `ExprSchemaHint.filterCompiled`, so the `list-equality` + * prescription is the membership spelling that lowers there + * (`record..contains(…)`). Absent, the call is byte for byte what it was. + */ + filterCompiled?: boolean, ): void => { if (raw == null) return; // Absent unless this is a served-row site on an object that declares a @@ -3029,6 +3037,7 @@ export function runStackExpressionPasses(stack: AnyRec, options: StackExpression ...(flowBare ? { flowVariables: flowBare.variables } : {}), ...(flowBare?.unproven ? { bareNamesUnproven: true } : {}), ...(flowBare?.timeRelativeSweep ? { timeRelativeSweep: true } : {}), + ...(filterCompiled ? { filterCompiled: true } : {}), } : { scope, ...roots }); for (const e of res.errors) { @@ -4728,7 +4737,9 @@ export function runStackExpressionPasses(stack: AnyRec, options: StackExpression // `sharing.zod.ts` maps it back to `condition` in its rejection message; // `predicate` is refused with no rename at all. #4984 removed exactly this // pair one file over; this was the same read left behind (#5017). - check(where, sharingRule.condition, ruleObj, 'record'); + // [#36167] Compiled to a query filter (`compileCelToFilter`), never + // evaluated as CEL: the list-equality prescription is spelled to lower. + check(where, sharingRule.condition, ruleObj, 'record', undefined, undefined, undefined, undefined, undefined, undefined, true); } // ── Hook `condition` predicates (record-scoped gate) ─────────────── diff --git a/packages/mcp/src/mcp-validate-expression.list-equality-36167.test.ts b/packages/mcp/src/mcp-validate-expression.list-equality-36167.test.ts index dbe7b9c362d..695e1828485 100644 --- a/packages/mcp/src/mcp-validate-expression.list-equality-36167.test.ts +++ b/packages/mcp/src/mcp-validate-expression.list-equality-36167.test.ts @@ -163,6 +163,24 @@ describe('validate_expression — list-equality on a multiple: true field (#3616 } }); + it('flow_condition: the bare rewrite is parenthesised whole and reads ok itself', async () => { + const [refused] = listEquality(await validate(stdioBridge(), "record.stage == 'b' && picks != 'a'", 'flow_condition')); + expect(refused!.params?.rewrite).toBe('(picks == null || !("a" in picks))'); + const r = await validate(stdioBridge(), `record.stage == 'b' && ${refused!.params?.rewrite as string}`, 'flow_condition'); + expect(listEquality(r)).toEqual([]); + }); + + // A flow no record write fires runs on what its entrance handed it: `picks` + // is not proven to be the field there, so `picks == 'a'` can be correct. + it.each(['api', 'schedule', 'none'] as const)( + 'CONTROL — flow_condition with triggerKind %s: neither the bare nor the record. read is judged', + async (triggerKind) => { + for (const expression of ["picks == 'a'", "record.picks == 'a'"]) { + expect(listEquality(await validate(stdioBridge(), expression, 'flow_condition', { triggerKind }))).toEqual([]); + } + }, + ); + it('CONTROL — flow_condition: a bare name a declared variable holds is not the field; without the member, as before', async () => { const variables = [{ name: 'picks', type: 'text' }]; expect(listEquality(await validate(stdioBridge(), "picks == 'a'", 'flow_condition', { variables }))).toEqual([]); diff --git a/packages/services/service-automation/src/flow-registration-checks.ts b/packages/services/service-automation/src/flow-registration-checks.ts index d08c3978d8e..902d7ee43e9 100644 --- a/packages/services/service-automation/src/flow-registration-checks.ts +++ b/packages/services/service-automation/src/flow-registration-checks.ts @@ -794,6 +794,14 @@ export function validateFlowExpressions( const objectName = bound?.triggerType === 'time_relative' ? bound.binding.object : ((startNode?.config ?? {}) as Record).objectName; + const startCfg = (startNode?.config ?? {}) as Record; + const sweep = (startCfg.timeRelative ?? {}) as Record; + const runBindsTypedRow = bound?.triggerType === 'record_change' + // The array form routes here only to be refused at bind: it never fires. + ? typeof startCfg.triggerType === 'string' + : bound?.triggerType === 'time_relative' + && typeof sweep.object === 'string' + && (typeof startCfg.objectName !== 'string' || startCfg.objectName === sweep.object); const schemaHint = typeof objectName === 'string' ? (() => { const s = this.objectSchemaResolver?.(objectName); @@ -804,6 +812,11 @@ export function validateFlowExpressions( fieldTypes: s.fieldTypes, // [#36167] A list compared with a scalar is reported (`list-equality`). ...(s.multiValueFields ? { multiValueFields: s.multiValueFields } : {}), + // [#36167] The run binds a row of the typed object (the flows + // `@objectstack/lint` declares `run-fails` on), so a flattened + // list read is proven to be the field: the one signal the + // list-equality verdict reads at a flattened site. + ...(runBindsTypedRow ? { faultOutcome: 'run-fails' as const } : {}), scope: 'flattened' as const, } : undefined; @@ -825,14 +838,6 @@ export function validateFlowExpressions( // every run it starts — and its refusal names the rewrite // ({@link SHARED_STEPS_REWRITE}; ruling 7023700548). `objectstack // validate` judges the same set. - const startCfg = (startNode?.config ?? {}) as Record; - const sweep = (startCfg.timeRelative ?? {}) as Record; - const runBindsTypedRow = bound?.triggerType === 'record_change' - // The array form routes here only to be refused at bind: it never fires. - ? typeof startCfg.triggerType === 'string' - : bound?.triggerType === 'time_relative' - && typeof sweep.object === 'string' - && (typeof startCfg.objectName !== 'string' || startCfg.objectName === sweep.object); const valueEnvelopeFieldTypes = runBindsTypedRow && !flowRebindsRunRowRoots(flow) ? schemaHint?.fieldTypes : undefined; diff --git a/packages/services/service-automation/src/list-equality-advisory-36167.test.ts b/packages/services/service-automation/src/list-equality-advisory-36167.test.ts index a3b0a326316..de6a0b14543 100644 --- a/packages/services/service-automation/src/list-equality-advisory-36167.test.ts +++ b/packages/services/service-automation/src/list-equality-advisory-36167.test.ts @@ -39,11 +39,15 @@ describe('registerFlow — a list compared with a scalar is reported (advisory)' return l; } - function makeFlow(condition: string) { + /** A record-triggered flow by default; `entrance` swaps in a flow no record write fires. */ + function makeFlow(condition: string, entrance: { type: string; triggerType?: string } = { type: 'record_change', triggerType: 'record-after-update' }) { return { - name: 'ticket_flow', label: 'Ticket Flow', type: 'record_change', + name: 'ticket_flow', label: 'Ticket Flow', type: entrance.type, nodes: [ - { id: 'start', type: 'start', label: 'Start', config: { objectName: 'ticket' } }, + { + id: 'start', type: 'start', label: 'Start', + config: { objectName: 'ticket', ...(entrance.triggerType ? { triggerType: entrance.triggerType } : {}) }, + }, { id: 'check', type: 'decision', label: 'Check', config: { condition } }, { id: 'end', type: 'end', label: 'End' }, ], @@ -54,11 +58,11 @@ describe('registerFlow — a list compared with a scalar is reported (advisory)' }; } - function warningsFor(condition: string): string[] { + function warningsFor(condition: string, entrance?: { type: string; triggerType?: string }): string[] { const warns: string[] = []; const engine = new AutomationEngine(loggerCapturing(warns)); engine.setObjectSchemaResolver((name) => (name === 'ticket' ? parseObjectFieldSchema(TICKET_FIELDS) : undefined)); - expect(() => engine.registerFlow('ticket_flow', makeFlow(condition) as any)).not.toThrow(); + expect(() => engine.registerFlow('ticket_flow', makeFlow(condition, entrance) as any)).not.toThrow(); return warns.filter((m) => /holds a list/.test(m)); } @@ -83,6 +87,23 @@ describe('registerFlow — a list compared with a scalar is reported (advisory)' expect(w[0]).toContain(` in ${reference}`); }); + it('the bare rewrite it prescribes is parenthesised whole, and is not reported itself', () => { + const [w] = warningsFor("stage == 'won' && labels != 'frontend'"); + expect(w).toContain('write `(labels == null || !("frontend" in labels))`'); + expect(warningsFor("stage == 'won' && (labels == null || !(\"frontend\" in labels))")).toEqual([]); + }); + + // A flow no record write fires runs on what its entrance handed it: the + // names are not proven to be the ticket's fields, so no verdict. + it.each([ + ['an API flow', { type: 'api', triggerType: 'api' }], + ['a scheduled flow', { type: 'schedule', triggerType: 'schedule' }], + ['a trigger-less autolaunched flow', { type: 'autolaunched' }], + ])('CONTROL — %s: neither the bare nor the record. read is reported', (_label, entrance) => { + expect(warningsFor("labels == 'frontend'", entrance)).toEqual([]); + expect(warningsFor("record.labels == 'frontend'", entrance)).toEqual([]); + }); + it.each([ "record.stage == 'won'", "record.owner == 'u1'", 'record.watchers != null', "'u1' in record.watchers", "stage == 'won'", "owner == 'u1'", 'labels != null', "'frontend' in labels", @@ -103,9 +124,14 @@ describe('the premise at a flow condition — the run flattens the record, and a expect(run("record.labels == 'frontend'", labels)).toBe(false); expect(run("labels != 'frontend'", labels)).toBe(true); }); - it('CONTROL — the membership rewrite answers per row', () => { - expect(run("labels != null && 'frontend' in labels", ['frontend', 'qa'])).toBe(true); - expect(run("labels != null && 'frontend' in labels", ['qa'])).toBe(false); - expect(run("labels != null && 'frontend' in labels", null)).toBe(false); + it('CONTROL — the prescribed bare rewrites answer per row, inside `&&` too', () => { + const member = '(labels != null && "frontend" in labels)'; + const notMember = '(labels == null || !("frontend" in labels))'; + for (const [labels, isMember] of [[['frontend', 'qa'], true], [['qa'], false], [[], false], [null, false]] as const) { + expect(run(member, labels)).toBe(isMember); + expect(run(notMember, labels)).toBe(!isMember); + expect(run(`true && ${notMember}`, labels)).toBe(!isMember); + expect(run(`false && ${notMember}`, labels)).toBe(false); + } }); }); diff --git a/packages/spec/src/migrations/entries/semantic/18.cel-list-equality-refused.ts b/packages/spec/src/migrations/entries/semantic/18.cel-list-equality-refused.ts index 6ea16816c02..fc41921f4ab 100644 --- a/packages/spec/src/migrations/entries/semantic/18.cel-list-equality-refused.ts +++ b/packages/spec/src/migrations/entries/semantic/18.cel-list-equality-refused.ts @@ -11,17 +11,26 @@ export const entry: SemanticMigration = { id: 'cel-list-equality-refused', surface: 'Any CEL predicate or formula the shared validator types against an object (a validation rule, a field rule, a ' - + 'formula, an action\'s visible / disabled, a hook or flow condition): `==` or `!=` ' - + 'between a read of a list-valued field (`multiselect`, `checkboxes`, `tags`, or a `select` / `radio` / ' - + '`lookup` / `user` / `file` / `image` field declared `multiple: true`) on `record` / `previous` — or, at a ' + + 'formula, an action\'s visible / disabled, a hook condition, a sharing rule condition, and the condition of a ' + + 'flow whose run binds a row of that object: a record-triggered flow, or a time-relative sweep of it): `==` or ' + + '`!=` between a read of a list-valued field (`multiselect`, `checkboxes`, `tags`, or a `select` / `radio` / ' + + '`lookup` / `user` / `file` / `image` field declared `multiple: true`) on `record` / `previous` — or, at such a ' + 'flow condition, its bare name, which the run binds to the trigger record\'s field — and a non-null ' + 'string, number or boolean literal, in either operand order. Not the shape: a name a comprehension macro ' - + 'binds (`record.items.exists(labels, labels == \'a\')`, where `labels` is one item), nor a bare name a ' - + 'declared flow variable holds', + + 'binds (`record.items.exists(labels, labels == \'a\')`, where `labels` is one item), a bare name a ' + + 'declared flow variable holds, nor any read in a flow no record write or sweep starts (an API, scheduled or ' + + 'trigger-less flow), whose run holds what its entrance handed it', replacement: - 'Test membership with `in`, null-guarded because `\'a\' in null` faults: `record.labels != null && ' - + '\'frontend\' in record.labels` for `==`, and `record.labels == null || !(\'frontend\' in record.labels)` for ' - + '`!=`. Compare the list with `null` to test whether it is set, and with a list literal for a whole-list match. ' + 'Test membership, parenthesised whole so it stands where the comparison stood, in the spelling the site reads. ' + + 'A `record.` / `previous.` read evaluated as CEL: `(has(record.labels) && record.labels != null && \'frontend\' ' + + 'in record.labels)` for `==`, `(!has(record.labels) || record.labels == null || !(\'frontend\' in ' + + 'record.labels))` for `!=` (`has()` answers on a sparse row or a null `previous`, where `\'a\' in null` and an ' + + 'absent key fault). A bare name at a flow condition: `(labels != null && \'frontend\' in labels)` / `(labels == ' + + 'null || !(\'frontend\' in labels))`. A sharing rule condition, which compiles to a query filter where `in` ' + + 'needs a field on its left: `(record.labels != null && record.labels.contains(\'frontend\'))` / ' + + '`(record.labels == null || !record.labels.contains(\'frontend\'))`, a membership filter (`$contains`). The ' + + 'refusal names the rewrite for its site. Compare the list with `null` to test whether it is set, and with a list ' + + 'literal for a whole-list match. ' + '`os validate`, `os build`, the MCP `validate_expression` tool and the Studio object editor\'s draft check ' + 'refuse the shape as `list-equality`, an error; the flow registration pass logs it.', reason: From 254d40cb40233500bc47152a1e91da62a451a324 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 07:30:01 +0000 Subject: [PATCH 2/2] test(lint, service-automation): the sharing-rule and API-flow list-equality pins build fixtures that register The sharing-rule fixture named a recipient type the spec does not have and no rule type, so the three sharing-site cases stopped at the spec-validity guard. The API-flow control carried no hook secret, so registerFlow refused it before the advisory pass ran. Claude-Session: https://claude.ai/code/session_01QsR2jVXKcrF3rr7ShYFZ9E Co-authored-by: Claude --- ...alidate-expressions.list-equality-36167.test.ts | 2 +- .../src/list-equality-advisory-36167.test.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/lint/src/validate-expressions.list-equality-36167.test.ts b/packages/lint/src/validate-expressions.list-equality-36167.test.ts index 04b2664545a..7e7a6598838 100644 --- a/packages/lint/src/validate-expressions.list-equality-36167.test.ts +++ b/packages/lint/src/validate-expressions.list-equality-36167.test.ts @@ -205,7 +205,7 @@ describe('publish lint — list-equality at a sharing rule condition', () => { specValid({ objects: [ticket], sharingRules: [ - { name: 'sr', object: 'ticket_probe', condition, sharedWith: { type: 'role', value: 'r' }, accessLevel: 'read' }, + { name: 'sr', type: 'criteria', object: 'ticket_probe', condition, sharedWith: { type: 'team', value: 't' }, accessLevel: 'read' }, ], }); /** The expression lint's findings and the enforceability pass's (which lowers the condition) together. */ diff --git a/packages/services/service-automation/src/list-equality-advisory-36167.test.ts b/packages/services/service-automation/src/list-equality-advisory-36167.test.ts index de6a0b14543..ccd54ead543 100644 --- a/packages/services/service-automation/src/list-equality-advisory-36167.test.ts +++ b/packages/services/service-automation/src/list-equality-advisory-36167.test.ts @@ -40,13 +40,18 @@ describe('registerFlow — a list compared with a scalar is reported (advisory)' } /** A record-triggered flow by default; `entrance` swaps in a flow no record write fires. */ - function makeFlow(condition: string, entrance: { type: string; triggerType?: string } = { type: 'record_change', triggerType: 'record-after-update' }) { + type Entrance = { type: string; triggerType?: string; secretRef?: string }; + function makeFlow(condition: string, entrance: Entrance = { type: 'record_change', triggerType: 'record-after-update' }) { return { name: 'ticket_flow', label: 'Ticket Flow', type: entrance.type, nodes: [ { id: 'start', type: 'start', label: 'Start', - config: { objectName: 'ticket', ...(entrance.triggerType ? { triggerType: entrance.triggerType } : {}) }, + config: { + objectName: 'ticket', + ...(entrance.triggerType ? { triggerType: entrance.triggerType } : {}), + ...(entrance.secretRef ? { secretRef: entrance.secretRef } : {}), + }, }, { id: 'check', type: 'decision', label: 'Check', config: { condition } }, { id: 'end', type: 'end', label: 'End' }, @@ -58,7 +63,7 @@ describe('registerFlow — a list compared with a scalar is reported (advisory)' }; } - function warningsFor(condition: string, entrance?: { type: string; triggerType?: string }): string[] { + function warningsFor(condition: string, entrance?: Entrance): string[] { const warns: string[] = []; const engine = new AutomationEngine(loggerCapturing(warns)); engine.setObjectSchemaResolver((name) => (name === 'ticket' ? parseObjectFieldSchema(TICKET_FIELDS) : undefined)); @@ -96,7 +101,8 @@ describe('registerFlow — a list compared with a scalar is reported (advisory)' // A flow no record write fires runs on what its entrance handed it: the // names are not proven to be the ticket's fields, so no verdict. it.each([ - ['an API flow', { type: 'api', triggerType: 'api' }], + // An inbound api flow registers only with a hook secret (ADR-0041). + ['an API flow', { type: 'api', triggerType: 'api', secretRef: 'TICKET_HOOK_SECRET' }], ['a scheduled flow', { type: 'schedule', triggerType: 'schedule' }], ['a trigger-less autolaunched flow', { type: 'autolaunched' }], ])('CONTROL — %s: neither the bare nor the record. read is reported', (_label, entrance) => {