You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit cb5a975
Browse filesBrowse the repository at this point in the historyBrowse files
fix(formula): list-equality prescribes a rewrite that works at each site, and judges a flow condition only where the run binds the typed row (#36340)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbPgGMxS6cCEEprR4e3dQNe9)_Fixes#36167
This is the card's last item: the builder half (#36185) and the
validator half (#36207) are merged, and the remaining follow-ups have
their own cards (#36217 skills text, #36218 review follow-ups, #36219
the as-you-type editor).
Clause-②: yes (widening)
Metadata-protocol: added
Skills-docs: follow-up #36217
## 维护者速读
-
作者把多值字段(多选、多人等)与单个值比较相等时,系统给出的改写建议现在在每个位置都能用:共享规则条件里也能用,且建议本身加了括号,不会被前面的条件拆开;由接口、定时或无触发方式启动的流程里,这种写法不再被误拒。
-
属于「表达式校验与作者护栏」:上一个已合并的拉取请求开始拒绝这种写法,复审发现它给的改写在共享规则里无法生效、部分写法会报错,还会误拒正确的流程条件。
- 若出错,作者看到的只是另一种改写建议,或某个流程条件不再被拦下;本改动可以整体撤回,不影响已存储的数据。
- 无
## What changes
Follow-up to #36207, which merged before its round-4 review findings
were addressed. This PR covers four of them: r05 S1, r05 S2, r05 S4 /
r06 N1, and r06 S1.
**The prescribed rewrite is spelled for its site and parenthesised
whole** (`listMembershipRewrite` in `packages/formula/src/validate.ts`).
Each spelling below was measured on the site's own evaluator or filter
compiler:
| site | `==` rewrite | `!=` rewrite |
|---|---|---|
| a `record.` / `previous.` read evaluated as CEL (validation rule,
field rule, formula, action `visible` / `disabled` / `pressed`, hook
condition) | `(has(record.f) && record.f != null && "v" in record.f)` |
`(!has(record.f) \|\| record.f == null \|\| !("v" in record.f))` |
| a bare name at a flow condition (the run binds every declared field,
`null` when empty) | `(f != null && "v" in f)` | `(f == null \|\| !("v"
in f))` |
| a sharing rule `condition`, compiled to a query filter (new
`ExprSchemaHint.filterCompiled`, filled by the publish lint) |
`(record.f != null && record.f.contains("v"))` | `(record.f == null \|\|
!record.f.contains("v"))` |
No single spelling works at every site, which is why the rewrite differs
per site:
- `"v" in record.f` does not lower to a filter. `compileCelToFilter`
answers "`in` requires a field on the left (got literal)", so the
sharing rule is dropped as `sharing-rule-unlowerable-condition`.
- `has()` does not lower either ("unsupported operator call").
- On the CEL evaluator, `record.f.contains("v")` faults on a list,
because there is no `list.contains` overload.
- `record.f != null && "v" in record.f` faults on a row that lacks the
key ("No such key"), which a sparse action row does. It also faults on a
null `previous`, as on a create.
The filter spelling lowers to `$and[{f:{$null:false}},
{f:{$contains:"v"}}]` and `$or[{f:{$null:true}},
{$not:{f:{$contains:"v"}}}]`. `$contains` on a JSON-stored (multi-value)
column is membership in `matchesFilterCondition` and in driver-sql
(`sql-driver-17590-json-column-membership.test.ts`). A number or boolean
operand is passed as its text (`contains("3")`), since `$contains`
compares text. The sharing-site message also says why `==` does not work
there: the query filter refuses `$eq` against a list column.
**A flattened (flow) site is judged only where the run binds a row of
the typed object** (r06 S1). `checkListEquality` now returns early at a
`'flattened'` site unless `faultOutcome` is `'run-fails'`. That outcome
is declared only on a record-triggered flow, or on a time-relative sweep
of the typed object: the lint's `faultOutcomeOf` ledger,
`validate-expressions.ts` around line 1632. On any other flow (API,
schedule, no trigger), the ledger's own row says the run "holds what its
entrance handed it". `seedRunVariables` flattens whatever record that
is. So an API flow whose request body carries a string `labels` runs
`labels == 'frontend'` correctly, and #36207 refused it. The MCP tool
already passes this outcome for `flow_condition` (its default
`triggerKind` is `record_change`). `registerFlow`'s advisory pass now
passes it on the same flows (`runBindsTypedRow`, which this PR moves
above the hint). Side effect: on those flows, the pass's logged
type-mismatch lines take the `run-fails` wording that `os validate`
already prints. It still only logs and never throws.
**Docblocks (r05 S4 / r06 N1).**
- `ExprSchemaHint.multiValueFields` now names the forms actually judged:
- `record.f` / `previous.f` and the bracket spelling;
- the optional spellings, which are refused as `invalid-cel` first;
- the bare name, only at a flattened site with `run-fails`, excluding
`flowVariables` and `bareNamesUnproven`;
- comprehension-bound names, which are never the field.
- `ExpressionRefusalParams['list-equality']` now documents `reference`
(the bracket spelling renders `record.f`; a bare name is the bare name)
and the per-site `rewrite`.
**Semantic entry** `cel-list-equality-refused` now has the per-site
replacement text and the narrowed surface. The surface adds the sharing
rule condition and limits flows to the proven-row ones.
## Tests
- `packages/formula/src/validate-list-equality-36167.test.ts`
- New describe, "the prescribed rewrite tests membership where it is
read". For each site class it takes the rewrite out of the refusal
itself, pins its text, and runs it:
- **CEL member read:** evaluated on rows `[a,b]` / `[b]` / `[]` / `null`
/ absent, and with `previous = null`. Each is also checked inside
`record.name == 'x' && …`, `record.name == 'y' && …` and `false || …`,
which pins the parenthesisation.
- **Bare name:** evaluated with the row bound as top-level names.
- **Filter:** lowered with `compileCelToFilter` and matched with
`matchesFilterCondition` (with the column declared `tags`), including
inside `&&`.
- Each rewrite validates clean at its own site.
- The CEL `in` form is shown not to lower.
- New describe, "a flattened site with no proven row binding gets no
verdict": bare and `record.` reads, `fail-closed` / `fail-open`, plus a
proven-site control.
- `packages/formula/src/expression-refusal-codes.test.ts`: the two
`list-equality` PINS carry the new rewrites. Two new pins cover the bare
name at a proven flattened site and the `filterCompiled` site, with
params and the whole message.
- `packages/lint/src/validate-expressions.list-equality-36167.test.ts`:
- action `visible` rewrites pinned, and each validates clean;
- a flow condition's bare `!=` rewrite pinned in the parenthesised form
and accepted inside `stage == 'qa' && …`;
- CONTROLS: an API, a trigger-less autolaunched and a scheduled flow get
no list-equality, bare or `record.`;
- new describe, the sharing rule `condition`: refused with the
`contains` rewrite, and that rewrite draws no finding from the
expression lint or from `validateSharingRuleEnforceability` (it lowers);
- CONTROL: the CEL `in` forms draw `sharing-rule-unlowerable-condition`
there.
-
`packages/services/service-automation/src/list-equality-advisory-36167.test.ts`:
- `makeFlow` now states its trigger (`record-after-update`);
- parenthesised bare rewrite pinned and not reported itself;
- CONTROLS: API, scheduled and trigger-less flows report nothing;
- premise: the bare rewrites answer per row on `evaluateCondition`,
including `false && (…)`.
- Two fixtures fixed at `254d40cb` (they had never run; each stopped
before the behaviour it pins):
- the sharing-rule describe in the lint pin built its rule with a
recipient type the spec does not have (`role`) and no rule `type`, so
all three cases failed at the spec-validity guard. It now uses `type:
'criteria'` and a `team` recipient, as the other spec-valid sharing
fixtures do;
- the API-flow CONTROL in the service-automation pin carried no hook
secret, so `registerFlow` refused the flow before the advisory pass ran.
It now names a `secretRef` (ADR-0041).
-
`packages/mcp/src/mcp-validate-expression.list-equality-36167.test.ts`:
the `flow_condition` rewrite is pinned and validates clean. CONTROL:
`triggerKind` `api` / `schedule` / `none` get no list-equality.
## Acceptance notes
- **Clause ② for this diff: `yes (widening)`.** Two things widen:
- it adds the optional public key `ExprSchemaHint.filterCompiled`;
- flow conditions on API / scheduled / trigger-less flows are accepted
again, after #36207 refused them.
Nothing in this diff refuses more. The changed rewrite text and the
narrower flattened scope are not narrowings. `Metadata-protocol: added`
because an accepted value is restored, so every package moved is
`minor`.
- The driver-sql leg of the filter rewrite is cited, not run here:
`$contains` membership on a JSON column is pinned in
`sql-driver-17590-json-column-membership.test.ts`, and `$not` is
NULL-safe (#5146). This PR measures the lowering and
`matchesFilterCondition`.
- Decision node `config.condition` in the lint: only the start node's
gate and edge / branch conditions carry the flow's outcome. An inert
node condition already has its own `flow-inert-node-condition` finding,
and gets no list-equality verdict.
- L2 S1 carried by #36218 (scope !== 'record'); nits N1–N4 accepted.
## Verification
Final head `254d40cb` (handover head `5a29954a` + `origin/main` merged
at `2b570445` + the two fixture fixes). Every reading below is at that
head.
<details><summary>Package suites and pins</summary>
- Build closure `--filter '@objectstack/lint^...' --filter
'@objectstack/mcp^...' --filter '@objectstack/service-automation^...'
--filter '@objectstack/scenarios^...' build`: lock VERDICT command-exit
0. Later a full `pnpm build --concurrency=2`: 120/120 tasks, VERDICT
command-exit 0.
- Pins: formula `validate-list-equality-36167` +
`expression-refusal-codes` 250/250 (the 8 bare-name failures of the
handover run are gone); lint `validate-expressions.list-equality-36167`
27/27 (3 failed before the fixture fix); mcp
`mcp-validate-expression.list-equality-36167` 15/15; service-automation
`list-equality-advisory-36167` 22/22 (1 failed before the fixture fix).
- Full suites, one locked run, VERDICT command-exit 0: formula build +
test 70 files / 2107 tests + typecheck exit 0; lint 225 files / 9434
tests + typecheck exit 0; mcp 83 files / 1467 tests + typecheck exit 0;
service-automation 290 files / 4220 tests + typecheck exit 0; spec
`src/migrations` 5 files / 198 tests.
</details>
<details><summary>Ablations (seven, each through ablation-replace WRAP
mode under the lock)</summary>
Each mutation was proven on disk (anchor 1 to 0, blob changed) and
restored (blob equal to the HEAD blob, empty `git diff HEAD`). Every
mutated module is read from source by its suite, so there is no dist
leg.
| ablation | file | pin result |
|---|---|---|
| delete the flattened proven-row early return | formula `validate.ts` |
5 failed / 245 passed (250) |
| never take the `filterCompiled` spelling | formula `validate.ts` | 13
failed / 237 |
| drop the outer parentheses of the `!=` member-read rewrite | formula
`validate.ts` | 6 failed / 244 |
| drop `has()` from the `==` member-read rewrite | formula `validate.ts`
| 4 failed / 246 |
| lint passes no `filterCompiled` at the sharing rule | lint
`validate-expressions.ts` | 2 failed / 25 (27) |
| service-automation always declares `run-fails` |
`flow-registration-checks.ts` | 3 failed / 19 (22): the API, scheduled
and trigger-less CONTROLS |
| service-automation never declares `run-fails` |
`flow-registration-checks.ts` | 5 failed / 17 (22) |
</details>
<details><summary>Derived gates</summary>
- `dispatch-gates --commands` at `254d40cb`: 96 families.
`dispatch-gates --ran` with recorded exit codes: 96 derived, 96 run, 0
NOT-MEASURED (a derived zero), every family exit 0.
- Three needed a prerequisite first and were re-run:
`check-plugin-teardown-shape --self-test` (exit 3 on the shallow clone
until its pinned fixture commit was fetched, then exit 0); the cli
`migrate-meta-engine-guidance` vitest (exit 1, MODULE_NOT_FOUND on an
unbuilt `@objectstack/mcp` dist, then 3/3 after the full build);
`check:dual-build-cjs-loads` (exit 3 PREREQUISITE NOT MET, then exit 0
after the full build: 124 require entry points across 72 packages load).
- `check:type-check-debt` exit 0. `check:nul-bytes` OK. `overlap-check`
VERDICT clean exit 0 against `origin/main` `2b570445` and #36333 (shares
`validate.ts`, merges cleanly).
- CI at `254d40cb`: all 69 check-runs completed, every one success or
skipped (Check Changeset, PR-body guards, Governed Surface Queue Guard,
every Lint and Type Check lane, Test Core 10/10 shards, Test UI 16/16,
Build Core, Dogfood Regression Gate).
- `test:repo` was not run locally (the diff touches no repo-project
test); CI's Test Core ran it.
</details>
Dogfood battery: n/a (no `!` in the title, and `Clause-②: yes
(widening)` has no `(narrowing)` arm).
Two-minute check: `pnpm --filter @objectstack/formula exec vitest run
src/validate-list-equality-36167.test.ts`. Expected: every test passes,
including the "prescribed rewrite" and "no proven row" describes.
Read first, by risk:
1. `packages/formula/src/validate.ts`: `listMembershipRewrite` and the
early return in `checkListEquality`.
2.
`packages/services/service-automation/src/flow-registration-checks.ts`:
`faultOutcome` on the advisory hint.
3. `packages/lint/src/validate-expressions.ts`: the sharing-rule
`check(…, true)`.
---
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01QsR2jVXKcrF3rr7ShYFZ9E
<!-- signed: repo:objectstack#7 · zhuangjianguo ·
session_01QsR2jVXKcrF3rr7ShYFZ9E -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
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
9
+
10
+
Clause-②: yes (widening)
11
+
Metadata-protocol: added
12
+
Skills-docs: follow-up #36217
13
+
14
+
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.
15
+
16
+
The rewrite the refusal prescribes now depends on the site, and is parenthesised whole so it can stand where the comparison stood (`A && (…)`):
17
+
18
+
-**A `record.` / `previous.` read evaluated as CEL** (a validation rule, a field rule, a formula, an action's `visible` / `disabled` / `pressed`, a hook condition):
19
+
- FROM `record.labels != null && "frontend" in record.labels`
20
+
- TO `(has(record.labels) && record.labels != null && "frontend" in record.labels)`
21
+
-`has()` answers on a sparse row or a null `previous`, where the old form faulted.
22
+
- 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 `&&`.
23
+
-**A bare name at a flow condition:**
24
+
- FROM `labels == null || !("frontend" in labels)`
25
+
- TO `(labels == null || !("frontend" in labels))`
26
+
- For `==` the TO form is `(labels != null && "frontend" in labels)`.
27
+
-**A sharing rule `condition`**, which compiles to a query filter:
28
+
- 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`.
29
+
- TO `(record.labels != null && record.labels.contains("frontend"))`, which lowers to a membership filter (`$contains`).
30
+
- For `!=` the TO form is `(record.labels == null || !record.labels.contains("frontend"))`.
31
+
- A number or boolean operand is passed as its text (`contains("3")`).
32
+
33
+
One-line fix: write the rewrite the refusal names.
34
+
35
+
`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.
0 commit comments