Repository navigation
Commit 561fe12
fix(formula)!: a flow condition that orders a bare date against text before date arithmetic on record. / previous. is refused (#37840)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoLsK4hT7Ct3Wpss39NMcVHb)_
Fixes #36377
Clause-②: no (narrowing)
Metadata-protocol: narrowed
Skills-docs: none — `skills/objectstack-formula/SKILL.md` already states
"The build refuses `end - start`, `date + n`, `today() + 30`" and names
no site or spelling it is limited to, so it now holds for this
flow-condition spelling as written
repo:objectstack#3 · os-tesla · session_01L9qibz2oLCRAYBpwsBBUyG
## 维护者速读
-
用户能看到什么变化:作者在校验或发布流程时,若流程条件先把日期字段直接和一段日期文字比较、再通过「当前记录」或「修改前记录」对日期加减数字,现在会被拒并提示改用按天计算的函数;以前只有这种混写能通过校验,运行时却每次失败。
- 为什么做:属于「表达式校验与作者护栏」,是上一张同类修复(流程条件里通过记录读日期再加减数字)留下的漏网写法,替编写流程的管理员和代写流程的
AI 助手解决「校验通过、流程每次运行都出错」。
- 出错会怎样:若误判,作者在校验或发布流程时会看到一条拒绝;已保存的流程照常加载、照常注册,只在下次发布时要求改写;本改动可整体撤回。
- 要你做什么:这是收紧已接受写法的破坏性变更,待座位契约审核通过后需要你本人审阅、批准并合并。
## What changes
A flow condition (start, edge, `decision` branch) binds the run's row
twice: its fields flattened to bare names, and the row as `record` (the
row before the write as `previous`). A condition that first orders a
date field's **bare** name against a text literal and then does
arithmetic on a **root** read was refused by no pass:
1. `firstTypeMismatch`'s bare pass met `Timestamp > string` (the bare
ordering) first, and `confirmAgainstDateText` stood it down (the runtime
answers a date text ordered against a text literal).
2. Its record-root pass types bare names and roots together, so it met
the same ordering first, not `isDateArith`, and answered null.
3. `validate.ts`'s bare date-text pass leaves roots `dyn`, so it found
nothing.
4. `recordRootDateTextIssue` asked `recordRootReadsFaultDateArith`,
which types the roots alone, met `record.due_date + 1` first, and stood
down as "answered by `firstTypeMismatch`", which had answered null.
Reproduced on `origin/main` c826e8a before any edit
(`validateExpression('predicate', …)`, flattened scope, `faultOutcome:
'run-fails'`, `due_date: date`):
| condition | before | after (this head) | run on the row's text |
|:---|:---|:---|:---|
| `due_date > "2026-01-01" && record.due_date + 1 > 5` | **0 findings**
| `date-text-arithmetic-run-fails`, `DateText + int`, `record.due_date`
| faults |
| `due_date > "2026-01-01" && previous.due_date - 7 < 0` | **0
findings** | `date-text-arithmetic-run-fails`, `DateText - int`,
`previous.due_date` | faults |
| `due_date > "2026-01-01" && record.picked_up_at + 1 > 5` (datetime) |
**0 findings** | `date-text-arithmetic-run-fails`, `record.picked_up_at`
| faults |
| `record.due_date > "2026-01-01" && record.due_date + 1 > 5` (all-root)
| `date-text-arithmetic-run-fails`, `record.due_date` | unchanged |
faults |
| `due_date > "2026-01-01" && due_date + 1 > 5` (all-bare) |
`date-text-arithmetic-run-fails`, `due_date` | unchanged | faults |
| `record.due_date + 1 > 5 && due_date > "2026-01-01"` (arithmetic
first) | `date-arithmetic-run-fails`, `record.due_date` | unchanged |
faults |
The fix, `packages/formula/src/validate.ts` `recordRootDateTextIssue`:
drop the stand-down. That pass is reached only from
`typeSoundnessIssue`'s `!mismatch` branch, i.e. only where
`firstTypeMismatch` answered null, so "the roots' own typing meets date
arithmetic first ⇒ answered by `firstTypeMismatch`" could only ever
stand down on a fault nobody else refused. Without it, the mixed
spelling takes the all-root spelling's verdict, code and words byte for
byte (pinned). `recordRootReadsFaultDateArith` (`cel-engine.ts`,
internal, not exported from the package entry) had no other caller and
is removed; both docblocks say why.
The verdict family: the dispatch's suggested route was to judge the root
pass's date-arith fault independently of the bare ordering, which would
answer `date-arithmetic` (`Timestamp + int`). I took the card's second
fix direction instead (have the stand-down ask `firstTypeMismatch`'s
actual answer, which is null by construction there), because then the
mixed spelling gets exactly what its all-bare and all-root spellings get
(`date-text-arithmetic`), which is the card's done-when ("refused … like
the other two"). Both families are errors with the same outcome arms and
prescribe `daysBetween` / `addDays`.
One case answers `date-arithmetic` and is pinned so: where a flow
variable holds the bare name (`flowVariables: ['due_date']`), the bare
ordering is not the field's, the record-root pass meets the root
arithmetic first, and it answers `date-arithmetic-run-fails`, as
`record.due_date + 1 > 5` alone does.
-
`packages/spec/src/migrations/entries/semantic/19.flow-condition-bare-ordering-before-record-date-arithmetic-refused.ts`:
the ADR-0087 semantic entry (a structured TODO, no mechanical rewrite),
modelled on #36333's
`18.flow-condition-record-date-arithmetic-refused.ts`.
- `.changeset/36377-flow-bare-ordering-record-date-arithmetic.md`:
`minor` for `@objectstack/formula` and `@objectstack/spec`, both
declaration lines, the Skills-docs line, **BREAKING** banner, FROM → TO
table, `adr-0087: registered
flow-condition-bare-ordering-before-record-date-arithmetic-refused`.
Same shape as #36333's.
Reach: the flattened scope is used only by flow conditions (lint's start
/ edge / `decision` conditions, `registerFlow`'s advisory, the MCP
`validate_expression` `flow_condition` site). Record-scoped sites are
unchanged.
## Tests
- `packages/formula/src/validate.test.ts`, new top-level describe
(#36377): the mixed spelling for `record.` / `previous.` / a datetime
field equals the all-root spelling's verdicts (code, params, message)
and faults in `celEngine.evaluate`; the all-bare spelling's code. Arms:
`run-may-fail` with no declared outcome, `run-fails` kept when bare
names are unproven, `date-arithmetic-run-fails` when a flow variable
shadows the bare name. CONTROL: arithmetic first keeps
`date-arithmetic`; the bare ordering beside `record.due_date < today()`,
`daysBetween(…)`, `addDays(previous.due_date, -7) < today()` is clean.
N3 pinned: the #30025 swap under unproven bare names hands `title > 5 &&
record.due_date + 1 > 5` the root read's `date-arithmetic-run-fails`
(`record.due_date`).
- `packages/lint/src/validate-expressions.test.ts`, new top-level
describe: start, edge and `decision` conditions give the mixed spelling
the all-root spelling's finding (severity, path, message), for `record.`
/ `previous.` / datetime. CONTROL: the bare ordering beside
`record.due_date < today()` is clean at all three sites.
-
`packages/runtime/src/domains/meta-flow-condition-record-date-text.test.ts`,
new top-level describe: the publish door (`publishMetaItem` on the real
`ObjectQL` rig) refuses the mixed spelling for `record.` and `previous.`
with `INVALID_METADATA` / 422, exactly one date-arithmetic issue naming
the root read, the same finding as the all-root spelling's (the message
before its quoted source), and leaves the item `draft`. CONTROL: the
bare ordering beside `record.due_date < today()` publishes and goes
`active`.
<details><summary>Local runs (head 8ca7780)</summary>
Exit codes captured before any pipe; tests, builds and typechecks under
`scripts/pm/os-verify-lock.sh` (the first formula and lint test runs at
2087f66 were not under the lock; the lint file and the formula suite
are unchanged since and the runtime file was rerun under it).
- `pnpm --filter @objectstack/formula exec vitest run --maxWorkers=2`
exit 0, Test Files 72 passed (72), Tests 2155 passed (2155).
- `pnpm --filter @objectstack/lint exec vitest run --maxWorkers=2
src/validate-expressions.test.ts` exit 0, Tests 538 passed (538).
- `packages/runtime`: `vitest run
src/domains/meta-flow-condition-record-date-text.test.ts` VERDICT
command-exit 0, Tests 6 passed (6).
- `pnpm --filter @objectstack/spec exec vitest run src/migrations` Tests
202 passed (202); `pnpm --filter @objectstack/service-automation exec
vitest run src/flow-registration-schema-e2e.test.ts` Tests 7 passed (7);
VERDICT command-exit 0.
- `pnpm --filter @objectstack/formula run typecheck && pnpm --filter
@objectstack/lint run typecheck` VERDICT command-exit 0. `pnpm --filter
@objectstack/runtime run typecheck`: `tsc --noEmit` clean;
`check:test-typecheck` names 3 files this diff does not touch
(`boolean-written-spelling-row-scope.test.ts`,
`meta-object-publish-column-changes.test.ts`,
`organization-ownership-boot-guard.turso-remote.kernel.test.ts`, 1 error
each); the touched test file is not among them. CI's `TypeScript Type
Check` is the verdict.
- `node scripts/pm/dispatch-gates.mjs --commands`: 95 families derived
for this diff; all 95 run, `--ran` reconciliation: "95 derived, 95 run,
0 NOT-MEASURED (a DERIVED zero — all 95 recorded an exit code and none
of them is 3)". Three first answered exit 3 and were rerun to exit 0:
`check-plugin-teardown-shape --self-test` (shallow clone; the fixture
sha fetched), `check:type-check-debt` (queued behind the dogfood hold;
rerun under the lock), `check:dual-build-cjs-loads` (needs the full
build the previous one ran).
- Dogfood battery (the `!` title), head 8ca7780: `pnpm --filter
@objectstack/dogfood test` under the lock, VERDICT command-exit 0, Test
Files 490 passed, 3 skipped (493), Tests 4144 passed, 68 skipped (4212),
no failure.
- `test:repo` not run locally: the diff touches none of its tests; it is
CI's (`Test Core`).
</details>
<details><summary>Ablation (committed first, mutated through
scripts/ablation-replace.mjs, restored to the HEAD blob)</summary>
Subject: the removed stand-down in `recordRootDateTextIssue`
(`packages/formula/src/validate.ts`). Mutation: after the
`RECORD_ROOT_READ_RE` guard, re-insert a stand-down on the roots-only
typing's date-arith answer (`firstTypeMismatch(source, celFieldTypes,
'flattened', every name shadowed)?.category === 'date-arith'`, the
removed predicate's semantics), marker `ABLATION-36377`; anchor 1 to 0,
blob `9fb19fcb8bd1` to `28d00dc285eb`. The formula suite imports
`./validate` from source, so no dist leg. Red: `src/validate.test.ts` 2
failed / 149 passed, the mixed-spelling verdict test and the arm test;
the CONTROL and N3 tests stayed green. Restored: blob `9fb19fcb8bd1` =
`HEAD:packages/formula/src/validate.ts`, `git diff HEAD` empty, marker
count 0.
</details>
## Acceptance notes
- N1 (not fixed, noted): `offendingRecordRead` names the first
`timestamp` field read through a root in field-map order, which can
differ from the field in the arithmetic (`record.borrow_date < today()
&& record.due_date + 1 > 5`). The bare path's `offendingField` has the
same best-effort rule; the verdict and code are right either way.
- N2 (not fixed, noted, behaviour kept as #36333 left it): under
unproven bare names, a source with both a bare-name and a root-read
date-arithmetic fault (`due_date + 1 > 5 && record.due_date + 1 > 5`)
reports the bare verdict at `date-arithmetic-run-may-fail`. Still an
error.
- N3: pinned (above).
- The dispatch's suggested route was replaced (see What changes); its
mechanism read was confirmed by the repro.
## Verification
Read first, by risk:
1. `packages/formula/src/validate.ts`, `recordRootDateTextIssue`: the
removed stand-down (the narrowing itself) and its docblock.
2. `packages/formula/src/cel-engine.ts`: the removed
`recordRootReadsFaultDateArith` and the corrected record-root comment.
3.
`packages/spec/src/migrations/entries/semantic/19.flow-condition-bare-ordering-before-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 36377` shows 4 passing tests.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibz2oLCRAYBpwsBBUyG)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent e86bf99 commit 561fe12
7 files changed
Lines changed: 251 additions & 48 deletions
File tree
- .changeset
- packages
- formula/src
- lint/src
- runtime/src/domains
- 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1427 | 1427 | | |
1428 | 1428 | | |
1429 | 1429 | | |
1430 | | - | |
1431 | | - | |
| 1430 | + | |
| 1431 | + | |
1432 | 1432 | | |
1433 | 1433 | | |
1434 | 1434 | | |
| |||
1604 | 1604 | | |
1605 | 1605 | | |
1606 | 1606 | | |
1607 | | - | |
1608 | | - | |
1609 | | - | |
1610 | | - | |
1611 | | - | |
1612 | | - | |
1613 | | - | |
1614 | | - | |
1615 | | - | |
1616 | | - | |
1617 | | - | |
1618 | | - | |
1619 | | - | |
1620 | | - | |
1621 | | - | |
1622 | | - | |
1623 | | - | |
1624 | | - | |
1625 | | - | |
1626 | | - | |
1627 | | - | |
1628 | | - | |
1629 | | - | |
1630 | | - | |
1631 | | - | |
1632 | | - | |
1633 | | - | |
1634 | | - | |
1635 | | - | |
1636 | | - | |
1637 | | - | |
1638 | | - | |
1639 | 1607 | | |
1640 | 1608 | | |
1641 | 1609 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1411 | 1411 | | |
1412 | 1412 | | |
1413 | 1413 | | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
| |||
920 | 919 | | |
921 | 920 | | |
922 | 921 | | |
923 | | - | |
924 | | - | |
925 | | - | |
926 | | - | |
927 | | - | |
928 | | - | |
929 | | - | |
930 | | - | |
931 | | - | |
932 | | - | |
933 | | - | |
934 | | - | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
935 | 939 | | |
936 | 940 | | |
937 | 941 | | |
| |||
941 | 945 | | |
942 | 946 | | |
943 | 947 | | |
944 | | - | |
945 | 948 | | |
946 | 949 | | |
947 | 950 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7100 | 7100 | | |
7101 | 7101 | | |
7102 | 7102 | | |
| 7103 | + | |
| 7104 | + | |
| 7105 | + | |
| 7106 | + | |
| 7107 | + | |
| 7108 | + | |
| 7109 | + | |
| 7110 | + | |
| 7111 | + | |
| 7112 | + | |
| 7113 | + | |
| 7114 | + | |
| 7115 | + | |
| 7116 | + | |
| 7117 | + | |
| 7118 | + | |
| 7119 | + | |
| 7120 | + | |
| 7121 | + | |
| 7122 | + | |
| 7123 | + | |
| 7124 | + | |
| 7125 | + | |
| 7126 | + | |
| 7127 | + | |
| 7128 | + | |
| 7129 | + | |
| 7130 | + | |
| 7131 | + | |
| 7132 | + | |
| 7133 | + | |
| 7134 | + | |
| 7135 | + | |
| 7136 | + | |
| 7137 | + | |
| 7138 | + | |
| 7139 | + | |
| 7140 | + | |
| 7141 | + | |
| 7142 | + | |
| 7143 | + | |
| 7144 | + | |
| 7145 | + | |
| 7146 | + | |
| 7147 | + | |
| 7148 | + | |
| 7149 | + | |
| 7150 | + | |
| 7151 | + | |
| 7152 | + | |
| 7153 | + | |
| 7154 | + | |
| 7155 | + | |
7103 | 7156 | | |
7104 | 7157 | | |
7105 | 7158 | | |
| |||
0 commit comments