Repository navigation
Commit c809deb
fix(formula)!: a flow condition's record. / previous. read of a date field takes the date-text verdicts, so timestamp(record.DATE_FIELD) is refused as its bare name is (#34935)
Fixes #34662
Clause-②: no (narrowing)
Metadata-protocol: narrowed
Skills-docs: none — `skills/objectstack-formula/SKILL.md` already states
the `date-text-call` rule (a `date` / `datetime` field handed to a
timestamp-only call, and `timestamp()` over a `date` field) with
`record.FIELD` spellings and names no site it is limited to, so it now
holds for a flow condition's root reads as written
## 维护者速读
- 改了什么:flow 条件(start / edge / `decision` 分支)里通过 `record.FIELD` /
`previous.FIELD` 读日期字段时,现在与裸字段名一样接受 date-text
这一族校验;`timestamp(record.borrow_date) < now()`(`borrow_date` 为 date 字段)在
`os validate` 和 flow 发布门被拒,错误码、措辞、结果分支(`date-text-call-run-fails`
等)与裸名写法相同,提示改写为 `date(record.borrow_date)` 或
`isoDate(addDays(record.borrow_date, N))`。
- 为什么改:运行时 date 字段是 `YYYY-MM-DD` 文本,`timestamp()` 解析不了,这条 flow
每次运行都失败;裸名写法早已被拒,`record.` 写法却零告警通过。
- 风险与回滚:收窄(BREAKING,按 minor 发布):以前能通过 `os validate` 和发布的 flow 条件,若经
`record.` / `previous.` 把 date 字段交给 `timestamp()`(或交给
`isoDate()`、做文本日期运算),现在被拒,直到改写为 `date(record.FIELD)`;`registerFlow` 仍只记
advisory 日志、照常注册,已存的 flow 在下次发布前继续运行。datetime 字段、`date(...)`
改写、Timestamp 类型已判的形状(`record.due_date + 1`)不受影响。回滚即 revert 本 PR。
- 先看:`packages/formula/src/validate.ts`(`recordRootDateTextIssue` 与
`typeSoundnessIssue`
的接入点)、`packages/formula/src/cel-engine.ts`(`firstDateTextCall` /
`firstDateTextVerdict` 新增的 `recordRootTypes` 参数与
`recordRootReadsFaultTimestampTyping`)、`.changeset/34662-flow-record-date-text.md`。
- 两分钟验证:`pnpm --filter @objectstack/formula exec vitest run
--maxWorkers=2 src/validate-date-text-arithmetic.test.ts -t 34662`,预期 6
个用例全部通过。
- 需要你做的:无,席位落地(受管面未触及);本 PR 是收窄,落地前需一次契约复审记录,由席位路由。
## What changes
A flow condition 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-text
family (`date-text-call*`, `date-text-arithmetic*`) typed the bare names
only. Measured on `origin/main` fc5913e through
`validateStackExpressions`, with the card's fixture (`library_loan`,
`borrow_date: date`, `picked_up_at: datetime`, start
`record-after-update`):
| start condition | findings before | findings after |
|:---|:---|:---|
| `timestamp(record.borrow_date) < now()` | 0 | 1 error,
`record.borrow_date` named |
| `timestamp(borrow_date) < now()` | 1 error | 1 error (unchanged) |
| `timestamp(previous.borrow_date) < now()` | 0 | 1 error,
`previous.borrow_date` named |
| `timestamp(record.picked_up_at) < now()` (CONTROL) | 0 | 0 |
The same holds on an edge condition and on a `decision` branch. The
other members of the family missed root reads the same way and are
covered by the same change: `isoDate(record.picked_up_at) == '...'` (0
findings before; the bare `isoDate(picked_up_at)` was refused) and
`record.due_date - record.borrow_date > duration('24h')` (no date-text
finding before).
- `packages/formula/src/validate.ts`: `typeSoundnessIssue` runs a
record-root pass after the bare-name date-text pass, at flattened scope
only: `recordRootDateTextIssue`. It types `record.FIELD` /
`previous.FIELD` with every field's type (a flow variable shadows a bare
name, never a root member), leaves every bare name `dyn`, and keeps only
`date-text-call*` / `date-text-arithmetic*`. This is the record-root
pass `firstTypeMismatch` already runs for the text/boolean mismatch,
applied to the date-text family. The outcome arm is the row's (`dateArm`
with `bareNamesUnproven` false), as a root read keeps its outcome for
`type-mismatch`. A shape the Timestamp typing of the roots already
faults on (`record.due_date + 1`) belongs to the `date-arithmetic`
family and stands down, the same order the flow value envelope uses.
`dateTextIssue` / `dateTextCallIssue` take the optional root typing, and
the message names the read as written (`verdict.root`).
- `packages/formula/src/cel-engine.ts`: `firstDateTextVerdict` and
`firstDateTextCall` take an optional `recordRootTypes` (flattened scope
only) and pass it to `buildTypedEnv`. On that pass a root read qualifies
by the root typing alone, so an `input.FIELD` read does not qualify.
Without the argument every call is unchanged. `DateTextVerdict` gains
the optional `root`. `recordRootReadsFaultTimestampTyping` is the
stand-down probe. None of these is on the package's public entry.
- `.changeset/34662-flow-record-date-text.md`: `minor` for
`@objectstack/formula` (the kind `narrowed` takes at least `minor`),
with the declaration lines, the **BREAKING** banner, a FROM to TO table
and the ADR-0087 disposition `already-registered` naming the three
semantic entries (`formula-timestamp-date-only-refused`,
`formula-date-text-call-refused`, `formula-date-subtraction-refused`).
Their `surface` text already names flow conditions among the predicates
judged with field types, spelled with `record.FIELD`, so it is left as
is: this change makes that text true for a root read. No entry,
generated file or registry changes.
No producer change was needed outside `packages/formula`.
`@objectstack/lint` (`os validate`, and the runtime publish gate that
runs the same `runStackExpressionPasses` body) and
`@objectstack/service-automation` (`registerFlow`) already hand flow
conditions the flattened hint with field types and the declared outcome.
The fix reaches all three through the shared validator.
## Tests
- `packages/formula/src/validate-date-text-arithmetic.test.ts`: new
top-level describe in the date-text harness. `record.` and `previous.`
over a date field are refused under `date-text-call-run-fails` with full
params (call, reference, rewrite, shift), and the evaluator faults on
them over the run's scope. CONTROL: `datetime` and the prescribed
`date(...)` parse are clean and evaluate to `true`. Arm pins:
`run-may-fail` with no declared outcome; `run-fails` kept on a root read
when bare names are unproven. A flow variable shadowing the bare name
leaves the root read judged. `isoDate(record.picked_up_at)` and
root-read date-text arithmetic are refused. The stand-downs
(`record.due_date + 1`, an `input.` read) take no date-text code.
- `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 shift text.
Rule id `expression-invalid` through `runAuthoringRules('build', ...)`.
CONTROL: `datetime` stays clean through either root at all three sites.
-
`packages/runtime/src/domains/meta-flow-condition-record-date-text.test.ts`
(new; the flow publish door, `saveMetaItem` then `publishMetaItem` over
the real engine): the bare name, `record.` and `previous.` are each
refused with `{ code: 'INVALID_METADATA', status: 422 }`, one
`expression-invalid` date-text issue each, and the item left `draft`.
CONTROL: `datetime` through either root publishes (`active`).
-
`packages/services/service-automation/src/flow-registration-schema-e2e.test.ts`:
new describe. `registerFlow` logs the date-text advisory for `record.` /
`previous.` as for the bare name and registers the flow. CONTROL:
`datetime` is not advised.
Ablation, after the fix was committed (`scripts/ablation-replace.mjs
--hold`, trap restore): the record-root pass was disabled in
`validate.ts` (call guarded by a literal that never equals the source),
`@objectstack/formula` rebuilt, and `ablation-dist-preflight.mjs`
confirmed the marker in `dist/index.js` and `dist/index.mjs`. Result:
formula 4 failed / 83 passed, lint 4 failed / 1 passed,
service-automation 1 failed / 4 passed, runtime 1 failed / 1 passed.
Every refusal pin went red and every CONTROL stayed green. Restore: blob
equal to HEAD, `git diff HEAD` empty, rebuilt, `--absent` preflight
clean, `git status --porcelain` empty.
## Acceptance notes
- **Declaration (seat ruling, L1 REWORK round 1).** `Clause-②: no
(narrowing)`, `Metadata-protocol: narrowed`: a pure narrowing, since the
new `recordRootTypes` parameter is on non-exported functions and nothing
published widens. A contract-review-tier L2 review is owed before the
queue; the seat routes it.
- **The publish door for a flow condition is `publishMetaItem` (seat:
accepted as landed).** `registerFlow` logs a condition's schema-aware
findings as an advisory and never throws, by contract (#1928,
`flow-registration-checks.ts`); it does not refuse the bare spelling
either. The refusal with `code` / `status` is the metadata publish gate
(`INVALID_METADATA` / 422), pinned in `packages/runtime`; `registerFlow`
is pinned for advisory parity.
- **Test placement.** The dispatch asked for a new test file named after
the card. AGENTS.md (ruling record 6583487846) puts a new pin for a
component that already has a shared harness into that file as a
top-level `describe`. So the formula, lint and `registerFlow` pins went
into their existing harnesses. The publish-door pin is a new file,
because no harness pins a flow condition's date verdict at that door.
- The `record` root is typed even when a flow declares a variable named
`record`. The `type-mismatch` record-root pass has always done the same,
and this change does not alter it.
- Same-shape gap outside this family, not fixed here: the
`date-arithmetic` verdict (Timestamp typing, `due_date + 1 > 5`) refuses
the bare name in a flow condition but not `record.due_date + 1 > 5` /
`previous.due_date + 1 > 5`. Measured on this branch with a `required`
date field: 1 error and 0 / 0 findings. The seat files it; this family
stands down on that shape so as not to change its code.
## Verification
Final head 60d4e1c. Dogfood battery on it (the `(narrowing)` arm):
`pnpm --filter '@objectstack/dogfood^...' build` then `pnpm --filter
@objectstack/dogfood test` under the lock, VERDICT command-exit 0, Test
Files 479 passed / 3 skipped (482), Tests 4072 passed / 68 skipped
(4140). Merged-head (653f1fb) package tests and typechecks: formula
68 files / 1878 tests, lint `validate-expressions.test.ts` 505/505,
service-automation e2e 5/5, runtime publish-door 2/2, all four
typechecks green. Gate readings and CI: the os-dev-report comments on
the card.
<details><summary>Premise table on origin/main fc5913e (built lint
dist)</summary>
```
[start] timestamp(record.borrow_date) LT now() -> 0
[start] timestamp(borrow_date) LT now() -> 1 (error, `borrow_date` is a date field ...)
[start] timestamp(record.picked_up_at) LT now() -> 0
[start] timestamp(previous.borrow_date) LT now() -> 0
[edge] same three rows: 0 / 1 / 0
```
(LT spells the less-than operator.)
</details>
<details><summary>After the fix (same probe)</summary>
```
[start] timestamp(record.borrow_date) LT now() -> 1 error, `record.borrow_date` is a date field
[start] timestamp(borrow_date) LT now() -> 1 error
[start] timestamp(record.picked_up_at) LT now() -> 0
[start] timestamp(previous.borrow_date) LT now() -> 1 error, `previous.borrow_date` is a date field
[start] timestamp(previous.picked_up_at) LT now() -> 0
[edge] identical
```
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_012MmDsS4GoHCgYwA2uv3n3C)_
<!-- signed: repo:objectstack#4 · os-lizheng ·
session_012MmDsS4GoHCgYwA2uv3n3C -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent dc53d4a commit c809deb
7 files changed
Lines changed: 583 additions & 27 deletions
File tree
- .changeset
- packages
- formula/src
- lint/src
- runtime/src/domains
- services/service-automation/src
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1255 | 1255 | | |
1256 | 1256 | | |
1257 | 1257 | | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
1258 | 1266 | | |
1259 | 1267 | | |
1260 | 1268 | | |
| |||
1408 | 1416 | | |
1409 | 1417 | | |
1410 | 1418 | | |
1411 | | - | |
1412 | | - | |
1413 | | - | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
1414 | 1423 | | |
1415 | 1424 | | |
1416 | 1425 | | |
| |||
1510 | 1519 | | |
1511 | 1520 | | |
1512 | 1521 | | |
| 1522 | + | |
| 1523 | + | |
1513 | 1524 | | |
1514 | 1525 | | |
1515 | | - | |
1516 | | - | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
1517 | 1531 | | |
1518 | 1532 | | |
1519 | 1533 | | |
| |||
1535 | 1549 | | |
1536 | 1550 | | |
1537 | 1551 | | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
1538 | 1557 | | |
1539 | 1558 | | |
1540 | 1559 | | |
1541 | 1560 | | |
1542 | 1561 | | |
| 1562 | + | |
1543 | 1563 | | |
1544 | 1564 | | |
| 1565 | + | |
1545 | 1566 | | |
1546 | | - | |
| 1567 | + | |
1547 | 1568 | | |
1548 | 1569 | | |
1549 | 1570 | | |
1550 | 1571 | | |
1551 | | - | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
1552 | 1576 | | |
1553 | | - | |
| 1577 | + | |
1554 | 1578 | | |
1555 | 1579 | | |
1556 | 1580 | | |
1557 | | - | |
| 1581 | + | |
1558 | 1582 | | |
1559 | 1583 | | |
1560 | 1584 | | |
1561 | 1585 | | |
1562 | 1586 | | |
1563 | 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 | + | |
1564 | 1619 | | |
1565 | 1620 | | |
1566 | 1621 | | |
| |||
1622 | 1677 | | |
1623 | 1678 | | |
1624 | 1679 | | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
1625 | 1687 | | |
1626 | 1688 | | |
1627 | 1689 | | |
1628 | 1690 | | |
1629 | 1691 | | |
1630 | 1692 | | |
| 1693 | + | |
1631 | 1694 | | |
1632 | 1695 | | |
1633 | | - | |
1634 | | - | |
1635 | | - | |
1636 | | - | |
1637 | | - | |
1638 | | - | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
1639 | 1709 | | |
1640 | | - | |
| 1710 | + | |
1641 | 1711 | | |
1642 | | - | |
| 1712 | + | |
1643 | 1713 | | |
1644 | 1714 | | |
1645 | 1715 | | |
| |||
1655 | 1725 | | |
1656 | 1726 | | |
1657 | 1727 | | |
1658 | | - | |
| 1728 | + | |
1659 | 1729 | | |
1660 | 1730 | | |
1661 | 1731 | | |
| |||
1672 | 1742 | | |
1673 | 1743 | | |
1674 | 1744 | | |
1675 | | - | |
| 1745 | + | |
1676 | 1746 | | |
1677 | 1747 | | |
1678 | 1748 | | |
| |||
0 commit comments