Skip to content

Commit 0f3ee58

Browse files
fix(formula,lint): a date-arithmetic verdict in a flow condition says the run fails, not that the value reads null (#30240)
<!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgPpByBofWLd4fRXKHA6v8SN)_ domain:server#4 · os-bill · session_01Utp6Ca5BRUDW37pk8jE1gW ## 维护者速读 - **改了什么**:流程条件(起始条件、连线条件、decision 分支)里对日期字段做加减(如 `close_date + 1 > 3`、`end_date - start_date > duration("1h")`),判词不再说「字段静默得到 null」,而是如实说明:条件出错时运行在此失败、流程要做的事没做。记录触发流程(及扫描本对象的定时相对触发)上说「运行失败」;其它流程(API、定时、动作或父流程启动)上说「只要这个名字在运行时拿到的是日期,运行就失败」。四个新拒绝码承载这两种句子。 - **为什么改**:#29953 / #30015 已让文本、布尔比较的判词说真话,日期判词被落下。引擎的 `evaluateCondition` 在每种流程上遇错都抛异常、运行失败,旧句子却告诉作者流程会继续往下走。 - **风险与回滚**:分级不变(日期判词在每个位置本来就是 error),发布门不收也不放。流程条件上的日期判词改用新码 `date-arithmetic-run-fails` / `-run-may-fail`、`date-text-arithmetic-run-fails` / `-run-may-fail`,按旧码 `date-arithmetic` / `date-text-arithmetic` 识别流程站点的使用方需改认;公式字段、校验规则等 record 范围站点原码原句不动。回滚即 revert,无数据迁移。 - **先看**:`packages/formula/src/validate.ts`(`dateFlowArm` / `dateFlowFault` 两个小函数和 `date-arith` 分支)、`packages/formula/src/expression-refusal.ts`(四个码)、`packages/lint/src/validate-expressions.test.ts`(三种流程 × 三个站点的钉子)。 - **两分钟验证**:`pnpm --filter @objectstack/lint exec vitest run src/validate-expressions.test.ts -t 30016`,预期 2 条通过:记录触发、定时、API 三个流程的起始条件、连线条件、decision 分支都报 error 且文案说运行失败、不说 null;record 范围校验规则对照仍说 null。 - **需要你做的**:无,席位落地。 Fixes #30016 Clause-②: yes (widening) — four codes join @objectstack/formula's ExpressionRefusalCode (date-arithmetic-run-fails, date-arithmetic-run-may-fail, date-text-arithmetic-run-fails, date-text-arithmetic-run-may-fail) and a flow condition's date verdicts move to them from date-arithmetic / date-text-arithmetic (a consumer keyed to those codes on a flow site re-keys); grading unchanged (error at every site); record-scoped sites keep their code and sentence. Metadata-protocol: none ## What changes Measured on `main` at `dfafae81` (after PR #30015, merged 2026-11-04T08:28Z). The `date-arith` branch of `typeSoundnessIssue` and the `fault` arm of `dateTextIssue` served one sentence, "this faults at runtime, so the field silently evaluates to null", at every scope. A `'flattened'` site is a flow condition (lint's flow walk, the engine's registration advisory pass, MCP `flow_condition`), and `dag-traversal.ts` `evaluateCondition` throws on a fault on every flow (ADR-0032 §1c): the run fails at the condition, nothing reads null. | site | before | now | |:--|:--|:--| | flow condition, `faultOutcome: 'run-fails'` (record-triggered start / edge / `decision`; a time-relative sweep of the typed object), `bareNamesUnproven` unset | `date-arithmetic` / `date-text-arithmetic`, error, "silently evaluates to null" | `date-arithmetic-run-fails` / `date-text-arithmetic-run-fails`, error: "this faults at runtime, and a flow condition that cannot be evaluated fails the run: the flow stops at this condition and the work the flow exists to do is not done (it does not read null)." | | any other flow condition (no outcome declared, or `bareNamesUnproven`) | the same | `date-arithmetic-run-may-fail` / `date-text-arithmetic-run-may-fail`, error: "this faults wherever `close_date` holds the date (that text) when the condition runs, and a flow condition that cannot be evaluated fails the run: …" | | `record`-scoped site (formula field, validation rule, display predicate) | `date-arithmetic` / `date-text-arithmetic` | unchanged, code and sentence | **Why two flow sentences, not one (measured).** On a flow that is not record-triggered the bare name holds what the entrance hands the run (`engine.ts` `celScope` docblock: the inbound hook's request body for `trigger-api`, an action's loaded or `id`-only record, a parent's record, or nothing). Through the built `@objectstack/formula` on this head: `celEngine.evaluate({ dialect: 'cel', source: 'close_date + 1 > 3' }, { extra: { close_date: 5 } })` answers `{ ok: true, value: true }`; with `'2026-01-01'` it faults (cel-js `no such overload` for a dyn string `+ int`). So "this faults at runtime" is not proven there, and a code names one message template (`expression-refusal.ts`, the contract), hence four codes, mirroring `type-mismatch-run-fails` / `type-mismatch-run-may-fail`. The run-fails sentence carries no "the write that fired it still lands" clause: `run-fails` also covers a time-relative sweep, which no write fires. **Routing.** No new mechanism: `dateFlowArm(scope, faultOutcome, bareNamesUnproven)` reads the hint lint already passes (`faultOutcomeOf`, `bareNamesUnproven` from #30025). The date verdicts read bare names only, so `bareNamesUnproven` downgrades them to `-run-may-fail`; a bare name a flow variable holds (`flowVariables`) is still excluded from typing, as before. Grading stays `error` everywhere. `@objectstack/lint` changes only the fault-outcome ledger's docblock. ## Tests - `packages/formula/src/expression-refusal-codes.test.ts`: a `PINS` entry for each new code (exact params and message); the flattened pins that used to sit under `date-arithmetic` / `date-text-arithmetic` move to `-run-may-fail` (their schema declares no outcome); the record-scoped pins are untouched. `SWEEP_SCHEMAS` gains the flattened deal schema with `faultOutcome: 'run-fails'` and `SWEEP_SOURCES` a flattened date subtraction, so the sweep reaches all four codes and holds their params to their messages. - `packages/formula/src/validate.test.ts`: flattened `start_date + 1 > 3` under `run-fails` → `-run-fails`; with no outcome and with `bareNamesUnproven` → `-run-may-fail`; neither says "evaluates to null"; `flowVariables: ['start_date']` → no verdict; control: a record-scoped `fail-closed` rule keeps `date-arithmetic` and its null sentence. - `packages/formula/src/validate-date-text-arithmetic.test.ts`: the flattened case now asserts `-run-may-fail`, plus `-run-fails` under the outcome and `-run-may-fail` under `bareNamesUnproven`. - `packages/lint/src/validate-expressions.test.ts`: three flows (record-triggered, `schedule`, `type: 'api'`), each with a start condition, an edge condition (date arithmetic) and a `decision` branch (date subtraction): every verdict `error`, the record-triggered one says "this faults at runtime, and a flow condition …", the other two "this faults wherever `close_date` holds …", none "evaluates to null". Control: a record-scoped validation rule's date arithmetic keeps the null sentence. <details><summary>Suites (head f4501b7, under os-verify-lock, shared box)</summary> ``` formula test Test Files 64 passed (64) Tests 1644 passed (1644) lint test Test Files 193 passed (193) Tests 7996 passed (7996) mcp test Test Files 56 passed (56) Tests 675 passed (675) typecheck (tsc --noEmit + check:test-typecheck): formula 0, lint 0 ``` </details> <details><summary>Ablation (scripts/ablation-replace.mjs; restored: blob == HEAD, git diff HEAD empty)</summary> ``` A1 formula: dateFlowArm always answers null (`if (scope !== 'flattened' || true /* ablated-30016-a1 */) return null;`) — the old "silently evaluates to null" sentence and code come back on every flow site × in a flow condition says the run fails, and keeps the null sentence on a record-scoped rule (#30016) × judges a flattened (flow) condition the same way, under the flow codes (#30016) × date-arithmetic-run-fails · × date-arithmetic-run-may-fail · × date-text-arithmetic-run-fails · × date-text-arithmetic-run-may-fail (PINS) × the SWEEP (code set unreached) Tests 7 failed | 197 passed (204) ``` </details> ## Acceptance notes - **A record-scoped `fail-closed` validation rule still says "silently evaluates to null".** There the fault refuses the write (`rule-validator.ts` `checkPredicate`, the ledger's `fail-closed` row), so the sentence is not true either. The card keeps that sentence and the seat ruled it out of scope; reported as a finding, not fixed here. - **`type-mismatch-run-fails` on a time-relative sweep says "the write that fired it still lands".** Since PR #30015 the `run-fails` outcome also covers a time-relative sweep of the typed object, which no write fires. Pre-existing, outside this card's date scope; the date sentence here avoids the clause. Reported as a finding. - **The date verdicts stay errors on flows that are not record-triggered,** where the type-mismatch verdict is a warning because what the run binds is not proven. Grading was ruled unchanged; the `-run-may-fail` sentence states the condition under which the run fails, which is true at that grade. - **`content/docs/data-modeling/formulas.mdx`** is outside the claimed file surface; its two date rows make no flow-specific null claim, so it is left as is. ## Verification All at head `3eea4f73` (`git rev-parse --short HEAD`), the commit this PR opens on (`origin/main` merged once). - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack`: 58 derived families (re-derived after the merge of `origin/main`, the same 58), each run on this head after a full `turbo run build` (`--filter='!@objectstack/docs'`, VERDICT command-exit 0), all **exit 0**. `--ran`: "58 derived famil(ies) accounted for — 58 run, 0 NOT-MEASURED". Among them `check-adr-0087-registration --base origin/main` (exit 0: no semantic entry is required for this move, so none is added), `check-changeset-no-major`, `check-empty-changeset`, `check:docs-transcript-drift`, `check:doc-authoring`, `check:test-source-alias`, `check:cross-package-test-inputs`, `check:dts-closure`, `check:dual-build-cjs-loads`, `check:lean-entry-closure`. - `pnpm lint` (`eslint . --no-inline-config`): exit 0. - Full dogfood: not run. The title has no `!` and `Clause-②` has no `(narrowing)` arm. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Utp6Ca5BRUDW37pk8jE1gW Co-authored-by: Claude <noreply@anthropic.com>
1 parent 771b2db commit 0f3ee58

8 files changed

Lines changed: 265 additions & 32 deletions
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/formula': patch
3+
'@objectstack/lint': patch
4+
---
5+
6+
fix(formula,lint): a date-arithmetic verdict in a flow condition says the run fails, not that the value reads null
7+
8+
Clause-②: yes (widening)
9+
Metadata-protocol: none
10+
11+
- **`@objectstack/formula`: four codes join `ExpressionRefusalCode`**: `date-arithmetic-run-fails`, `date-arithmetic-run-may-fail`, `date-text-arithmetic-run-fails` and `date-text-arithmetic-run-may-fail`, with the same params as `date-arithmetic` / `date-text-arithmetic`. A flow condition (a `'flattened'` site) that does arithmetic on a date field used to be told the field "silently evaluates to null", but the engine's `evaluateCondition` throws on the fault on every flow, so the run fails at the condition. Where the caller declares the run proven to hold the field (`faultOutcome: 'run-fails'`, with `bareNamesUnproven` unset) the verdict is served under `-run-fails` and says the run fails; anywhere else in a flow it is served under `-run-may-fail` and says the run fails wherever the name holds the field's date when the condition runs (a flow started by an API call, an action or a parent flow binds what its entrance hands over, which can be a number). The grade is unchanged: an error at every site. A `record`-scoped site (a formula field, a validation rule, a display predicate) keeps `date-arithmetic` / `date-text-arithmetic` and their sentence. A consumer keyed to the old codes on a flow condition re-keys to the new ones.
12+
- **`@objectstack/lint`**: the fault-outcome ledger's docblock names the date verdicts' flow codes; the routing is the existing `faultOutcome` / `bareNamesUnproven` hint, unchanged.

‎packages/formula/src/expression-refusal-codes.test.ts‎

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,37 @@ const PINS: { readonly [C in ExpressionRefusalCode]: readonly [Pin<C>, ...Pin<C>
295295
'on dates: this faults at runtime, so the field silently evaluates to null. Use `daysBetween(a, b)` for the span ' +
296296
'in whole days, and `daysFromNow(n)` / `addDays(d, n)` / `addMonths(d, n)` to shift a date.',
297297
},
298+
],
299+
// [#30016] A flattened (flow) condition: the fault fails the run, it never
300+
// reads null — `run-fails` where the run is proven to hold the field.
301+
'date-arithmetic-run-fails': [
302+
{
303+
produce: () =>
304+
onlyError('predicate', 'close_date + 1 > 3', {
305+
fields: ['close_date'],
306+
fieldTypes: { close_date: 'date' },
307+
faultOutcome: 'run-fails',
308+
}),
309+
params: { operands: 'google.protobuf.Timestamp + int', reference: 'close_date' },
310+
message:
311+
'date arithmetic `google.protobuf.Timestamp + int` — `close_date` is a date, and CEL can\'t do arithmetic ' +
312+
'on dates: this faults at runtime, and ' +
313+
'a flow condition that cannot be evaluated fails the run: the flow stops at this condition and the work the flow ' +
314+
'exists to do is not done (it does not read null). ' +
315+
'Use `daysBetween(a, b)` for the span in whole days, and `daysFromNow(n)` / `addDays(d, n)` / `addMonths(d, n)` to shift a date.',
316+
},
317+
],
318+
'date-arithmetic-run-may-fail': [
298319
{
299320
produce: () =>
300321
onlyError('predicate', 'close_date + 1 > 3', { fields: ['close_date'], fieldTypes: { close_date: 'date' } }),
301322
params: { operands: 'google.protobuf.Timestamp + int', reference: 'close_date' },
302323
message:
303324
'date arithmetic `google.protobuf.Timestamp + int` — `close_date` is a date, and CEL can\'t do arithmetic ' +
304-
'on dates: this faults at runtime, so the field silently evaluates to null. Use `daysBetween(a, b)` for the span ' +
305-
'in whole days, and `daysFromNow(n)` / `addDays(d, n)` / `addMonths(d, n)` to shift a date.',
325+
'on dates: this faults wherever `close_date` holds the date when the condition runs, and ' +
326+
'a flow condition that cannot be evaluated fails the run: the flow stops at this condition and the work the flow ' +
327+
'exists to do is not done (it does not read null). ' +
328+
'Use `daysBetween(a, b)` for the span in whole days, and `daysFromNow(n)` / `addDays(d, n)` / `addMonths(d, n)` to shift a date.',
306329
},
307330
],
308331
'date-text-arithmetic': [
@@ -319,18 +342,40 @@ const PINS: { readonly [C in ExpressionRefusalCode]: readonly [Pin<C>, ...Pin<C>
319342
'faults at runtime, so the field silently evaluates to null. Use `daysBetween(a, b)` for the span in whole days, ' +
320343
'and `daysFromNow(n)` / `addDays(d, n)` / `addMonths(d, n)` to shift a date.',
321344
},
345+
],
346+
'date-text-arithmetic-run-fails': [
322347
{
323348
produce: () =>
324349
onlyError('predicate', 'end_at - start_at > duration("1h")', {
325350
fields: ['start_at', 'end_at'],
326351
fieldTypes: { start_at: 'datetime', end_at: 'datetime' },
352+
faultOutcome: 'run-fails',
327353
}),
328354
params: { operands: 'DateText - DateText', reference: 'start_at' },
329355
message:
330356
'date arithmetic `DateText - DateText` — `start_at` is a date field, and the runtime holds a date field ' +
331-
'as its text (`YYYY-MM-DD`, or an ISO-8601 instant for a date-time), which CEL can\'t do arithmetic on: this ' +
332-
'faults at runtime, so the field silently evaluates to null. Use `daysBetween(a, b)` for the span in whole days, ' +
333-
'and `daysFromNow(n)` / `addDays(d, n)` / `addMonths(d, n)` to shift a date.',
357+
'as its text (`YYYY-MM-DD`, or an ISO-8601 instant for a date-time), which CEL can\'t do arithmetic on: ' +
358+
'this faults at runtime, and ' +
359+
'a flow condition that cannot be evaluated fails the run: the flow stops at this condition and the work the flow ' +
360+
'exists to do is not done (it does not read null). ' +
361+
'Use `daysBetween(a, b)` for the span in whole days, and `daysFromNow(n)` / `addDays(d, n)` / `addMonths(d, n)` to shift a date.',
362+
},
363+
],
364+
'date-text-arithmetic-run-may-fail': [
365+
{
366+
produce: () =>
367+
onlyError('predicate', 'end_at - start_at > duration("1h")', {
368+
fields: ['start_at', 'end_at'],
369+
fieldTypes: { start_at: 'datetime', end_at: 'datetime' },
370+
}),
371+
params: { operands: 'DateText - DateText', reference: 'start_at' },
372+
message:
373+
'date arithmetic `DateText - DateText` — `start_at` is a date field, and the runtime holds a date field ' +
374+
'as its text (`YYYY-MM-DD`, or an ISO-8601 instant for a date-time), which CEL can\'t do arithmetic on: ' +
375+
'this faults wherever `start_at` holds that text when the condition runs, and ' +
376+
'a flow condition that cannot be evaluated fails the run: the flow stops at this condition and the work the flow ' +
377+
'exists to do is not done (it does not read null). ' +
378+
'Use `daysBetween(a, b)` for the span in whole days, and `daysFromNow(n)` / `addDays(d, n)` / `addMonths(d, n)` to shift a date.',
334379
},
335380
],
336381
'date-duration-value': [
@@ -594,6 +639,7 @@ const SWEEP_SOURCES: readonly string[] = [
594639
'close_date + 1 > 3',
595640
'record.close_date - record.close_date',
596641
'today() - record.close_date',
642+
'close_date - close_date > duration("1h")',
597643
'record.name > 5',
598644
'record.active + 1 > 5',
599645
"record.account == 'a1' && record.account.name == 'x'",
@@ -631,6 +677,10 @@ const SWEEP_SCHEMAS: readonly (ExprSchemaHint | undefined)[] = [
631677
optionFields: ['status'],
632678
},
633679
{ fields: ['status', 'close_date'], objectName: 'deal', fieldTypes: { close_date: 'date' } },
680+
// [#30016] The same flow condition where the run is proven to hold the
681+
// field: the date verdicts' `-run-fails` codes (the line above reaches
682+
// `-run-may-fail`).
683+
{ fields: ['status', 'close_date'], objectName: 'deal', fieldTypes: { close_date: 'date' }, faultOutcome: 'run-fails' },
634684
// [#29926] The deal schema once per declared fault outcome, so the sweep
635685
// reaches each `type-mismatch-*` code and holds its params to its message.
636686
...(['fail-closed', 'run-fails', 'fail-open'] as const).map((faultOutcome): ExprSchemaHint => ({

‎packages/formula/src/expression-refusal.ts‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,35 @@ export interface ExpressionRefusalParams {
164164
'bare-reference': { readonly name: string };
165165
/**
166166
* Arithmetic on a date field against a number. `operands` are the CEL
167-
* operand types; `reference` is the field as written, when it is known.
167+
* operand types; `reference` is the field as written, when it is known. A
168+
* flattened (flow) condition is `date-arithmetic-run-fails` /
169+
* `date-arithmetic-run-may-fail`.
168170
*/
169171
'date-arithmetic': { readonly operands: string; readonly reference?: string };
170172
/**
171173
* Arithmetic on a date field's runtime TEXT that the evaluator cannot answer
172174
* (`record.end_date - record.start_date`), judged with the field declared as
173175
* that text. `operands` are the CEL operand types (the text is `DateText`);
174-
* `reference` is the field as written, when it is known.
176+
* `reference` is the field as written, when it is known. A flattened (flow)
177+
* condition is `date-text-arithmetic-run-fails` / `-run-may-fail`.
175178
*/
176179
'date-text-arithmetic': { readonly operands: string; readonly reference?: string };
180+
/**
181+
* [#30016] ERROR: `date-arithmetic` in a flow condition whose run is proven
182+
* to hold the field there (`faultOutcome: 'run-fails'`) — the condition
183+
* faults, so the run fails at it. It never reads null.
184+
*/
185+
'date-arithmetic-run-fails': { readonly operands: string; readonly reference?: string };
186+
/**
187+
* [#30016] ERROR: `date-arithmetic` in any other flow condition — it faults,
188+
* and so fails the run, wherever the name holds the field's date when the
189+
* condition runs; what the run binds under the name is not proven there.
190+
*/
191+
'date-arithmetic-run-may-fail': { readonly operands: string; readonly reference?: string };
192+
/** [#30016] ERROR: `date-text-arithmetic`, at a `date-arithmetic-run-fails` site. */
193+
'date-text-arithmetic-run-fails': { readonly operands: string; readonly reference?: string };
194+
/** [#30016] ERROR: `date-text-arithmetic`, at a `date-arithmetic-run-may-fail` site. */
195+
'date-text-arithmetic-run-may-fail': { readonly operands: string; readonly reference?: string };
177196
/**
178197
* A formula that computes a `google.protobuf.Duration`
179198
* (`today() - record.start_date`), which a field reads as `{}`. `reference`
@@ -274,6 +293,10 @@ const CODE_TABLE = {
274293
'bare-reference': true,
275294
'date-arithmetic': true,
276295
'date-text-arithmetic': true,
296+
'date-arithmetic-run-fails': true,
297+
'date-arithmetic-run-may-fail': true,
298+
'date-text-arithmetic-run-fails': true,
299+
'date-text-arithmetic-run-may-fail': true,
277300
'date-duration-value': true,
278301
'type-mismatch': true,
279302
'type-mismatch-fail-closed': true,

‎packages/formula/src/validate-date-text-arithmetic.test.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,25 @@ describe('date subtraction the runtime cannot answer (#28944)', () => {
119119
expect(since.message).toMatch(/daysBetween\(a, b\)/);
120120
});
121121

122-
it('judges a flattened (flow) condition the same way', () => {
122+
it('judges a flattened (flow) condition the same way, under the flow codes (#30016)', () => {
123123
const flattened: ExprSchemaHint = {
124124
fields: ['start_date', 'end_date'],
125125
fieldTypes: { start_date: 'date', end_date: 'date' },
126126
};
127+
// No declared outcome: the run fails wherever the name holds the date's text.
127128
const refused = validateExpression('predicate', 'end_date - start_date > duration("72h")', flattened);
128-
expect(refused.errors.map((e) => e.code)).toEqual(['date-text-arithmetic']);
129+
expect(refused.errors.map((e) => e.code)).toEqual(['date-text-arithmetic-run-may-fail']);
129130
expect(refused.errors[0].params).toEqual({ operands: 'DateText - DateText', reference: 'start_date' });
131+
expect(refused.errors[0].message).not.toMatch(/evaluates to null/);
132+
// The run is proven to hold the field: it fails at the condition.
133+
const proven = validateExpression('predicate', 'end_date - start_date > duration("72h")', { ...flattened, faultOutcome: 'run-fails' });
134+
expect(proven.errors.map((e) => e.code)).toEqual(['date-text-arithmetic-run-fails']);
135+
expect(proven.errors[0].message).toMatch(/this faults at runtime, and a flow condition that cannot be evaluated fails the run/);
136+
// A node can rebind the bare names: not proven, whatever the outcome.
137+
const unproven = validateExpression('predicate', 'end_date - start_date > duration("72h")', {
138+
...flattened, faultOutcome: 'run-fails', bareNamesUnproven: true,
139+
});
140+
expect(unproven.errors.map((e) => e.code)).toEqual(['date-text-arithmetic-run-may-fail']);
130141
expect(validateExpression('predicate', 'today() - start_date > duration("72h")', flattened).errors).toEqual([]);
131142
});
132143

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,34 @@ describe('validateExpression (ADR-0032)', () => {
10631063
expect(r.ok).toBe(true);
10641064
expect(r.errors).toHaveLength(0);
10651065
});
1066+
1067+
// [#30016] A flow condition's fault fails the run (`evaluateCondition`
1068+
// throws on every flow), so the flow codes never say it reads null. The
1069+
// grade stays an error at every site.
1070+
it('in a flow condition says the run fails, and keeps the null sentence on a record-scoped rule (#30016)', () => {
1071+
const flow = { ...schema, scope: 'flattened' } as const;
1072+
const codeOf = (hint: object) => {
1073+
const r = validateExpression('predicate', 'start_date + 1 > 3', { ...flow, ...hint });
1074+
expect(r.warnings).toHaveLength(0);
1075+
return r.errors.map((e) => [e.code, e.message] as const);
1076+
};
1077+
const [[provenCode, proven]] = codeOf({ faultOutcome: 'run-fails' });
1078+
expect(provenCode).toBe('date-arithmetic-run-fails');
1079+
expect(proven).toMatch(/this faults at runtime, and a flow condition that cannot be evaluated fails the run/);
1080+
expect(proven).not.toMatch(/evaluates to null/);
1081+
for (const hint of [{}, { faultOutcome: 'run-fails', bareNamesUnproven: true }]) {
1082+
const [[code, message]] = codeOf(hint);
1083+
expect(code).toBe('date-arithmetic-run-may-fail');
1084+
expect(message).toMatch(/this faults wherever `start_date` holds the date when the condition runs, and a flow condition/);
1085+
expect(message).not.toMatch(/evaluates to null/);
1086+
}
1087+
// A bare name a flow variable holds is not the field: no verdict.
1088+
expect(codeOf({ faultOutcome: 'run-fails', flowVariables: ['start_date'] })).toEqual([]);
1089+
// Control: a record-scoped validation rule keeps its code and sentence.
1090+
const rule = validateExpression('predicate', 'record.start_date + 1 > 3', { ...schema, faultOutcome: 'fail-closed' });
1091+
expect(rule.errors.map((e) => e.code)).toEqual(['date-arithmetic']);
1092+
expect(rule.errors[0].message).toMatch(/this faults at runtime, so the field silently evaluates to null/);
1093+
});
10661094
});
10671095

10681096
describe('introspection', () => {

0 commit comments

Comments
 (0)