Repository navigation
Commit 97b9d1e
fix(formula)!: a flow condition's record. / previous. date arithmetic is refused as its bare name is (#36333)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1X8UqWLrzTYpuat8L5eLdf2c)_
Fixes #34946
Clause-②: no (narrowing)
Metadata-protocol: narrowed
Skills-docs: none — `skills/objectstack-formula/SKILL.md` already states
"No date arithmetic. The build refuses `date + n` and `end - start`" and
names no site it is limited to, so it now holds for a flow condition's
`record.FIELD` / `previous.FIELD` reads as written
repo:objectstack#4 · os-project-manager ·
session_01FEkQ5pb2t8Z8C64PkPyVt1
## 维护者速读
-
用户能看到什么变化:作者在校验或发布流程时,若流程条件通过「当前记录」或「修改前记录」读取日期字段并直接加减数字,现在会和直接写字段名一样被拒,并提示改用按天计算的函数;以前这种写法能通过校验,运行时却每次失败。
- 为什么做:属于「表达式校验与作者护栏」,替编写流程的管理员和代写流程的 AI
助手解决「校验通过、流程每次运行都出错」的问题,与已修好的日期文本同类问题是同一族。
- 出错会怎样:若误判,作者在校验或发布流程时会看到一条拒绝;已保存的流程照常加载、照常注册,只在下次发布时要求改写;本改动可整体撤回。
- 要你做什么:这是收紧已接受写法的破坏性变更,需要你本人审阅、批准并亲手合并。L1 ACCEPT 7076562103,全量测试 0 失败
7076550688,契约 PASS 7076631700(座位 7,head f278fec);一个不阻塞的遗留写法(main
上同样存在,不是回归)和三个小问题另立 #36377 跟进。
## What changes
A flow condition (start, edge, `decision` branch) is evaluated over a
scope where the run's row is bound twice: its fields flattened to bare
names, and the row itself as `record` (with the row before the write as
`previous`). The date-arithmetic verdict typed the bare names only.
`firstTypeMismatch`'s flattened record-root pass typed `record.FIELD` /
`previous.FIELD` but kept only the text/boolean mismatch, so
`record.due_date + 1 > 5` passed while `due_date + 1 > 5` was refused,
and both fault at run time on the `YYYY-MM-DD` text on every run.
Measured through `validateStackExpressions` (the `os validate` body) on
a record-triggered flow (`record-after-update`), object `library_loan`
with `due_date: date` and `picked_up_at: datetime` (both `required`),
start condition:
| start condition | before (`origin/main` 28ba01f) | after (this
head) |
|:---|:---|:---|
| `due_date + 1 > 5` | 1 error, date arithmetic
`google.protobuf.Timestamp + int`, `due_date` | 1 error (unchanged) |
| `record.due_date + 1 > 5` | 0 | 1 error, same verdict,
`record.due_date` named |
| `previous.due_date + 1 > 5` | 0 | 1 error, same verdict,
`previous.due_date` named |
| `picked_up_at + 1 > 5` (CONTROL, datetime) | 1 error, `picked_up_at` |
1 error (unchanged) |
| `record.picked_up_at + 1 > 5` (CONTROL) | 0 | 1 error, matching the
bare name |
| `previous.picked_up_at + 1 > 5` (CONTROL) | 0 | 1 error, matching the
bare name |
| `record.due_date < today()` (CONTROL) | 0 | 0 |
| `timestamp(record.due_date) < now()` (CONTROL, date-text) | 1 error,
date-text call | 1 error (unchanged, no second finding) |
The datetime control: a `datetime` field is a Timestamp in the type
check exactly as a `date` field is, and its bare name already took the
date-arithmetic verdict, so its root reads now take that verdict too,
word for word with the reference swapped. That is the dispatch's control
("keep whatever verdict the bare name gets for a datetime").
- `packages/formula/src/cel-engine.ts`, `firstTypeMismatch`: the
record-root pass now answers `category: 'date-arith'` when its first
operator fault is date/duration arithmetic against a number
(`isDateArith`), with `field` and `root` from `offendingRecordRead(…,
'timestamp')`. The text/boolean branch is unchanged. The comment that
said the `date-arith` verdict "stays the bare name's alone" is
corrected, and the `root` field's doc and
`recordRootReadsFaultDateArith`'s doc say the root read is answered
there too.
- `packages/formula/src/validate.ts`, `typeSoundnessIssue`: a root
read's date verdict takes the row's arm (`dateArm` with
`bareNamesUnproven` false), as the root read's type mismatch (#30025)
and date-text verdicts (`recordRootDateTextIssue`) already do. So
`record.due_date + 1 > 5` stays `date-arithmetic-run-fails` where bare
names are unproven or a flow variable shadows `due_date`. The bare
name's arm is unchanged.
- No double report: `recordRootDateTextIssue` runs only when
`firstTypeMismatch` answers null, and it already stood down on this
exact shape (`recordRootReadsFaultDateArith`). The #34662 date-text pins
are green and unchanged.
-
`packages/spec/src/migrations/entries/semantic/18.flow-condition-record-date-arithmetic-refused.ts`:
the ADR-0087 semantic entry (a structured TODO; no mechanical rewrite,
since a span in days and a shifted date are different intents), modelled
on `18.cel-list-equality-refused.ts`.
- `.changeset/34946-flow-record-date-arithmetic.md`: `minor` for
`@objectstack/formula` and `@objectstack/spec` (`Metadata-protocol:
narrowed` grades `minor`; spec ships the new ADR-0087 entry in its
generated migration registry), the declaration lines, the **BREAKING**
banner, a FROM to TO table, and `adr-0087: registered
flow-condition-record-date-arithmetic-refused`.
Reach (the dispatch asked to stop if the narrowing reached beyond flow
conditions): the flattened scope is used only by flow conditions.
`@objectstack/lint` passes it for start, edge and `decision` conditions,
`@objectstack/service-automation`'s `registerFlow` (advisory only) and
the MCP `validate_expression` tool's `flow_condition` site. Formula
fields, validation rules, hooks and actions are `record`-scoped, where
`record.due_date + 1` was already refused (`date-arithmetic`,
`-fail-closed`, `-fail-open`). No widening was needed.
## Tests
- `packages/formula/src/validate.test.ts`, new top-level describe
(#34946): `record.` and `previous.` date arithmetic refused under
`date-arithmetic-run-fails` with full params (`operands`, `reference`
naming the read), and the evaluator faults on them over the run's scope.
CONTROL: the datetime field's root reads equal the bare name's verdict.
Arms: `run-may-fail` with no declared outcome, `run-fails` kept on a
root read when bare names are unproven or shadowed. CONTROL:
`record.due_date < today()`, `previous.due_date < today()`,
`date(record.due_date) < now()` and the prescribed rewrites
(`daysBetween(record.due_date, today()) > 5`, `addDays(record.due_date,
1) < today()`, `addDays(previous.due_date, -7) < today()`) are clean.
The date-text shapes keep their one finding (`date-text-call-run-fails`,
`date-text-arithmetic-run-fails`) and `record.title > 5` keeps
`type-mismatch-run-fails`.
- `packages/lint/src/validate-expressions.test.ts`, new top-level
describe: start, edge and `decision` conditions refuse `record.` /
`previous.` at the bare name's path and severity, with the bare name's
message and the reference swapped. Reported under `expression-invalid`
through `runAuthoringRules('build', …)`, the rule body the runtime
publish door runs. CONTROL: datetime root reads equal the bare name's
findings at all three sites; `record.due_date < today()` stays clean;
`timestamp(record.due_date) < now()` keeps exactly one date-text
finding.
-
`packages/services/service-automation/src/flow-registration-schema-e2e.test.ts`,
new top-level describe: `registerFlow` logs the date-arithmetic advisory
for `record.` / `previous.` as for the bare name and still registers.
CONTROL: an ordering against `today()` is not advised.
-
`packages/runtime/src/domains/meta-flow-condition-record-date-text.test.ts`,
new top-level describe (#34946, added at `f278fece6f`): the publish door
(`publishMetaItem` over the real `ObjectQL` engine) refuses the bare
name, `record.due_date` and `previous.due_date` date arithmetic with
`INVALID_METADATA` / 422 and one date-arithmetic issue naming the read,
leaving the item draft. CONTROL: a datetime field's root reads take the
same refusal; `record.due_date < today()` publishes and goes active. The
loan fixture gains one required `date` field `due_date`. Runs at
`f278fece6f`: 4/4 passed; ablating the cel-engine record-root
`isDateArith` branch turns exactly the 2 new tests red, restored to the
HEAD blob with `git diff HEAD` empty and `ablation-dist-preflight
--absent` clean.
Publish door, first measured on head 4426723 as a scratch copy of the
same rig (now committed as the pin above):
| start condition | publish | date-arithmetic finding | row state |
|:---|:---|:---|:---|
| `due_date + 1 > 5` | `INVALID_METADATA` / 422 | `expression-invalid`,
`due_date` | draft |
| `record.due_date + 1 > 5` | `INVALID_METADATA` / 422 |
`expression-invalid`, `record.due_date` | draft |
| `previous.due_date + 1 > 5` | `INVALID_METADATA` / 422 |
`expression-invalid`, `previous.due_date` | draft |
| `picked_up_at + 1 > 5` (CONTROL) | `INVALID_METADATA` / 422 |
`expression-invalid`, `picked_up_at` | draft |
| `record.picked_up_at + 1 > 5` (CONTROL) | `INVALID_METADATA` / 422 |
`expression-invalid`, `record.picked_up_at` | draft |
| `previous.picked_up_at + 1 > 5` (CONTROL) | `INVALID_METADATA` / 422 |
`expression-invalid`, `previous.picked_up_at` | draft |
| `record.due_date < today()` (CONTROL) | published | none | active |
At `f278fece6f` (the patch round: changeset regrade and the runtime
pin): runtime pin 4/4 and its ablation as above; `dispatch-gates
--commands` 98 families derived (one more than at 4426723:
`check:route-envelope`); the families for the changed paths
(`check-adr-0087-registration`, `check-changeset-no-major`,
`check-empty-changeset`, `check:cross-package-test-inputs`,
`check:test-source-alias`, `check:tier-file-adoption`,
`check:route-envelope`) exit 0; `overlap-check` clean. The runs below
and the dogfood battery are from 4426723; the patch round changed
only the changeset and a runtime test file.
<details><summary>Local runs (head 4426723)</summary>
All under `scripts/pm/os-verify-lock.sh`, exit codes captured before any
pipe:
- `pnpm --filter @objectstack/formula build` exit 0; `pnpm --filter
@objectstack/formula test` exit 0, Test Files 70 passed (70), Tests 2067
passed (2067); `pnpm --filter @objectstack/formula typecheck` exit 0
(test layer: 7 errors held in `test-typecheck-debt.json`, unchanged).
- `pnpm --filter @objectstack/lint exec vitest run --maxWorkers=2
src/validate-expressions.test.ts` exit 0, Tests 529 passed (529).
- `pnpm --filter @objectstack/service-automation exec vitest run
--maxWorkers=2 src/flow-registration-schema-e2e.test.ts` exit 0, Tests 7
passed (7).
- `pnpm --filter @objectstack/spec exec vitest run --maxWorkers=2
src/migrations` exit 0, Test Files 5 passed (5), Tests 198 passed (198)
(spec built with the new entry; `gen:migration-registry` runs in its
build).
- `node scripts/pm/dispatch-gates.mjs --commands` derived 97 families
for this diff; all 97 run locally, reconciled with `--ran`: "97 derived,
97 run, 0 NOT-MEASURED, 0 UNRUN". `pnpm check:dual-build-cjs-loads`
first answered PREREQUISITE NOT MET (exit 3, no full build yet), then
exit 0 after `check:type-check-debt` built the tree; every other family
exit 0 on the first run.
- Dogfood battery (the `!` title), on head 4426723: `pnpm --filter
@objectstack/dogfood test` under the lock, VERDICT command-exit 0, Test
Files 484 passed, 3 skipped (487), Tests 4107 passed, 68 skipped (4175),
no failure.
- `test:repo` (vitest `repo` project) not run locally: the diff touches
none of its tests; it is CI's (`Test Core`).
</details>
<details><summary>Ablations (each committed first, mutated through
scripts/ablation-replace.mjs, restored to the HEAD blob)</summary>
1. Subject: the new `isDateArith` branch of the record-root pass
(`packages/formula/src/cel-engine.ts`). Anchor `if (rootTyped &&
isDateArith(rootTyped)) {` replaced by a never-true guard carrying
`ABLATED_34946` (anchor 1 to 0, blob `8eb099d83f32` to `4975d5dd3077`),
formula rebuilt, `ablation-dist-preflight.mjs @objectstack/formula
ABLATED_34946` exit 0 (the marker reached `dist/`, which the lint and
service-automation suites read). Red: formula `validate.test.ts` 3
failed / 236 passed (the three #34946 verdict tests; the CONTROL for
orderings and date-text stayed green), lint 5 failed / 524 passed (all
five non-ordering #34946 tests), service-automation 1 failed / 6 passed
(the advisory test). Restored: blob back to `8eb099d83f32` =
`HEAD:packages/formula/src/cel-engine.ts`, `git diff HEAD` empty,
rebuilt, preflight `--absent` exit 0, lint 529/529 again.
2. Subject: the root read's arm in `typeSoundnessIssue`
(`packages/formula/src/validate.ts`). Anchor `dateArm(scope,
faultOutcome, mismatch.root !== undefined ? false : bareNamesUnproven)`
replaced by `dateArm(scope, faultOutcome, bareNamesUnproven ...)` (blob
`aeedf005910e` to `b35d7d64bb2a`). Red: formula `validate.test.ts` 1
failed / 146 passed, the arm test (`record.due_date + 1 > 5` under
unproven bare names). Restored: blob `aeedf005910e` = HEAD, `git diff
HEAD` empty, 147/147.
</details>
## Acceptance notes
- Kept as before, deliberately: where bare names are unproven and a
source holds both a bare-name date-arithmetic fault and a root-read one
(`due_date + 1 > 5 && record.due_date + 1 > 5`), the first (bare)
verdict is reported, at `date-arithmetic-run-may-fail`. Still an error;
the swap-to-the-root-read step `typeSoundnessIssue` does for a bare type
mismatch was not extended to the date verdict.
- The field a multi-date expression names is best effort, as for the
bare name: `offendingRecordRead` names the first `timestamp` field read
through a root, in field-map order.
- Declarations follow the two closest precedents in this family (#34935,
#36207): `Metadata-protocol: narrowed` with a `minor` changeset
(regraded at `f278fece6f`).
- Carried by #36377: contract review 7076631700 S1 (a bare date ordering
against text AND-ed before a `record.` date arithmetic still passes;
measured first on that card) and nits N1–N3.
## Verification
Read first, by risk:
1. `packages/formula/src/cel-engine.ts`, the new `isDateArith` branch of
`firstTypeMismatch`'s record-root pass (the narrowing itself).
2. `packages/formula/src/validate.ts`, the `dateArm` call in
`typeSoundnessIssue` (the root read's arm).
3.
`packages/spec/src/migrations/entries/semantic/18.flow-condition-record-date-arithmetic-refused.ts`
(the upgrade-guide text).
Two-minute check: `pnpm --filter @objectstack/formula exec vitest run
--maxWorkers=2 src/validate.test.ts -t 34946` shows 4 passing tests.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01FEkQ5pb2t8Z8C64PkPyVt1)_
<!-- signed: repo:objectstack#4 · os-project-manager ·
session_01FEkQ5krBqrrgxCYgjXmfbv -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 7b9e229 commit 97b9d1e
8 files changed
Lines changed: 386 additions & 9 deletions
File tree
- .changeset
- packages
- formula/src
- lint/src
- runtime/src/domains
- 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1339 | 1339 | | |
1340 | 1340 | | |
1341 | 1341 | | |
1342 | | - | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
1343 | 1346 | | |
1344 | 1347 | | |
1345 | 1348 | | |
| |||
1419 | 1422 | | |
1420 | 1423 | | |
1421 | 1424 | | |
1422 | | - | |
1423 | | - | |
1424 | | - | |
1425 | | - | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
1426 | 1432 | | |
1427 | 1433 | | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
1428 | 1443 | | |
1429 | 1444 | | |
1430 | 1445 | | |
| |||
1595 | 1610 | | |
1596 | 1611 | | |
1597 | 1612 | | |
1598 | | - | |
| 1613 | + | |
| 1614 | + | |
1599 | 1615 | | |
1600 | 1616 | | |
1601 | 1617 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | | - | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
1328 | 1329 | | |
1329 | 1330 | | |
1330 | 1331 | | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
535 | 535 | | |
536 | 536 | | |
537 | 537 | | |
538 | | - | |
| 538 | + | |
| 539 | + | |
539 | 540 | | |
540 | 541 | | |
541 | 542 | | |
| |||
612 | 613 | | |
613 | 614 | | |
614 | 615 | | |
615 | | - | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
616 | 620 | | |
617 | 621 | | |
618 | 622 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6966 | 6966 | | |
6967 | 6967 | | |
6968 | 6968 | | |
| 6969 | + | |
| 6970 | + | |
| 6971 | + | |
| 6972 | + | |
| 6973 | + | |
| 6974 | + | |
| 6975 | + | |
| 6976 | + | |
| 6977 | + | |
| 6978 | + | |
| 6979 | + | |
| 6980 | + | |
| 6981 | + | |
| 6982 | + | |
| 6983 | + | |
| 6984 | + | |
| 6985 | + | |
| 6986 | + | |
| 6987 | + | |
| 6988 | + | |
| 6989 | + | |
| 6990 | + | |
| 6991 | + | |
| 6992 | + | |
| 6993 | + | |
| 6994 | + | |
| 6995 | + | |
| 6996 | + | |
| 6997 | + | |
| 6998 | + | |
| 6999 | + | |
| 7000 | + | |
| 7001 | + | |
| 7002 | + | |
| 7003 | + | |
| 7004 | + | |
| 7005 | + | |
| 7006 | + | |
| 7007 | + | |
| 7008 | + | |
| 7009 | + | |
| 7010 | + | |
| 7011 | + | |
| 7012 | + | |
| 7013 | + | |
| 7014 | + | |
| 7015 | + | |
| 7016 | + | |
| 7017 | + | |
| 7018 | + | |
| 7019 | + | |
| 7020 | + | |
| 7021 | + | |
| 7022 | + | |
| 7023 | + | |
| 7024 | + | |
| 7025 | + | |
| 7026 | + | |
| 7027 | + | |
| 7028 | + | |
| 7029 | + | |
| 7030 | + | |
| 7031 | + | |
| 7032 | + | |
| 7033 | + | |
| 7034 | + | |
| 7035 | + | |
| 7036 | + | |
| 7037 | + | |
| 7038 | + | |
| 7039 | + | |
| 7040 | + | |
| 7041 | + | |
| 7042 | + | |
| 7043 | + | |
| 7044 | + | |
| 7045 | + | |
| 7046 | + | |
| 7047 | + | |
| 7048 | + | |
| 7049 | + | |
| 7050 | + | |
| 7051 | + | |
| 7052 | + | |
6969 | 7053 | | |
6970 | 7054 | | |
6971 | 7055 | | |
| |||
0 commit comments