Repository navigation
Commit ad92dfd
fix(lint)!: refuse == / != on a list-valued field reached through a lookup hop (#36673)
Fixes #36237
Clause-②: yes (narrowing)
Metadata-protocol: narrowed
Skills-docs: none — the objectstack-formula skill already teaches that a
list field compared with a scalar literal is refused, and the
has()-guarded `in` rewrite; a hop read of a list field takes the same
rewrite
## 维护者速读
- 用户能看到什么变化:作者在校验规则或公式里拿关联对象的多值字段和单个值做等号比较时,构建和保存对象时会直接报错并给出改写,以前静默通过。
- 为什么做:多值字段被单值比较的问题根字段已经拦住,隔一层关联就漏掉了;这次补上,替写条件的作者解决"规则看着对却永远不触发"。
- 出错会怎样:误拦只会出现在保存或构建时,作者按提示改写即可通过,已存的数据照常读取;撤回这次改动即恢复旧行为。
- 要你做什么:无。
## What changes
The root-field case (`record.labels == 'vip'` on a list-valued field) is
refused as `list-equality` by the shared validator. One lookup hop away,
`record.account.labels == 'vip'`, nothing refused it: `ExprSchemaHint`
carries the root object's fields only, so the validator never learns
that `labels` on the hop target is a list.
Route taken: the card's route 2, a lint pass beside
`refuseUndeclaredHopField`. No `ExprSchemaHint` member is added.
- `@objectstack/formula`: new export `findHopListEquality(source,
listLeaves)`. It returns the `list-equality` refusals (the same code,
params, message and rewrite as the root case) for each `==` / `!=`
between a one-hop read `record.REF.LEAF` and a non-null scalar literal,
where `listLeaves` maps the reference REF to the list-valued fields of
its target. The comparison walk the root case used is now shared: it was
moved out of `checkListEquality` into `forEachListEquality`, with no
change in behaviour. `relationship-traversal.ts` gains the
module-internal reader `hopMemberOf`, which is `rootMemberOf` one
segment further.
- `@objectstack/lint`: `refuseHopListEquality` builds that map from the
objects as served (a reference that is itself multi-valued, or that
targets the stored-metadata family, is left out) and runs at the same
two sites as `refuseUndeclaredHopField`: a validation rule's hydrated
`condition` / `when` (nested branches included), and a formula
`expression`.
- `@objectstack/spec`: the ADR-0087 semantic entry
`cel-list-equality-refused` now names the one-hop read in its `surface`
(a validation rule's `condition` / `when` and a field `expression`, REF
single-valued, LEAF list-valued; not a multi-valued reference, a second
hop, a `previous` hop, or a hop at any other site) and states its doors
in `replacement` (`os validate`, `os build`, the object save door; not
the Studio draft check, not the shared-validator half of the MCP
`validate_expression` tool). Prose only: no schema shape changes, and
`check:generated` reports all 14 artifacts up to date.
Reach, measured once (the card asked for this). A hop is served at
exactly two sites: a validation rule predicate and a formula expression.
Every other CEL site (an action's `visible`, a flow condition, a hook
condition) binds the stored id at `record.account`, so this shape is not
a list comparison there.
- On a real ObjectQL write path, with a throwaway probe that is not
committed: the rule `record.account.labels == 'vip'` ACCEPTED the write
both for an account labelled `['vip','eu']` and for one labelled
`['eu']`, so it never fires. The prescribed rewrite REFUSED the VIP
account and ACCEPTED the EU one.
- Doors that now refuse: `os validate` / `os build`, and the object save
door (`runStackExpressionPasses` with `runtimeWriteType: 'object'`,
pinned in the new lint test).
## Tests
- `packages/formula/src/validate-hop-list-equality-36237.test.ts`: a
premise check on the evaluator (a hydrated hop list compared with a
scalar gives a constant), refusals in both operand orders and in both
member spellings, the code and params, a rewrite that evaluates per row
and is not itself refused, and controls (a scalar leaf, null tests,
`in`, a root field, an unmapped reference, two hops, a comprehension
that binds `record`, an empty map, a source that does not compile).
-
`packages/lint/src/validate-expressions.hop-list-equality-36237.test.ts`:
refusals on one hop to a `multiselect` and on one hop to a `multiple:
true` `user` field, with the slot's key path; the prescribed rewrite
passes with zero errors; one hop to a scalar field passes; a conditional
rule's `when`, a formula and the object save door are covered; a
multi-valued reference and a site that serves no hop are controls.
- Ablation, one for each card pin (lint source; the test reads `src`
directly, so no build is needed): deleting the rule-site call turns the
two refusal pins and the when/formula pin red (3 failed); pointing the
leaves at every target field instead of the list-valued ones turns the
two scalar controls red (2 failed). Both mutations were applied and
restored by `scripts/ablation-replace.mjs`: the anchor went 1 to 0, and
the restored blob matched HEAD with an empty `git diff HEAD`.
<details><summary>Readings (local, final head a59d4a8)</summary>
- Dogfood battery at a59d4a8 (the title carries `!`; `pnpm --filter
@objectstack/dogfood test` under the lock, no shard, no path): VERDICT
command-exit 0; Test Files 487 passed, 3 skipped (490); Tests 4121
passed, 68 skipped (4189); no failures.
- `@objectstack/formula` test: Test Files 71 passed (71), Tests 2128
passed (2128). Read at ff7e133; formula source is unchanged since.
- `@objectstack/lint` test: Test Files 228 passed (228); Tests 9476
passed, 5 skipped. Read at d26a320, after the two ledger files were
added; lint source is unchanged since. The 5 skips depend on a built
`dist`.
- `@objectstack/spec` migrations tests: Test Files 5 passed (5), Tests
200 passed (200). `check:generated`: all 14 artifacts up to date.
- `@objectstack/formula` and `@objectstack/lint` typecheck: VERDICT
command-exit 0.
- Derived gate families (`dispatch-gates --commands`): 67 before the
spec entry edit, of which 64 exited 0 and 3 are NOT MEASURED
(`check:dual-build-cjs-loads`, `check:lean-entry-closure`,
`check-plugin-teardown-shape --self-test`; their prerequisite is a
whole-tree build or a deeper clone). Re-derived at a59d4a8 there are
92. The 25 new ones (spec families) all exited 0, two of them after a
re-run once a concurrent build had restored `dist`.
- Re-run at a59d4a8, all exit 0: `check-adr-0087-registration --base
origin/main`, `check-empty-changeset`, `check:nul-bytes`,
`check-affected-docs`, `check-drift-comment`, `check:issue-citations`,
`check:doc-authoring`, `check:changeset-gate-self-tests`.
</details>
## Acceptance notes
- Public API: `findHopListEquality` is a new named export of
`@objectstack/formula`. That package has one entry, and keeping the
refusal there avoids a second copy of its code, params, message and
rewrite in lint. Nothing existing changes shape.
- Narrowing, declared: a source that `os validate`, `os build` or an
object save accepted before is now refused when it compares a
hop-reached list with a scalar. That comparison never fired at runtime
(measured above), so the only rules refused are ones that already did
nothing. The title and the changeset headline carry `!`, and the
changeset carries the BREAKING line with FROM / TO.
- Not reached by this route, by design: Studio's draft check and the
shared-validator half of the MCP `validate_expression` tool. Both judge
the root case through `ExprSchemaHint`, which carries the root object's
fields only. The card's Done-when ("or the condition's author is told at
save") is met at the object save door. The ADR-0087 entry now names the
same doors.
- ADR-0087 disposition: `already-registered cel-list-equality-refused`.
This PR extends that entry's surface and replacement.
- In-repo producers, found by grepping `examples/` and `packages/qa` for
`record.X.Y ==|!=` plus a literal: 4 candidates. One is a hop to a
single `select` at a validation rule (`app-showcase` invoice
`record.account.status`), which is accepted. The other three are
object-valued fields at an action `visible`, which is not a hop site.
None would be refused, and the dogfood battery agrees.
## Verification
Files to read first, ordered by risk:
1. `packages/formula/src/validate.ts`: the `forEachListEquality`
extraction (the root-case behaviour must be byte-identical) and
`findHopListEquality`.
2. `packages/lint/src/validate-expressions.ts`: `refuseHopListEquality`
and its two call sites.
3. `.changeset/36237-hop-list-equality.md`.
Two-minute check: `pnpm --filter @objectstack/lint exec vitest run
src/validate-expressions.hop-list-equality-36237.test.ts`. Expect 10
passed.
---
_Generated by [Claude
Code](https://claude.ai/code/session_011y7As7qKGpBTzxc5S8q3Ko)_
<!-- signed: repo:objectstack#7 · os-alice ·
session_011y7As7qKGpBTzxc5S8q3Ko -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 49c6bf3 commit ad92dfd
10 files changed
Lines changed: 426 additions & 4 deletions
File tree
- .changeset
- packages
- formula/src
- lint/src
- spec/src/migrations/entries/semantic
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
186 | 190 | | |
187 | 191 | | |
188 | 192 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
238 | 238 | | |
239 | 239 | | |
240 | 240 | | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
241 | 262 | | |
242 | 263 | | |
243 | 264 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
1567 | 1567 | | |
1568 | 1568 | | |
1569 | 1569 | | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
1570 | 1626 | | |
1571 | 1627 | | |
1572 | 1628 | | |
| |||
1592 | 1648 | | |
1593 | 1649 | | |
1594 | 1650 | | |
1595 | | - | |
| 1651 | + | |
1596 | 1652 | | |
1597 | 1653 | | |
1598 | 1654 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
198 | 201 | | |
199 | 202 | | |
200 | 203 | | |
| |||
206 | 209 | | |
207 | 210 | | |
208 | 211 | | |
| 212 | + | |
209 | 213 | | |
210 | 214 | | |
211 | 215 | | |
| |||
231 | 235 | | |
232 | 236 | | |
233 | 237 | | |
| 238 | + | |
234 | 239 | | |
235 | 240 | | |
236 | 241 | | |
| |||
547 | 552 | | |
548 | 553 | | |
549 | 554 | | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
550 | 560 | | |
551 | 561 | | |
552 | 562 | | |
| |||
0 commit comments