Skip to content

Commit 091455d

Browse files
committed
fix(formula): an advisory rule's date verdict says the rule is skipped and the write proceeds
On a fail-open site (a warning / info validation rule) the date-arithmetic and date-text-arithmetic verdicts close on the type-mismatch-fail-open clause, under their own codes date-arithmetic-fail-open and date-text-arithmetic-fail-open. The grade stays an error; a formula field keeps date-arithmetic and its null sentence. Claude-Session: https://claude.ai/code/session_01Utp6CbJFWadws6f9r4B8Ke Co-authored-by: Claude <noreply@anthropic.com>
1 parent 89eebee commit 091455d

2 files changed

Lines changed: 33 additions & 12 deletions

File tree

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ export interface ExpressionRefusalParams {
167167
* operand types; `reference` is the field as written, when it is known. A
168168
* flattened (flow) condition is `date-arithmetic-run-fails` /
169169
* `date-arithmetic-run-may-fail`; a fail-closed site is
170-
* `date-arithmetic-fail-closed`. An advisory rule's stays this code.
170+
* `date-arithmetic-fail-closed`, and an advisory rule's is
171+
* `date-arithmetic-fail-open`.
171172
*/
172173
'date-arithmetic': { readonly operands: string; readonly reference?: string };
173174
/**
@@ -176,7 +177,8 @@ export interface ExpressionRefusalParams {
176177
* that text. `operands` are the CEL operand types (the text is `DateText`);
177178
* `reference` is the field as written, when it is known. A flattened (flow)
178179
* condition is `date-text-arithmetic-run-fails` / `-run-may-fail`; a
179-
* fail-closed site is `date-text-arithmetic-fail-closed`.
180+
* fail-closed site is `date-text-arithmetic-fail-closed`, an advisory rule's
181+
* `date-text-arithmetic-fail-open`.
180182
*/
181183
'date-text-arithmetic': { readonly operands: string; readonly reference?: string };
182184
/**
@@ -204,6 +206,14 @@ export interface ExpressionRefusalParams {
204206
'date-arithmetic-fail-closed': { readonly operands: string; readonly reference?: string };
205207
/** [#30250] ERROR: `date-text-arithmetic`, at a `date-arithmetic-fail-closed` site. */
206208
'date-text-arithmetic-fail-closed': { readonly operands: string; readonly reference?: string };
209+
/**
210+
* [#30494] ERROR: `date-arithmetic` in an advisory (`warning` / `info`)
211+
* validation rule, a site that FAILS OPEN — the fault skips the rule and the
212+
* write proceeds (the `type-mismatch-fail-open` outcome). It never reads null.
213+
*/
214+
'date-arithmetic-fail-open': { readonly operands: string; readonly reference?: string };
215+
/** [#30494] ERROR: `date-text-arithmetic`, at a `date-arithmetic-fail-open` site. */
216+
'date-text-arithmetic-fail-open': { readonly operands: string; readonly reference?: string };
207217
/**
208218
* A formula that computes a `google.protobuf.Duration`
209219
* (`today() - record.start_date`), which a field reads as `{}`. `reference`
@@ -317,6 +327,8 @@ const CODE_TABLE = {
317327
'date-text-arithmetic-run-may-fail': true,
318328
'date-arithmetic-fail-closed': true,
319329
'date-text-arithmetic-fail-closed': true,
330+
'date-arithmetic-fail-open': true,
331+
'date-text-arithmetic-fail-open': true,
320332
'date-duration-value': true,
321333
'type-mismatch': true,
322334
'type-mismatch-fail-closed': true,

‎packages/formula/src/validate.ts‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,10 @@ const DATE_FAIL_CLOSED_CLAUSE =
440440
* (`date − date + 1`, `today() + 30`) — always faults at runtime and never
441441
* recovers, so it blocks the build. A formula reads that fault as null; a
442442
* flattened (flow) condition's fault fails the run, under the
443-
* `date-arithmetic-run-fails` / `-run-may-fail` codes (#30016), and a
443+
* `date-arithmetic-run-fails` / `-run-may-fail` codes (#30016), a
444444
* fail-closed site's refuses the write, under `date-arithmetic-fail-closed`
445-
* (#30250, {@link dateArm}).
445+
* (#30250), and an advisory rule's skips the rule, under
446+
* `date-arithmetic-fail-open` (#30494, {@link dateArm}).
446447
* - `type-mismatch` (**warning**): a text/boolean field used with an
447448
* arithmetic/ordering operator against a number — nulls unless the text value
448449
* happens to be numeric, so it stays advisory. An **error** where the caller
@@ -611,25 +612,32 @@ function typeSoundnessIssue(
611612
* where it holds the date: `run-may-fail`. A `record`-scoped site that fails
612613
* closed (`faultOutcome: 'fail-closed'`: an `error` validation rule, a field
613614
* write rule, an option `visibleWhen`, a hook `condition`) refuses the write
614-
* on the fault: `fail-closed` (#30250). An advisory rule (`fail-open`) keeps
615-
* the null sentence. The grade stays an error everywhere.
615+
* on the fault: `fail-closed` (#30250). An advisory rule (`faultOutcome:
616+
* 'fail-open'`) is skipped on the fault and the write proceeds: `fail-open`,
617+
* the `type-mismatch-fail-open` clause (#30494). The grade stays an error
618+
* everywhere.
616619
*/
617-
type DateArm = 'run-fails' | 'run-may-fail' | 'fail-closed';
620+
type DateArm = 'run-fails' | 'run-may-fail' | 'fail-closed' | 'fail-open';
618621
function dateArm(
619622
scope: 'record' | 'flattened',
620623
faultOutcome: ExprSchemaHint['faultOutcome'],
621624
bareNamesUnproven: boolean | undefined,
622625
): DateArm | null {
623-
if (scope !== 'flattened') return faultOutcome === 'fail-closed' ? 'fail-closed' : null;
626+
if (scope !== 'flattened') {
627+
return faultOutcome === 'fail-closed' || faultOutcome === 'fail-open' ? faultOutcome : null;
628+
}
624629
return faultOutcome === 'run-fails' && !bareNamesUnproven ? 'run-fails' : 'run-may-fail';
625630
}
626631

627632
/**
628-
* [#30016, #30250] The fault clause of a date verdict whose fault does not read
629-
* null; `held` names what a flow condition's field holds at run time.
633+
* [#30016, #30250, #30494] The fault clause of a date verdict whose fault does
634+
* not read null; `held` names what a flow condition's field holds at run time.
635+
* An advisory rule's is the type mismatch's own `fail-open` clause, word for
636+
* word: one outcome, one sentence.
630637
*/
631638
function dateArmFault(arm: DateArm, ref: string | null, held: 'date' | 'text'): string {
632639
if (arm === 'fail-closed') return `this faults at runtime, and here ${DATE_FAIL_CLOSED_CLAUSE}`;
640+
if (arm === 'fail-open') return `this faults at runtime, and here ${TYPE_MISMATCH_FAULT_ARMS['fail-open'].clause}`;
633641
const fails =
634642
'a flow condition that cannot be evaluated fails the run: the flow stops at this condition and the ' +
635643
'work the flow exists to do is not done (it does not read null).';
@@ -645,8 +653,9 @@ function dateArmFault(arm: DateArm, ref: string | null, held: 'date' | 'text'):
645653
* - `date-text-arithmetic`: arithmetic on that text the evaluator faults on —
646654
* `record.end_date - record.start_date` (either field kind), `record.d -
647655
* duration('24h')` — so the expression reads null (in a flow condition the
648-
* run fails instead, and on a fail-closed site the write is refused:
649-
* `flowArm`, #30016, #30250). Any role.
656+
* run fails instead, on a fail-closed site the write is refused, and on an
657+
* advisory rule the rule is skipped: `flowArm`, #30016, #30250, #30494).
658+
* Any role.
650659
* - `date-duration-value`: a formula (`value` role) that computes a
651660
* `google.protobuf.Duration` — `today() - record.start_date` — which a field
652661
* serialises as `{}`. A predicate that COMPARES a duration

0 commit comments

Comments
 (0)