Repository navigation
Commit 4374517
fix(formula)!: flow-condition verdicts agree with the run — severity, the index spelling, macro variables (#39072)
Part of #38959 — items 1, 5 and 2 are fixed here, item 3 is recorded as
accepted fail-open (below), and item 4 (the wording of the
date-against-text ordering verdict) is ruled (7344060050, option A: a
refusal code of its own) and is built in a later `Part of #38959` PR
after this one lands.
Clause-②: no (narrowing)
Metadata-protocol: narrowed
Skills-docs: none — `skills/objectstack-formula/SKILL.md` rule 5 already
says the build refuses date arithmetic and a date field in a
timestamp-only call, with no exception for a source that also carries a
type mismatch; no skill teaches the index spelling, the type-mismatch
warning, or ordering a macro variable over date fields
## 维护者速读
-
用户能看到什么变化:编写流程的管理员在校验或发布流程时,以前「条件里同时有文本比数字的小问题和日期相减的大问题」只给一条警告就能发布、上线后每次运行都失败,现在会直接拒绝(字段显示条件、按钮显示条件、共享规则条件等记录级表达式也同样处理);用下标方式读取文本或布尔字段再和数字比较的写法,现在和点号写法一样被指出;对日期列表逐项和日期文本比较这种能正常运行的写法,在条件里不再被误拒;流程赋值里的取值表达式结论不变。
- 为什么做:属于「表达式校验与作者护栏」,替编写流程的管理员和代写流程的 AI
助手解决「校验通过、上线后每次运行都出错」与「能运行却被拒」两类误判。
-
出错会怎样:若误判,作者在校验或发布时会看到一条拒绝;已保存的流程照常加载注册(取值表达式的结论与改动前一致,不会因本改动在加载时被拒),只在下次发布时要求改写;本改动可整体撤回。
-
要你做什么:这是收紧已接受写法的破坏性变更,待座位契约审核通过、试跑全套通过后,需要你本人审阅并合并;另有一项「日期与文本比较的提示文案」需要你拍板(见报告里的待决问题)。
## What changes
All in `@objectstack/formula` (`validate.ts`, `cel-engine.ts`), plus the
ADR-0087 semantic entry and the changeset.
- **Item 1, precedence** (`typeSoundnessIssue`). The type check reports
one finding per source and asked the text/boolean mismatch first; the
date-text family was asked only when that answered null. Now, over a
mismatch graded a **warning** (no declared outcome: a flow that is not
record-triggered, `bareNamesUnproven`, and every record-scoped site with
no fault outcome: a formula field `expression`, a field `visibleWhen` /
`settledWhen` / `uiReadonlyWhen`, a field
`conditionalFormatting[].condition`, a field group `visibleWhen`, an
action `visible` / `disabled` / `pressed`, a sharing rule `condition`,
the object `uiReadonlyWhen`), the date-text family is asked and its
**error** wins. It is asked with the full field typing, then with only
the date fields typed (text/boolean fields `dyn`), because the check
reports its first fault and a mismatch met first masks the date-text
fault behind it (`record.title > 5 && due_date - borrow_date > ...`).
Only `date-text-arithmetic*` / `date-text-call*` errors are taken (never
`date-duration-value`, pinned). Codes:
`date-text-arithmetic-run-may-fail` / `date-text-call-run-may-fail` on a
flow that is not record-triggered; under `bareNamesUnproven`,
`date-text-arithmetic-run-fails` / `date-text-call-run-fails` over a
`record.FIELD` read and the `-run-may-fail` codes over a bare one;
`date-text-arithmetic` / `date-text-call` at a record-scoped site. A
mismatch graded an **error** keeps its code and words (the
record-triggered arm is unchanged), except one answered by an index read
alone (item 5's new reach): there the date-text family is asked first,
so every code the index spelling had from PR #38949 is kept.
- **Item 5, index reads in the mismatch pass** (`firstTypeMismatch`).
The record-root pass now opens on `RECORD_ROOT_DATE_TEXT_READ_RE`
(member or index) as well as `RECORD_ROOT_READ_RE`. Where only an index
read opened it, it takes the text/boolean mismatch and nothing else:
date arithmetic against a number stays the date-text family's (PR
#38949's codes), and the date-against-text-field ordering (S1,
`record['due_date'] > record['title']`, which evaluates) is not judged
(`confirmAgainstDateText(..., keepUndeclared)`), so S1 stays clean —
that verdict is item 4's question. The index read is named by its member
spelling, as the date-text pass already names it, also where a member
read opened the pass (review S2): `record['title'] > 5 && record.status
== 'open'` names `record.title` and takes `type-mismatch-run-fails`
under `bareNamesUnproven` (it was the warning), and `record['title'] > 5
&& record.notes == 'n'` names `record.title` (it named `record.notes`).
Where two text fields are read the name is the first of them in the
field table, for either spelling alike (stated limit N6, carried by
#39105: `previous.notes > 5 && record['title'] == 'x'` names
`record.title`). Review S3, seat ruling (a): where the mismatch kept is
the ordering of a date against a text field (the `keepUndeclared`
survivor of `confirmAgainstDateText`, #32595's verdict, which the run
answers), an index read does not supply the name (`keptOrdering`), so
`record.due_date > record['title']`, `record['due_date'] >
record['title'] && record.status == 'open'` and `record.due_date > title
&& record['notes'] == 'n'` keep the base's `type-mismatch-run-may-fail`
warning under `bareNamesUnproven`. Done together with item 1, never
before it.
- **Item 2, macro variables** (`comparesDateTextAgainstUndeclared`). A
comparison that reads a variable a macro binds (`all`, `exists`,
`exists_one`, `map`, `filter`) was kept as a mismatch unconditionally.
The variable is now read as an element of the list it ranges over: the
operand is checked with the variable replaced by `RECEIVER[0]` in the
same env, inner macros shadowing the name. `[due_date,
record.borrow_date].exists(d, d > '2026-01-01')` is no longer refused;
`[title].exists(t, t > 5)` and `[due_date].exists(d, d > title)` keep
the verdict their written-out forms take. Where the element does not
check, the verdict is kept as before. This widens flow conditions and
record-scoped sites only (review M1, seat ruling option a):
`firstTypeMismatch` takes `options.macroElements`, and the flow value
envelope's date-text check (`flowValueEnvelopeDateTextIssue`), which
stands down when that check finds a mismatch, asks it with
`macroElements: false`, the typing it had at the merge base. So
`[record.due_date].exists(d, d > '2026-01-01') ?
isoDate(record.picked_up_at) : 'x'` as an assignment value validates and
registers as it did; no flow value envelope verdict changes.
-
`packages/spec/src/migrations/entries/semantic/19.flow-condition-mismatch-warning-and-index-mismatch-refused.ts`:
the semantic entry (structured TODO, no mechanical rewrite), modelled on
PR #38949's.
- `.changeset/38959-flow-condition-verdicts.md` and the entry name every
site and code above, and say that no value envelope verdict changes.
- `.changeset/38959-flow-condition-verdicts.md`: `minor` for formula and
spec, both declaration lines, BREAKING banner, FROM → TO, the
registration marker.
## Tests
`packages/formula/src/validate-date-text-arithmetic.test.ts`, new
top-level describe for #38959 (21 tests): the five hidden-refusal
sources on both arms (no outcome: the date-text error alone;
record-triggered: `type-mismatch-run-fails` unchanged) plus a
no-date-fault control that stays a warning, the record-scoped formula
arm; five index/member pairs equal on three arms with equal params, the
member-parity row for `record['due_date'] > 5`, the masked index order,
PR #38949's index codes kept on three arms; five macro sources clean on
three arms and evaluating `true`, and three that keep their verdict.
Second review round (+1 in the describe, 27 now; file 149): the three S3
sources on the `unproven` arm stay the base's warning and evaluate, with
the member spelling's error as control (S3); `[due_date].exists(d, d >
[title].map(d, d)[0])` stays `type-mismatch-run-fails`, the pin for the
`inner.delete` line (N3). First review round (+5 in the describe): an
index read beside a member read on three arms, named `record.title`
(S2); the family filter, `date-duration-value` under a mismatch warning
stays the warning (N2); an inner macro rebinding the name,
`[due_date].exists(d, d >= [record.borrow_date].filter(d, d >
'2026-01-01')[0])` clean and evaluating (N3); the `bareNamesUnproven`
and record-scope codes (N4); the review's two value envelopes give the
merge-base answer (ok) at `validateExpression(..., { flowValueEnvelope:
true })`, with controls (M1).
`packages/services/service-automation/src/flow-registration-checks.test.ts`:
both values register at `registerFlow`, the date-text fault alone is
refused (M1).
`packages/lint/src/validate-expressions.mismatch-precedence-38959.test.ts`:
a field `visibleWhen`, an action `visible` and a sharing rule
`condition` take the date-text error, the mismatch alone stays a warning
(S1). One PR #38949 assertion that pinned the old reach
(`previous['title'] > 5` not judged) is replaced by the new pin; its M1
and S1 tests are untouched and green.
<details><summary>Second review round at 8755c4d: suites, ablations,
unproven differential, gates</summary>
- At `8755c4de17` (no merge; origin/main not re-merged):
`packages/formula` vitest 72 files, 2238 passed; `pnpm typecheck` exit
0; `packages/lint` vitest 261 files, 10323 passed;
`flow-registration-checks.test.ts` 35 passed; `packages/spec`
`src/migrations` 213 passed; `migrate-meta-engine-guidance.test.ts` 3
passed (it reddened once on a tracker id in the entry's guidance, now
removed; the id stays in the changeset).
- Ablations through `scripts/ablation-replace.mjs` (formula's two test
files, 300 tests, each restored to the HEAD blob with `git diff HEAD`
empty): unmutated 300 passed; S3 guard off (`!keptOrdering` to `true`) 1
failed; only the `inner.delete(macro.name)` line removed 1 failed (the
review's N3 gap); the earlier set unchanged in kind: precedence off 10,
index gate off 6, `keepUndeclared` off 1, dates-only off 2, macro
element typing off 7, index-first date-text off 3, index-only
date-arithmetic guard off 1, index naming off 9, family filter off 1,
shadowing branch off 1, envelope gate dropped 1.
- `unproven` differential, base (merge base, `packages/formula`
identical to `2595004f2e`) against this head: 10,725 generated
conditions (an ordering or arithmetic over member, index, `previous` and
bare reads of text, boolean, date, datetime and number fields and
literals, alone and joined with `&&` to six clauses true on the row):
9,529 same, 36 error to error (code or params), 512 warning to error,
516 clean to error, 132 clean to warning. Each move to a stronger grade
was evaluated on a row that makes every neighbouring clause true (the
`&&` forces the moved clause to run): all 1,160 fault, 0 evaluate.
Against the previous head `90c0977c55` the same set had 240
warning-to-error moves that evaluate, all the ordering of a date against
a text field (S3); 0 now. The `rt`, `none` and `sweep` arms: every move
faults; none weaker.
- Corpus: 6,537 recorded calls 0 changed; 224 generated envelopes 0
changed.
- `check:adr-0087-registration` exit 0; `dispatch-gates --ran` at
`8755c4de17`: 99 derived, 95 run with exit 0, 4 NOT MEASURED
(`check:dual-build-cjs-loads`, `check:query-options-erasure`,
`check:slot-lookup`, `check:type-check-debt`: over the foreground cap or
needing a full build, not started).
</details>
<details><summary>First review round at 90c0977: suites, ablations,
corpus, gates</summary>
- At `90c0977c55` (origin/main `4b8a67d8fa` merged in):
`packages/formula` vitest 72 files, 2237 passed; `pnpm typecheck` exit
0; `packages/lint` vitest 261 files, 10323 passed;
`flow-registration-checks.test.ts` 35 passed;
`migrate-meta-engine-guidance.test.ts` 3 passed.
- Ablations through `scripts/ablation-replace.mjs` (formula's two test
files, 299 tests, each restored to the HEAD blob with `git diff HEAD`
empty): unmutated 299 passed; precedence off 10 failed; index gate off
6; `keepUndeclared` off 1; dates-only pass off 2; macro element typing
off 7; index-first date-text off 3; index-only date-arithmetic guard off
1; index naming off 9; family filter off 1 (review 9, was 0);
inner-macro shadowing off 1 (review 10, was 0); envelope gate
`macroElements: false` dropped 1; naming beside a member read back to
`!memberRead` 1. With the formula rebuilt under the mutation: precedence
off reds the lint pin 3 of 4, the envelope gate dropped reds the
registration pin 2 of 35. The `severity === 'error'` half of the filter
cannot red: every date-text verdict is an error today.
- Corpus, base `2595004f2e` vs this head: the 6,537 recorded calls
(2,446 unique, 11 macros, 46 value envelopes, 14 index reads) 0 changed;
controls 3 of 3 changed. Generated: 224 value envelopes joining 7 macros
to 8 values, 0 changed; 147 conditions with an index read beside a
member read on 5 arms: 495 same, 188 params only (`reference` added or
corrected), 52 warning to error (all `bareNamesUnproven`), none weaker.
- `check:adr-0087-registration` exit 0; `dispatch-gates --ran`: 99
derived, 95 run with exit 0, 4 NOT MEASURED
(`check:dual-build-cjs-loads` needs a full build,
`check:query-options-erasure` exit 124 at my 280s cap,
`check:slot-lookup` and `check:type-check-debt` over the cap last round,
not started).
</details>
<details><summary>First round: suite runs, ablations, door and corpus
readings</summary>
- `pnpm exec vitest run --maxWorkers=2` in `packages/formula`: 72 files,
2232 passed. `pnpm typecheck` (formula, incl. `check:test-typecheck`):
exit 0.
- Lint suite against the head formula build: 260 files, 10318 passed.
Service-automation files that read these verdicts (4): 140 passed.
- Ablations (each mutation landed per `scripts/ablation-replace.mjs`,
restored to the HEAD blob, `git diff HEAD` empty), two test files, 294
tests: precedence off 9 failed; index gate off 6 failed;
`keepUndeclared` off 1 failed (the S1 control); macro element typing off
5 failed; date-only unmasking off 2 failed; index-first date-text off 3
failed (incl. PR #38949's M1 test).
- Door (`os validate --json` on a scratch `defineStack` project, one
flow per source, record-triggered and a time-relative sweep of another
object, all fields required), base `2595004f2e` vs head: item 1 sources
warning only → error (`date arithmetic DateText - DateText`,
`isoDate(...)`); `record['title'] > 5` and `record['active'] + 1 > 3`
clean → error / warning; the masked index order clean → error; the
`.exists` source error / warning → clean. Unchanged: M1 index rows
(refused), S1 rows (clean), `record.due_date > record.title` (refused),
the nullable ternary (clean), `record['due_date'] > 5` (clean, as its
member spelling).
- Corpus: 6,537 recorded `validateExpression` calls (the lint suite, `os
validate` on the five examples, and the service-automation suite up to
where I stopped it), 2,446 unique, re-judged base vs head: 0 changes.
Positive controls appended to the same run: 3 of 3 change (item 1, item
5, item 2 sources), 1 of 1 control unchanged.
</details>
## Acceptance notes
- **Carried elsewhere, not fixed here.** #39107: the value-envelope
shape (a macro over a date read joined to a date-text fault, in a
value), which this PR keeps at its merge-base verdict; it awaits the
maintainer. #39105: the review's N1 (`['2026-01-01'].exists(x, due_date
> x)` refused while it evaluates), N5 residual shapes, and N6, a stated
limit: the name follows field-table order, not the operand at the
faulting operator, so `previous.notes > 5 && record['title'] == 'x'`
names `record.title` (it named `previous.notes`); naming by the operand
is the follow-up there. #39104: item 3's wider shape (Timestamp minus
date text with a left operand that is not a direct call faults on every
row).
- **Item 3, accepted fail-open.** `(status == 'open' ? now() : null) -
record.picked_up_at > duration('1h')` passes and faults. Carrying the
branch type cannot refuse it cleanly: typed as the branch, the check
sees a Timestamp minus a date text, which the evaluator answers when it
can see the Timestamp (`now() - record.picked_up_at > duration('1h')`
evaluates). It faults because the null-ternary rewrite wraps the branch
in `dyn(...)` and the evaluator's Timestamp-vs-date-text coercion does
not look through it (`dyn(now()) - record.picked_up_at` faults the same
way), and the null branch faults on its own (`null - TEXT`). Refusing it
means modelling that wrapper in the check, which is not the branch type;
the operand stays `dyn` and passes by the fail-open law.
- **Item 4, not done here.** The verdict stays (its ruling). Its
sentence is the `type-mismatch*` template, which says "against a number
… the expression faults" and, per arm, that the run fails or the write
is refused; none is true of an ordering that evaluates.
`expression-refusal.ts` says a code names one template, so a true
sentence needs its own code. Ruled 7344060050 (option A, a new refusal
code); built in a later `Part of #38959` PR, which also rewrites the two
comments that still call the question open (review N8).
- A date ordered against a number (`due_date > 5`, `record.due_date >
5`, `record['due_date'] > 5`, `[due_date].exists(d, d > 5)`) passes and
faults in every spelling; the index spelling now takes its member
verdict, which is clean. Reported, not fixed: a new verdict for every
spelling.
- Masked mismatch in the other direction: an ordering of a date against
a number ahead of date arithmetic (`due_date > 5 && due_date -
borrow_date > ...`) is not unmasked by this change.
## Verification
First read (by risk): `packages/formula/src/validate.ts`
(`typeSoundnessIssue`, `dateTextOver`),
`packages/formula/src/cel-engine.ts` (`firstTypeMismatch` root pass with
its `keptOrdering` naming guard and its `macroElements` option,
`comparesDateTextAgainstUndeclared`), and
`flowValueEnvelopeDateTextIssue` in `validate.ts`, the one caller that
asks for the old macro typing, the new describe in
`validate-date-text-arithmetic.test.ts`.
Two minutes: `pnpm --filter @objectstack/formula exec vitest run
--maxWorkers=2 src/validate-date-text-arithmetic.test.ts` — expect 149
passed (27 in the describe named "flow-condition verdicts agree with the
run").
Contract-tier review re-owed at the new head (narrowing), and the
dogfood battery (`!` title).
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QSeKYnrQ7UMtHofKQVjcH2)_
<!-- signed: repo:objectstack@os-justin · os-justin ·
session_01QSeKYnrQ7UMtHofKQVjcH2 -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent f6b008e commit 4374517
7 files changed
Lines changed: 649 additions & 51 deletions
File tree
- .changeset
- packages
- formula/src
- lint/src
- services/service-automation/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 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
0 commit comments