Repository navigation
Commit 65ce798
docs(skills): objectstack-formula says == / != on a list-valued field is refused and teaches the null-guarded membership test (#36354)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9JpRoUZGqtwqMU5k7b4C58D)_
Fixes #36217
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:照着对外发布的公式技能写条件的 AI
作者,现在会被告知「多值字段不能直接拿来和单个值比较相等或不相等」,并按条件所在的位置拿到对应的正确写法:普通条件、流程条件、共享规则条件各一种;此前技能对此只字未提。
-
为什么做:校验器已经开始拒绝这种比较(它在每一行上都得出同一个答案,条件永远不变),这是「多值字段相等比较收紧」那项工作欠下的技能配套,替写多选、标签类字段条件的作者解决「被拒了却不知道该怎么改」的问题;共享规则那一种写法尤其要紧,照普通写法写出来的共享规则不会授予任何人权限。
-
出错会怎样:只改技能文字、两道技能自测题和一条发布说明,不动任何代码与契约;最坏情况是作者读到一段讲得不清楚的说明,直接撤回本次改动即可恢复原文。
- 要你做什么:审批这个受治理的技能改动(技能目录属于需要你亲自批准的范围);席位会先完成自己的核对与达档复审再来请你。
## What changes
`skills/objectstack-formula/SKILL.md`, the published formula skill,
gains a note directly under the CEL cheat-sheet's operator table. It
says that `==` / `!=` between a list-valued field and a scalar literal
is refused, names the refusal as the validator emits it, names which
fields are list-valued, and shows the refused form beside the rewrite
the refusal prescribes at each site, for `==` and for `!=`:
```text
record.tags == 'vip' # REFUSED
# evaluated as CEL; has() covers a sparse action row and a null `previous`
(has(record.tags) && record.tags != null && 'vip' in record.tags)
(!has(record.tags) || record.tags == null || !('vip' in record.tags))
# bare name in a flow condition (has() takes no bare name)
(tags != null && 'vip' in tags)
(tags == null || !('vip' in tags))
# SharingRule `condition`: compiled to a query filter, where has() and a literal-first `in` do not lower
(record.tags != null && record.tags.contains('vip'))
(record.tags == null || !record.tags.contains('vip'))
```
The six rewrites are what `listMembershipRewrite`
(`packages/formula/src/validate.ts`) returns at each site, read on
`origin/main` at 9abc732 after merging it into this branch; the file
is unchanged up to dda5e74. The skill writes the literal single-quoted
where the validator prints it double-quoted; nothing else differs, and a
probe compares the two mechanically (see Tests). The three sites:
- **evaluated as CEL** (a `record.` / `previous.` read): the `in` test,
guarded by `has()` and `!= null`. `has()` is what keeps the test from
faulting on an action's sparse row and on a `previous` that is `null`.
- **a bare name in a flow condition**: the `in` test behind `!= null`
alone, because `has()` takes no bare name.
- **a sharing rule's `condition`**: `.contains()`. That condition is
never evaluated as CEL. It is compiled to a query filter, where `in`
lowers only with a field on its left and `has()` does not lower at all,
so the CEL spelling there is refused at build and the rule grants
nothing. This is the one site lint marks as filter-compiled
(`packages/lint/src/validate-expressions.ts`, the sharing-rule `check`
call).
Every rewrite is parenthesised whole, as the validator writes it, so it
can stand where the comparison stood (`A && (…)`).
The list of list-valued fields is now the full set: `multiselect` /
`checkboxes` / `tags` (`MULTI_OPTION_TYPES`), and `select` / `radio` /
`lookup` / `user` / `file` / `image` with `multiple: true`
(`MULTI_CAPABLE_TYPES`, `packages/spec/src/data/field-value.zod.ts`).
The note no longer offers `.exists()`. The validator prescribes `in` and
`.contains()`, and the eval case grades the `in` spelling.
### Paid for by deletion, ceiling unchanged
The file had 32 tokens of headroom under its ratchet ceiling (6008), and
the note costs more. No ceiling was raised. Twelve restatements were cut
from the same file, each keeping another home. The first six were in the
head reviewed before; the last six pay for the per-site spellings.
| Cut | Where it still lives |
|:---|:---|
| the `has()` section's opening sentence ("true whenever the key
exists") | the cheat-sheet row `Key existence (NOT null-safety)`, the
section heading, and the paragraph that follows |
| the Salesforce-flavor block's clause "`os build` errors with a located
message, and the flow engine throws" | the `Verify your work` section |
| "Hook conditions and validation predicates bind the same two roots" |
the `previous` table directly under it, and the cheat-sheet row
`Previous record (update hooks, validation rules)` |
| "Record-change flow triggers ride the same dispatch" | the `previous`
table's `after*` row, which names the record-change flow trigger |
| "It is a refusal, never a silent downgrade to one hook call" | the
same paragraph's "the platform refuses a predicate write" |
| the translation table's double-quoted-string row | the cheat-sheet row
`String literal` ("CEL parses the double-quoted form too") |
| the stdlib intro's "there is no `src/` to read in an installed app" |
the same sentence's "ships `dist` only" |
| "Use `daysBetween(a, b)` for whole days, two `datetime(…)` for hours
(row below)" in the date-arithmetic note | the table directly under it:
rows `Inclusive span`, `Tenure in years` and `Hours between` |
| the `Sub-day offset` row's "the calendar helpers land on UTC midnight"
| the Dates table rows for `today()`, `daysFromNow(n)` and `daysAgo(n)`,
each "at UTC midnight" |
| the parenthesis "`previous.status`, where `previous` is `null`" in the
unevaluable-condition warning | the `previous` table's insert row:
`null`, and "a column read off it (`previous.x`) has no value and
faults" |
| the second transition-condition code block (`previous.status != 'done'
&& record.status == 'done'`) | the section's first example, the same
shape with another value (`previous.status != 'escalated' &&
record.status == 'escalated'`); the sentence it illustrated stays |
| the first half of the translation table's warning ("`OLD.x` and
`ISCHANGED(x)` both land on `previous.x`, which is `null` on an insert
event") | the `OLD.x` and `ISCHANGED(x)` rows directly above it, and the
`previous` table's insert row; the warning keeps "`previous.x` fails the
write on an insert unless guarded by `previous != null &&`" |
Skill size readings (lines are the measure; tokens as the ratchet counts
them):
| | Before (`origin/main` 9abc732) | After (5dfda71) |
|:---|---:|---:|
| `skills/objectstack-formula/SKILL.md`, lines | 491 | 493 (+2) |
| same file, priced tokens / ceiling | 5976 / 6008 | 6007 / 6008 |
| all `skills/*/SKILL.md`, lines | 4950 | 4952 (+2) |
| ratcheted authored bundle, tokens / ceiling | 197507 / 202541 | 197538
/ 202541 |
| whole shipped tree, tokens | 290262 | 290686 |
`.changeset/36217-formula-skill-list-equality.md`: a `patch` for
`@objectstack/skills`, which ships the `skills/**` tree through its
`dist`. Its text follows the note: the three spellings, the twelve cuts,
the two eval cases.
Two eval cases exercise the note, in
`skills/objectstack-formula/evals/cel-predicates-formulas.json`:
- **13**, a hook `condition` over a `tags` field (evaluated as CEL):
must contain `record.labels != null`, `in record.labels` and the `P`
tag. It now forbids the wrong literal as a wrong answer writes it, the
`P` tag followed by `record.labels == 'urgent'`, and no longer the bare
comparison, which a correct answer names as the thing refused. Its
reference answer is the validator's spelling.
- **14**, a sharing rule `condition` over the same field: must contain
`record.labels != null` and `record.labels.contains(`, and forbids the
wrong literal and a `has(record.labels) &&` guard, which does not lower.
Eval fixtures are measured by the token ratchet, not ratcheted.
## Tests
Nothing here changes tested behaviour, so there is no ablation. Two
throwaway probes, both at 5dfda71.
<details><summary>The six rewrites against the validator, the evaluator
and the filter compiler</summary>
A probe read the six rewrite lines out of the skill file and ran
`validateExpression`, `celEngine.evaluate`, `compileCelToFilter` and
`matchesFilterCondition` from `packages/formula/src` over them (run with
`tsx`, `@objectstack/spec` resolved to its source). Last line: `PROBE
OK: 0 unexpected`.
| Check | Reading |
|:---|:---|
| each line equals `params.rewrite` of the `list-equality` refusal at
its site (quote character aside): CEL site `==` and `!=`, flow site `==`
and `!=`, sharing rule `==` and `!=` | 6 of 6 equal |
| each line is accepted by the validator at its site | 6 of 6 accepted |
| CEL-site lines evaluated on a list holding the value / not holding it
/ empty / `null` / key absent | `==`: `true` / `false` / `false` /
`false` / `false`; `!=`: the negation; no fault |
| CEL-site lines on `previous = null` | `==` `false`, `!=` `true`, no
fault |
| flow-site lines on the same rows bound as top-level names (key absent
does not occur there) | `==`: `true` / `false` / `false` / `false`;
`!=`: the negation |
| sharing-rule lines lowered by `compileCelToFilter` and matched against
the same five rows | lower; match exactly the rows where the value is a
member (`!=`: the others) |
| CONTROL: the two CEL-site lines, and plain `record.tags != null &&
'vip' in record.tags`, handed to `compileCelToFilter` | `not lowered:
unsupported`, all three |
| each type the note names is refused: `multiselect`, `checkboxes`,
`tags`; `select`, `radio`, `lookup`, `user`, `file`, `image` with the
field named multi-valued | 9 of 9 refused as `list-equality` |
| CONTROL: the six multi-capable types, not multiple | 0 of 6 refused |
</details>
<details><summary>The eval file's reference answers under its own
grader</summary>
`gradeAnswer` (`packages/qa/scenarios/src/skill-evals/grade.ts`) over
each case's `expected_output`, cases parsed by the runner's own
`parseEvalFile`:
| Tree | Reading |
|:---|:---|
| d319685 (the head reviewed before; control) | cases 1 to 12 PASS;
case 13 FAIL, `forbidden=["record.labels == 'urgent'"]` |
| 5dfda71 | cases 1 to 14 PASS |
Named answers at 5dfda71, each graded as expected: case 13 passes the
note's CEL spelling and the plain null-guarded `in` spelling, and fails
the refused form and the `.contains()` spelling; case 14 passes the
note's `.contains()` spelling (single- or double-quoted, with or without
the `P` tag), and fails the CEL spelling, a `has()`-guarded
`.contains()` and the refused form.
</details>
## Acceptance notes
- The cuts fall outside the operator-table area the claim's file surface
describes, inside the same file. They are the payment the ratchet asks
for; each row above names the surviving home.
- After this change the file's headroom is 1 token (4 bytes).
- Not taught, for the byte budget: at a sharing rule the validator
passes a number or boolean literal to `.contains()` as its text
(`record.f == 3` becomes `record.f.contains("3")`); and at a flow
condition the refusal fires only where the run is proven to bind a row
of the typed object. Neither changes what an author should write for a
text value; the refusal's own message carries the exact rewrite in both
cases.
- The card's two bare membership forms (`'x' in record.tags`,
`record.tags.exists(t, t == 'x')`) are accepted by the validator and
fault on a `null` list. The skill teaches the validator's guarded forms
and does not offer `.exists()`. Noted here and not filed.
- Read, not measured: the skill's "Surfaces" section says an unevaluable
`SharingRule` `condition` "aborts the write". The lint rule for sharing
rules (`packages/lint/src/validate-sharing-rule-enforceability.ts`)
describes a different outcome for a condition that does not lower: a
build error, and at runtime a rule that is skipped and grants nothing,
with one WARN line. That sentence is outside this card and was left as
it is. Noted here and not filed.
- `main` moved from 9abc732 to dda5e74 after the merge. The seven
commits touch no file under `skills/`, `packages/formula/`, the
sharing-rule call in lint, the eval grader or the token ratchet, so the
branch was not merged again.
## Verification
Read first: the new note under the cheat-sheet table in
`skills/objectstack-formula/SKILL.md` beside `listMembershipRewrite` in
`packages/formula/src/validate.ts`, then the twelve deletions in the
same diff, then cases 13 and 14 in the eval file.
Two-minute check: `node scripts/check-skills-token-ratchet.mjs` — expect
the formula row to read `6007 / 6008` and every file within its ceiling.
<details><summary>Local gates at 5dfda71</summary>
The derived set (`node scripts/pm/dispatch-gates.mjs --commands`, 49
commands) was run in full; `--ran` reconciliation: "49 derived
famil(ies) accounted for — 44 run, 5 NOT-MEASURED (5 DERIVED from a
recorded exit 3)". 44 exited 0, among them `node
scripts/check-skills-token-ratchet.mjs` ("6007 tokens (ceiling 6008;
headroom 1)"), `pnpm --filter @objectstack/spec run check:skill-docs`
("Skill docs in sync"), `pnpm check:skill-links`, `pnpm
check:skill-identifier-liveness`, `pnpm check:skill-compatibility`,
`pnpm check:skill-frame-sync`, `pnpm check:doc-authoring`, `pnpm
check:nul-bytes`, `pnpm check:published-files`, `node
scripts/check-empty-changeset.mjs --base origin/main`, `node
scripts/check-changeset-no-major.mjs --base origin/main`.
NOT MEASURED locally (exit 3, prerequisite not met: each reads built
package output): `pnpm --filter @objectstack/lint run
check:doc-formula-expressions`, `pnpm check:dts-closure`, `pnpm
check:dual-build-cjs-loads`, `pnpm check:lean-entry-closure`, `pnpm
check:sourcemap-no-sources-content`. The build they need never got the
container's shared verify lock: three waits of 5, 540 and 540 seconds,
all `queue-timeout`, behind one dogfood run that held the lock for more
than 80 minutes. CI ran them on this head: all 29 completed check-runs
on 5dfda71 are `success` (16 more are skipped), among them Lint & Repo
Gates, Lint · docs & code guards, Lint · repo & tooling gates, Lint · PM
dispatch-gates, TypeScript Type Check, Type Check · source gates, Build
Core, Test Core, Check Changeset and Governed Surface Queue Guard.
Outside the derived set: `pnpm --filter @objectstack/spec run
check:skill-refs` exit 0 ("10 generated files in sync").
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01ADHkmRY38EZf38Yy3zthbY
<!-- signed: repo:objectstack#2 · os-steve ·
session_01ADHkmRY38EZf38Yy3zthbY -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent ee651ce commit 65ce798
3 files changed
Lines changed: 69 additions & 27 deletions
File tree
- .changeset
- skills/objectstack-formula
- evals
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
85 | 103 | | |
86 | 104 | | |
87 | 105 | | |
88 | 106 | | |
89 | 107 | | |
90 | 108 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | 109 | | |
95 | 110 | | |
96 | 111 | | |
| |||
140 | 155 | | |
141 | 156 | | |
142 | 157 | | |
143 | | - | |
144 | | - | |
| 158 | + | |
145 | 159 | | |
146 | 160 | | |
147 | 161 | | |
| |||
166 | 180 | | |
167 | 181 | | |
168 | 182 | | |
169 | | - | |
| 183 | + | |
170 | 184 | | |
171 | 185 | | |
172 | 186 | | |
173 | 187 | | |
174 | 188 | | |
175 | 189 | | |
176 | 190 | | |
177 | | - | |
| 191 | + | |
178 | 192 | | |
179 | 193 | | |
180 | 194 | | |
| |||
278 | 292 | | |
279 | 293 | | |
280 | 294 | | |
281 | | - | |
282 | | - | |
| 295 | + | |
283 | 296 | | |
284 | 297 | | |
285 | 298 | | |
| |||
321 | 334 | | |
322 | 335 | | |
323 | 336 | | |
324 | | - | |
325 | | - | |
| 337 | + | |
326 | 338 | | |
327 | 339 | | |
328 | 340 | | |
| |||
336 | 348 | | |
337 | 349 | | |
338 | 350 | | |
339 | | - | |
| 351 | + | |
340 | 352 | | |
341 | 353 | | |
342 | 354 | | |
| |||
345 | 357 | | |
346 | 358 | | |
347 | 359 | | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
| 360 | + | |
355 | 361 | | |
356 | 362 | | |
357 | 363 | | |
358 | 364 | | |
359 | | - | |
360 | | - | |
| 365 | + | |
361 | 366 | | |
362 | 367 | | |
363 | 368 | | |
| |||
369 | 374 | | |
370 | 375 | | |
371 | 376 | | |
372 | | - | |
373 | | - | |
| 377 | + | |
374 | 378 | | |
375 | 379 | | |
376 | 380 | | |
| |||
388 | 392 | | |
389 | 393 | | |
390 | 394 | | |
391 | | - | |
392 | 395 | | |
393 | 396 | | |
394 | 397 | | |
| |||
397 | 400 | | |
398 | 401 | | |
399 | 402 | | |
400 | | - | |
401 | | - | |
402 | | - | |
| 403 | + | |
| 404 | + | |
403 | 405 | | |
404 | 406 | | |
405 | 407 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
123 | 143 | | |
124 | 144 | | |
125 | 145 | | |
0 commit comments