Skip to content

Commit 561fe12

Browse files
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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
'@objectstack/formula': minor
3+
'@objectstack/spec': minor
4+
---
5+
6+
fix(formula)!: a flow condition that orders a bare date field against text before date arithmetic on `record.FIELD` or `previous.FIELD` is now refused, as its all-bare and all-root spellings already were
7+
8+
Clause-②: no (narrowing)
9+
Metadata-protocol: narrowed
10+
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
11+
12+
<!-- adr-0087: registered flow-condition-bare-ordering-before-record-date-arithmetic-refused -->
13+
14+
**BREAKING** accept-set narrowing. In a flow condition (a start, edge or `decision` branch condition) the run binds the record's fields under their bare names and also as `record`, with the row before the write as `previous`. A condition that first orders a `date` or `datetime` field's bare name against a text literal and then does arithmetic against a number on a `record.FIELD` / `previous.FIELD` read, such as `due_date > "2026-01-01" && record.due_date + 1 > 5`, passed `os validate` and the publish door with no finding. The flow then failed on every run, because the field reaches the run as its text and the evaluator cannot add a number to it. The all-bare spelling (`due_date > "2026-01-01" && due_date + 1 > 5`) and the all-root spelling (`record.due_date > "2026-01-01" && record.due_date + 1 > 5`) were refused already.
15+
16+
- **The verdict.** The mixed spelling now gets the all-root spelling's verdict: `date-text-arithmetic-run-fails` on a record-triggered flow or a sweep of the typed object, `date-text-arithmetic-run-may-fail` elsewhere, naming the read as written. A root read keeps the row's arm where bare names are unproven. Where a flow variable holds the bare name, the ordering is not the field's, and the root read's arithmetic takes `date-arithmetic-run-fails`, as `record.due_date + 1 > 5` alone does.
17+
- **Where.** `os validate` / `os build` (`validateStackExpressions`) report an `error`, and the flow publish door refuses the publish with `INVALID_METADATA` (422). `registerFlow` logs it as an advisory and still registers the flow, so a stored flow keeps its run-time behaviour until it is next published.
18+
- **Not refused.** The same bare ordering beside an ordering of the root read (`due_date > "2026-01-01" && record.due_date < today()`), and `daysBetween` / `addDays` over it. The run-time evaluator is unchanged.
19+
20+
## FROM → TO
21+
22+
| FROM | TO |
23+
|:---|:---|
24+
| `due_date > "2026-01-01" && record.due_date + 1 > 5` | `due_date > "2026-01-01" && daysBetween(record.due_date, today()) > 5` (days past due) or `due_date > "2026-01-01" && addDays(record.due_date, 1) < today()` (a shifted date) |
25+
| `due_date > "2026-01-01" && previous.due_date - 7 < today()` | `due_date > "2026-01-01" && addDays(previous.due_date, -7) < today()` |
26+
27+
One-line fix: in a flow condition, never add or subtract a number on a date field read through `record` or `previous`, whatever precedes it; use `daysBetween(a, b)` for a span and `addDays(d, n)` to shift a date.

‎packages/formula/src/cel-engine.ts‎

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,8 +1427,8 @@ export function firstTypeMismatch(
14271427
// against a number — `record.due_date + 1` faults on the field's text on
14281428
// every run exactly as `due_date + 1` does. Either names the read as
14291429
// written (`root`). The date-text family reaches the roots through
1430-
// `validate.ts`'s record-root pass (#34662), which stands down on the
1431-
// date-arith shape answered here ({@link recordRootReadsFaultDateArith}).
1430+
// `validate.ts`'s record-root pass (#34662), asked only where this answers
1431+
// null (#36377).
14321432
if (scope !== 'flattened' || !RECORD_ROOT_READ_RE.test(source)) return null;
14331433
const rootTyped = unsoundOverload(buildTypedEnv(bareTypes, 'flattened', 'timestamp', fieldCelTypes));
14341434
if (rootTyped && isDateArith(rootTyped)) {
@@ -1604,38 +1604,6 @@ export function firstDateTextVerdict(
16041604
}
16051605
}
16061606

1607-
/**
1608-
* [#34662] Whether the FIRST operator fault the Timestamp typing of a flattened
1609-
* condition's `record.<field>` / `previous.<field>` reads meets (every bare
1610-
* name `dyn`) is date/duration arithmetic against a number ({@link isDateArith})
1611-
* — `record.due_date + 1`. That shape is the `date-arithmetic` family's, and it
1612-
* is exactly where the bare name's own order stops: {@link firstTypeMismatch}
1613-
* answers `date-arith` there (for the root read too, #34946) and the date-text
1614-
* check is never asked. Any other
1615-
* Timestamp-typing fault — `record.end_date - record.start_date > 3` (a Duration
1616-
* ordered against a number), `record.d >= "2026-01-01"` (the text ordering the
1617-
* runtime answers) — leaves the bare name's mismatch check at null and the
1618-
* date-text check asked, so it does not stand the record-root pass down
1619-
* either. `false` when the source does not parse.
1620-
*/
1621-
export function recordRootReadsFaultDateArith(
1622-
source: string,
1623-
recordRootTypes: Readonly<Record<string, FieldCelType>>,
1624-
): boolean {
1625-
if (typeof source !== 'string' || !source.trim()) return false;
1626-
try {
1627-
const result = buildTypedEnv({}, 'flattened', 'timestamp', recordRootTypes)
1628-
.parse(rewriteNullableTernary(rewriteIndexedHas(source))).check?.() as
1629-
| { valid?: boolean; error?: { message?: string } }
1630-
| undefined;
1631-
if (result?.valid !== false) return false;
1632-
const m = UNSOUND_OVERLOAD_RE.exec(result.error?.message ?? '');
1633-
return m !== null && isDateArith(m);
1634-
} catch {
1635-
return false;
1636-
}
1637-
}
1638-
16391607
/**
16401608
* cel-js's code for a CALL no overload accepts — `isoDate(string)`,
16411609
* `string.getFullYear()` — raised by the checker and the evaluator alike

‎packages/formula/src/validate.test.ts‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,3 +1411,70 @@ describe('a flow condition\'s record.<field> / previous.<field> read takes the d
14111411
expect(codes('record.title > 5')).toEqual(['type-mismatch-run-fails']);
14121412
});
14131413
});
1414+
1415+
// [#36377] A flow condition that orders the BARE date name against a text
1416+
// literal before it does arithmetic on the field's `record.` / `previous.` read
1417+
// (`due_date > "2026-01-01" && record.due_date + 1 > 5`) was refused by no pass:
1418+
// the Timestamp typing met the ordering first and stood it down for the bare
1419+
// name and the record-root pass alike, and the record-root date-text pass stood
1420+
// down because the roots' own typing met date arithmetic first, a shape it read
1421+
// as answered elsewhere. The run faults on the `YYYY-MM-DD` text every time. The
1422+
// mixed spelling now takes the verdict, code and words its all-bare and
1423+
// all-root spellings take.
1424+
describe('a flow condition that orders the bare date name before date arithmetic on its record. / previous. read is refused (#36377)', () => {
1425+
const fieldTypes = { title: 'text', borrow_date: 'date', due_date: 'date', picked_up_at: 'datetime' };
1426+
const CONDITION: ExprSchemaHint = { scope: 'flattened', fields: Object.keys(fieldTypes), fieldTypes, faultOutcome: 'run-fails' };
1427+
const errorsOf = (source: string, hint: ExprSchemaHint = CONDITION) => validateExpression('predicate', source, hint).errors;
1428+
const codes = (source: string, hint: ExprSchemaHint = CONDITION) => errorsOf(source, hint).map((e) => e.code);
1429+
const verdicts = (source: string, hint: ExprSchemaHint = CONDITION) =>
1430+
errorsOf(source, hint).map((e) => ({ code: e.code, params: e.params, message: e.message }));
1431+
const ROW = { title: 'Dune', borrow_date: '2026-11-16', due_date: '2026-11-30', picked_up_at: '2026-11-16T09:30:00.000Z' };
1432+
const run = (source: string) => celEngine.evaluate({ dialect: 'cel', source }, { ...ROW, record: ROW, previous: ROW });
1433+
1434+
it('refuses the mixed spelling with exactly the verdict the all-root spelling gets, naming the root read', () => {
1435+
for (const [root, field, op] of [
1436+
['record', 'due_date', '+ 1'], ['previous', 'due_date', '- 7'], ['record', 'picked_up_at', '+ 1'],
1437+
] as const) {
1438+
const allRoot = `${root}.${field} > "2026-01-01" && ${root}.${field} ${op} > 5`;
1439+
const mixed = `${field} > "2026-01-01" && ${root}.${field} ${op} > 5`;
1440+
const expected = verdicts(allRoot);
1441+
expect(expected.map((v) => v.code), allRoot).toEqual(['date-text-arithmetic-run-fails']);
1442+
expect(expected[0].params, allRoot).toMatchObject({ reference: `${root}.${field}` });
1443+
expect(verdicts(mixed), mixed).toEqual(expected);
1444+
// Both fault on the field's text on every run.
1445+
expect(run(mixed), mixed).toMatchObject({ ok: false });
1446+
}
1447+
// The all-bare spelling takes the same code, naming the bare name.
1448+
expect(verdicts('due_date > "2026-01-01" && due_date + 1 > 5').map((v) => [v.code, v.params]))
1449+
.toEqual([['date-text-arithmetic-run-fails', { operands: 'DateText + int', reference: 'due_date' }]]);
1450+
});
1451+
1452+
it('takes the row\'s outcome arm: run-may-fail where none is declared, run-fails kept when bare names are unproven', () => {
1453+
const mixed = 'due_date > "2026-01-01" && record.due_date + 1 > 5';
1454+
expect(codes(mixed, { ...CONDITION, faultOutcome: undefined })).toEqual(['date-text-arithmetic-run-may-fail']);
1455+
expect(codes(mixed, { ...CONDITION, bareNamesUnproven: true })).toEqual(['date-text-arithmetic-run-fails']);
1456+
// A flow variable holding the bare name leaves the bare ordering `dyn`, so the record-root pass meets the
1457+
// root read's arithmetic first and answers it under `date-arithmetic`, as for `record.due_date + 1 > 5` alone.
1458+
expect(codes(mixed, { ...CONDITION, flowVariables: ['due_date'] })).toEqual(['date-arithmetic-run-fails']);
1459+
});
1460+
1461+
it('CONTROL: the arithmetic first keeps its date-arithmetic verdict, and the prescribed rewrites stay clean', () => {
1462+
expect(codes('record.due_date + 1 > 5 && due_date > "2026-01-01"')).toEqual(['date-arithmetic-run-fails']);
1463+
for (const source of [
1464+
'due_date > "2026-01-01" && record.due_date < today()',
1465+
'due_date > "2026-01-01" && daysBetween(record.due_date, today()) > 5',
1466+
'due_date > "2026-01-01" && addDays(previous.due_date, -7) < today()',
1467+
]) {
1468+
expect(validateExpression('predicate', source, CONDITION), source).toEqual({ ok: true, errors: [], warnings: [] });
1469+
}
1470+
});
1471+
1472+
it('the #30025 swap under unproven bare names hands a root read\'s date-arithmetic verdict the row\'s arm', () => {
1473+
// The bare text mismatch is not proven the field's; the root read's date arithmetic is, and its answer wins.
1474+
const unproven: ExprSchemaHint = { ...CONDITION, bareNamesUnproven: true };
1475+
expect(verdicts('title > 5 && record.due_date + 1 > 5', unproven).map((v) => [v.code, v.params])).toEqual([[
1476+
'date-arithmetic-run-fails',
1477+
{ operands: 'google.protobuf.Timestamp + int', reference: 'record.due_date' },
1478+
]]);
1479+
});
1480+
});

‎packages/formula/src/validate.ts‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
firstDateTextVerdict,
2525
firstTypeMismatch,
2626
inferCelType,
27-
recordRootReadsFaultDateArith,
2827
RECORD_ROOT_READ_RE,
2928
parseCelToAst,
3029
parseCelToAstWithReason,
@@ -920,18 +919,23 @@ const DATE_TEXT_FAMILY_RE = /^date-text-(?:call|arithmetic)(?:-|$)/;
920919
* root read, left `dyn`, checked clean. Typed here with every field's type
921920
* (a flow variable shadows a bare name, never a root member), every bare name
922921
* `dyn`, the same verdict, code and words come back, naming the read as
923-
* written. The order is the bare name's own: there {@link firstTypeMismatch}
924-
* answers `date-arith` when the Timestamp typing's first fault is date/duration
925-
* arithmetic against a number, and the date-text check is asked only once it
926-
* answers null. So the pass stands down exactly where the roots' first
927-
* Timestamp-typing fault is that shape (`record.due_date + 1`, the
928-
* `date-arithmetic` family's, {@link recordRootReadsFaultDateArith}), and on no
929-
* other fault: `record.due_date - record.borrow_date > 3` (a Duration ordered
930-
* against a number) and an expression that orders a date field against a text
931-
* literal before it calls `timestamp()` are judged, as their bare spellings
932-
* are. Only `date-text-call*` / `date-text-arithmetic*` are kept. The outcome arm is
933-
* the row's: a root read keeps the declared outcome whatever binds the bare
934-
* names (#30025), so `bareNamesUnproven` is not asked.
922+
* written. The order is the bare name's own: the date-text check is asked
923+
* only once {@link firstTypeMismatch} answers null, and this pass is reached
924+
* only there, so it never stands down on a shape that check answers (its
925+
* record-root pass answers `record.due_date + 1` under `date-arith`, #34946).
926+
* [#36377] Nor on any other: the roots' own Timestamp typing meeting date
927+
* arithmetic first is no answer. `due_date > "2026-01-01" && record.due_date + 1 > 5`
928+
* orders the bare name against a text literal first, which the runtime answers
929+
* and {@link firstTypeMismatch} stands down on for the bare name and the root
930+
* pass alike, so it answers null and the arithmetic on the root read faults on
931+
* every run; judged here it takes the `date-text-arithmetic` verdict its all-bare
932+
* and all-root spellings take. `record.due_date - record.borrow_date > 3` (a
933+
* Duration ordered against a number) and an expression that orders a date
934+
* field against a text literal before it calls `timestamp()` are judged, as
935+
* their bare spellings are. Only `date-text-call*` / `date-text-arithmetic*`
936+
* are kept. The outcome arm is the row's: a root read keeps the declared
937+
* outcome whatever binds the bare names (#30025), so `bareNamesUnproven` is
938+
* not asked.
935939
*/
936940
function recordRootDateTextIssue(
937941
source: string,
@@ -941,7 +945,6 @@ function recordRootDateTextIssue(
941945
faultOutcome: ExprSchemaHint['faultOutcome'],
942946
): { issue: ExprValidationError; severity: 'error' | 'warning' } | null {
943947
if (!RECORD_ROOT_READ_RE.test(source) || !Object.values(celFieldTypes).includes('timestamp')) return null;
944-
if (recordRootReadsFaultDateArith(source, celFieldTypes)) return null;
945948
const dateOnly = new Set(Object.keys(celFieldTypes).filter((name) => fieldTypes[name] === 'date'));
946949
const found = dateTextIssue(source, {}, 'flattened', role, dateArm('flattened', faultOutcome, false), dateOnly, celFieldTypes);
947950
return found && DATE_TEXT_FAMILY_RE.test(found.issue.code) ? found : null;

‎packages/lint/src/validate-expressions.test.ts‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7100,6 +7100,59 @@ describe('validateStackExpressions — a flow condition\'s record. / previous. r
71007100
});
71017101
});
71027102

7103+
// [#36377] A flow CONDITION that orders the BARE date name against a text
7104+
// literal before it does arithmetic on the field's `record.` / `previous.`
7105+
// read got zero findings, while its all-bare and all-root spellings were
7106+
// refused, and it fails every run on the `YYYY-MM-DD` text. It now takes the
7107+
// all-root spelling's finding, at the same path and severity.
7108+
describe('validateStackExpressions — a bare date ordering before date arithmetic on a record. / previous. read is refused (#36377)', () => {
7109+
const LOAN = {
7110+
name: 'library_loan',
7111+
fields: { due_date: { type: 'date', required: true }, picked_up_at: { type: 'datetime', required: true } },
7112+
};
7113+
type Site = 'start' | 'edge' | 'decision';
7114+
const stackWith = (site: Site, condition: string) => ({
7115+
objects: [LOAN],
7116+
flows: [{
7117+
name: 'loan_due',
7118+
nodes: [
7119+
{
7120+
id: 'start', type: 'start',
7121+
config: { objectName: 'library_loan', triggerType: 'record-after-update', ...(site === 'start' ? { condition } : {}) },
7122+
},
7123+
...(site === 'decision'
7124+
? [{ id: 'gate', type: 'decision', config: { conditions: [{ label: 'Due', expression: condition }] } }]
7125+
: []),
7126+
{ id: 'end', type: 'end' },
7127+
],
7128+
edges: site === 'decision'
7129+
? [{ id: 'e1', source: 'start', target: 'gate' }, { id: 'e2', source: 'gate', target: 'end' }]
7130+
: [{ id: 'e1', source: 'start', target: 'end', ...(site === 'edge' ? { condition } : {}) }],
7131+
}],
7132+
});
7133+
const shape = (issues: ExprIssue[]) => issues.map((i) => [i.severity, i.path ?? i.where, i.message]);
7134+
7135+
it.each(['start', 'edge', 'decision'] as const)(
7136+
'refuses the mixed spelling in a %s condition with the all-root spelling\'s finding',
7137+
(site) => {
7138+
for (const [root, field, op] of [
7139+
['record', 'due_date', '+ 1'], ['previous', 'due_date', '- 7'], ['record', 'picked_up_at', '+ 1'],
7140+
] as const) {
7141+
const allRoot = validateStackExpressions(stackWith(site, `${root}.${field} > "2026-01-01" && ${root}.${field} ${op} > 5`));
7142+
expect(allRoot.map((i) => i.severity), `${site}: ${root}.${field}`).toEqual(['error']);
7143+
const mixed = `${field} > "2026-01-01" && ${root}.${field} ${op} > 5`;
7144+
expect(shape(validateStackExpressions(stackWith(site, mixed))), `${site}: ${mixed}`).toEqual(shape(allRoot));
7145+
}
7146+
},
7147+
);
7148+
7149+
it('CONTROL: the same bare ordering before an ordering of the root read against today() stays clean', () => {
7150+
for (const site of ['start', 'edge', 'decision'] as const) {
7151+
expect(validateStackExpressions(stackWith(site, 'due_date > "2026-01-01" && record.due_date < today()')), site).toEqual([]);
7152+
}
7153+
});
7154+
});
7155+
71037156
/**
71047157
* [ADR-0113 D1, as amended] A `required` field's own `visibleWhen` decides its
71057158
* requirement on the write, and a predicate the server cannot evaluate counts

0 commit comments

Comments
 (0)