Skip to content

Commit 0c6f679

Browse files
fix(formula): a date ordered against a text field gets its own refusal code, date-text-ordering (#39148)
Part of #38959 Item 4 only, ruled option A in 7344060050. Items 1, 5 and 2 landed in #39072, and item 3 is recorded as accepted fail-open; the seat closes the card when this lands. Clause-②: yes Metadata-protocol: none Skills-docs: none — the kind is `none` with no arm, and `skills/objectstack-formula` names no `type-mismatch*` code for this shape ## 维护者速读 - 用户能看到什么变化:流程条件、校验规则、公式里把日期字段和文本字段比大小时,提示语换成一条新代码 `date-text-ordering`,说的是实际发生的事——按文本逐字比较,不会运行出错;该拦截的照样拦截,级别(错误/警告)不变。 - 为什么做:流程条件发布检查那张卡的第 4 项(日期与文本比大小的提示语不实),按你选的方案 A:给这种判定一个自己的代码和真实的句子。 - 出错会怎样:最坏是某处按旧代码匹配这种写法的提示会改看到新代码,拦截与否和级别都不变;可直接撤回本 PR 恢复旧提示。 - 要你做什么:无(契约审核由席位安排)。 ## Fix round (contract review 7349732810, S1 and N3), head `c18de9c61d` - **S1.** The params and sentence of `date-text-ordering` now come from the comparison that keeps the verdict. - `comparesDateTextAgainstUndeclared` returns that comparison instead of a boolean: its operator, its operand types and its counterpart. - The counterpart is given only when it is a text field read. An index read is named in member spelling. - `firstTypeMismatch` passes the comparison on as `ordering`, and `validate.ts` reads the params and sentence from it. - `field` and `root` are untouched, so the grade cannot move. - This supersedes the `dateTextOrdering: true` flag that the `cel-engine.ts` bullet and the ablation lines below describe. - **`reference` is narrower.** It now appears only for a direct text-field read. Computed text (`upper(record.title)`, `string(record.notes)`, a concatenation) loses it, and the sentence then reads "a text value". An index read `record['title']` gains `reference: record.title`. The params type is unchanged. - **Pins.** Both of the reviewer's shapes are pinned at 7 sites, with params asserted by equality. A base-vs-head sweep of 94,080 judgments found 0 code or grade changes; 22,488 changed params or sentence only. - **N3.** The lint counter comment and the `#30026` note are reworded; prose only. - **Review.** The delta contract review passed with `No must-fix, no should-fix.` ## What changes - **`@objectstack/formula`, `expression-refusal.ts`.** One new code in the closed refusal vocabulary, `date-text-ordering`, params `operands`, `operator`, `reference?` (the text counterpart as written, when it is a field read). Its pin file holds three pins: a formula-field warning, a record-triggered flow error with the reversed operand order, and a counterpart that is no field read. - **`validate.ts`, `typeSoundnessIssue`.** Where the type mismatch is the kept date-against-text ordering (the #32595 verdict, unchanged), the refusal is `date-text-ordering` with a sentence that says what the run does: the runtime holds the date field as its text, so the comparison evaluates as a text comparison and does not fault, answering by spelling, not by date. It prescribes `date(TEXT)` to compare dates (null where the text is no date) or `string(...)` on the date side to compare text on purpose. Both prescriptions are pinned clean at every site and evaluated. - **Same sources, same grade.** The grade is the one the site's `type-mismatch*` code carried: an error at a site that declares its fault outcome (fail-closed rule, advisory rule, record-triggered flow, sweep of the typed object, a member read under `bareNamesUnproven`), a warning elsewhere (formula field, flow condition with no declared outcome, unproven bare name). Review S3 on #39072 stays as ruled: the three S3 sources keep the warning grade, now under the new code. - **Final spelling, measured against the ledger.** The working name `date-text-ordering-run-may-fail` was not taken. In this ledger a `-run-fails` / `-run-may-fail` / `-fail-closed` / `-fail-open` / `-sweep-run-fails` / `-value-run-may-fail` suffix names the fault outcome a sentence states at one site. This verdict has no fault, so it has no outcome to name, and its sentence is the same at every site. The contract ("a code names ONE message template") then gives one code with no suffix. That is the precedent of `list-equality` and `date-duration-value`, and the shape of the `date-text-arithmetic` / `date-text-call` family names. It does not match `DATE_TEXT_FAMILY_RE` (`date-text-(call|arithmetic)`), so the item-1 precedence never takes it as a date-text fault. - **A date-text fault beside the ordering is the finding at every grade.** The new sentence says its comparison does not fault, so where the same source also holds a date-text fault (`record.due_date > record.title && record.due_date - record.borrow_date > duration('1h')`), the date-text error wins at error sites too. At warning sites it already won (item 1). At error sites this moves the code from `type-mismatch*-fails` to `date-text-arithmetic*`, at the same grade. - **`cel-engine.ts`.** `firstTypeMismatch` reports which mismatch is the kept ordering (`dateTextOrdering: true`, from the `keptOrdering` flag it already computed). This is three code lines (one result field, two spreads) and their doc comment beyond the claim's "comment only" surface, declared below. The two comments that still called item 4 open are rewritten (N8): `cel-engine.ts`, beside `offendingRecordRead(..., !keptOrdering)`, and the S3 pin's comment in `validate-date-text-arithmetic.test.ts`. - **`@objectstack/lint`, `validate-expressions.ts`.** This is one consumer branch that matched the old code on this shape. The `#30026` note, which says why a time-relative sweep of another object only warns, fired on `type-mismatch-run-may-fail` warnings. The ordering was served as that code, so the note was printed for it. It now counts `date-text-ordering` warnings at a flow condition too, so the note still prints for the ordering, as before. Without this, the note would silently drop for `due_date > title` on such a flow (measured on the built lint: the warning alone, no note). ### Consumer pins of the old code on this shape Updated, every one: - `packages/formula/src/validate-date-text-arithmetic.test.ts`: the #32595 rows (eight ordering rows, `type-mismatch-fail-closed` to `date-text-ordering`; `record.title < today()` keeps `type-mismatch-fail-closed` as the control), the flattened macro row (`type-mismatch-run-may-fail` to `date-text-ordering`), the #38959 macro pins (`[due_date].exists(d, d > title)` and the inner-map source, `type-mismatch-run-fails` to `date-text-ordering`), and the S3 pin (three sources `warning:type-mismatch-run-may-fail` to `warning:date-text-ordering`, member control `error:type-mismatch-run-fails` to `error:date-text-ordering`). - `packages/formula/src/expression-refusal-codes.test.ts`: the new code's pins, and one sweep source (`record.close_date < record.name`) so the closed-set sweep reaches it. The sweep budget docblock's call count (a volatile count) is replaced by its formula, per AGENTS.md. - `packages/lint/src/validate-expressions.ts` (source, above). Searched, with nothing pinning the old code or sentence on this shape. Each suite below ran green against the rebuilt formula: - flow publish and registration: `packages/objectql/src/publish-type-mismatch-fail-closed.test.ts` (12 passed), `packages/services/service-automation/src/flow-registration-checks.test.ts` (35 passed); - lint: the whole `@objectstack/lint` suite (261 files, 10,327 passed); - MCP and validate tool: `packages/mcp/src/mcp-validate-expression.test.ts` (80 passed); - REST envelope: no test pins a formula refusal code. The publish door answers `INVALID_METADATA` with the message, and the grade is unchanged, so the status is too; - dogfood and CLI: `git grep` of tests, `packages/qa`, `examples` and `docs/qa` for the old sentence on a date-vs-text source and for the operand spellings `Timestamp < string` / `string < google.protobuf.Timestamp`: no hit outside formula. ## Tests - New top-level describe in `validate-date-text-arithmetic.test.ts`, "a date ordered against a text field is served under its own code, with a true sentence (#38959 item 4)". It covers: - `record.due_date > record.title` and its reverse, and a datetime pair, at seven sites, each at the grade the old code carried there; - the sentence: the first-sentence shape, the "does not fault" clause, and no fault wording; - the run evaluates each source; - the text-order answer; - both prescriptions clean at every site; - CONTROL: a real mismatch (`record.title > 5`, `record.title < today()`) keeps `type-mismatch*` at every site and faults; - a date-text fault beside the ordering is the finding at every site, and faults. - New top-level describe in `packages/lint/src/validate-expressions.mismatch-precedence-38959.test.ts` (spec-valid fixtures). It covers the publish lint over: - a record-triggered flow: error, new sentence; - a sweep of the typed object: error; - a sweep of another object: warning plus the note; - CONTROL: `title > 5` keeps `type mismatch`. - No HTTP envelope carries this code. The lint door drops formula codes into its finding, and the publish door answers `INVALID_METADATA`, so no `status` assertion applies. `code` is asserted at the formula layer. <details><summary>Runs at 0fee6f4 (after merging origin/main 27ce3c0)</summary> - `pnpm --filter @objectstack/formula build && … vitest run --maxWorkers=2`: 72 files, 2270 passed; `@objectstack/lint` vitest: 261 files, 10327 passed (one `os-verify-lock` run, VERDICT command-exit 0). - `pnpm --filter @objectstack/formula typecheck` and `pnpm --filter @objectstack/lint typecheck` (both include `check:test-typecheck`): exit 0, at 037ff18 (pre-merge; the merge brought no formula or lint change). - mcp `mcp-validate-expression.test.ts` 80 passed; objectql `publish-type-mismatch-fail-closed.test.ts` 12 passed; service-automation `flow-registration-checks.test.ts` 35 passed (against the rebuilt formula and lint). - Sweep case wall time, `expression-refusal-codes.test.ts` alone: 461 ms and 252 ms, against its 16 000 ms budget. </details> <details><summary>Ablations (scripts/ablation-replace.mjs, each restore verified: blob equals HEAD, git diff HEAD empty)</summary> - `if (mismatch.dateTextOrdering) {` to `if (false) {` (the new branch): the two formula files, 34 failed. - `}, true);` to `}, false);` (date-text precedence at every grade): 5 failed, the precedence pins at the error sites. - `cel-engine.ts` root-pass flag to `...(false ? …)`: 14 failed. First-pass flag to `...(false ? …)`: 18 failed. - lint counter `(w.code === 'date-text-ordering' && scope === 'flattened')` to `(false)`: 1 failed, the sweep-note pin. </details> ## Acceptance notes - **File surface.** The claim lists `cel-engine.ts` for its comment only. The verdict's identity is known only inside `firstTypeMismatch` (`keptOrdering`), so three code lines there carry it out. Rebuilding it in `validate.ts` from the operand spelling would mislabel `bool + DateText` real faults. The lint source line is the consumer branch named above. Both are outside the stated surface and are reported to the seat. - **A real mismatch beside the ordering is still the finding.** Measured: `record.due_date > record.title || record.active + 1 > 2` and `due_date > title && notes * 2 > 1` answer the `bool + int` / `string * int` mismatch under its `type-mismatch*` code, not the ordering. The new sentence speaks of "this comparison" only. - `packages/spec/src/migrations/entries/semantic/19.flow-condition-mismatch-warning-and-index-mismatch-refused.ts` (#39072) describes the ordering as "the mismatch kept as before" and its warning grade. Both still hold in grade, and it names no code for it. It is untouched. - `content/docs/releases/**` and `CHANGELOG.md` are untouched; the changeset names the code move. ## Verification Read first, by risk: 1. `packages/formula/src/validate.ts`: the `if (mismatch.dateTextOrdering)` branch and `dateTextOver(…, always)`. 2. `packages/formula/src/cel-engine.ts`: the two `dateTextOrdering` spreads. 3. `packages/lint/src/validate-expressions.ts`: the counter line. Two-minute check: `pnpm --filter @objectstack/formula exec vitest run --maxWorkers=2 src/validate-date-text-arithmetic.test.ts -t "item 4"`. Expect every case green, including the seven per-site grade cases for each pair and the two CONTROL blocks. <details><summary>Gates: dispatch-gates --commands (71 families) and --ran reconciliation</summary> - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` at 0fee6f4: 71 families. - 67 ran with exit 0, each exit captured before any pipe. - `--ran` reconciliation: "71 derived famil(ies) accounted for — 67 run, 4 NOT-MEASURED". - NOT MEASURED, left to CI: - `check:dual-build-cjs-loads`: exit 3, needs a full build; - `check:query-options-erasure`: exit 124 at my 200 s per-gate timeout; - `check:slot-lookup` and `check:type-check-debt`: not started, over the foreground cap in the earlier rounds on this card. - `check:nul-bytes`, `check:doc-authoring`, `check:issue-citations`, `check:adr-0087-registration --base origin/main`, `check:empty-changeset`, `check:changeset-no-major`, `check:closing-keyword-parity`: exit 0. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYnrQ7UMtHofKQVjcH2)_ <!-- signed: repo:objectstack@os-justin · os-justin · session_01QSeKYnrQ7UMtHofKQVjcH2 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 355e8e3 commit 0c6f679

8 files changed

Lines changed: 456 additions & 45 deletions
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@objectstack/formula': patch
3+
'@objectstack/lint': patch
4+
---
5+
6+
fix(formula): a date ordered against a text field gets its own refusal code, `date-text-ordering`, with a sentence that says what the run does (#38959 item 4)
7+
8+
Clause-②: yes
9+
Metadata-protocol: none
10+
11+
**What changed.** `validateExpression` keeps refusing a date or datetime field ordered (`<`, `<=`, `>`, `>=`) against a text counterpart that is not a literal — a text field read directly or through a ternary, or text computed by `+`, `upper(…)`, `string(…)` or `isoDate(…)` (the #32595 verdict, unchanged) — at the same grade at every site: an error where the site declares its fault outcome (a fail-closed rule, an advisory rule, a record-triggered flow, a time-relative sweep of the typed object), a warning elsewhere (a formula field, a flow condition with no declared outcome, an unproven bare name). Until now it was served under the `type-mismatch*` code of the site, whose sentence says the field is "used against a number" and that "the expression faults". Neither is true: the runtime holds a date field as its text, so the comparison evaluates as a text comparison and does not fault. It is now served under one new code in the closed `EXPRESSION_REFUSAL_CODES` set, `date-text-ordering`, with params `operands`, `operator` and, when the counterpart is a field read, `reference`. Its sentence says that the comparison is answered by spelling, not by date, and prescribes `date(…)` to compare dates or `string(…)` on the date side to compare text on purpose.
12+
13+
**The code move, for a consumer that matches the old code on this shape.** Where you matched `type-mismatch`, `type-mismatch-fail-closed`, `type-mismatch-fail-open`, `type-mismatch-run-fails`, `type-mismatch-sweep-run-fails` or `type-mismatch-run-may-fail` and the source orders a date field against text, the refusal now carries `date-text-ordering`; it arrives in `errors[]` or `warnings[]` exactly as the old one did. Add a catalogue row for `date-text-ordering`: its params carry no `held`. A real type mismatch (text or a boolean against a number, text against `today()`) keeps its `type-mismatch*` code. Where the same source also holds a date-text fault (`record.due_date > record.title && record.due_date - record.borrow_date > duration('1h')`), that fault's `date-text-arithmetic*` / `date-text-call*` error is the finding at every site, as it already was where the ordering was a warning; where the ordering was an error this moves the code from `type-mismatch*` to the date-text one, at the same grade.
14+
15+
**`@objectstack/lint`.** A time-relative flow that sweeps another object than the one its conditions are typed against still gets its note saying why a condition's verdict is a warning there, when that warning is `date-text-ordering`, as it did when the same verdict was served as `type-mismatch-run-may-fail`.

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

Lines changed: 79 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,12 +1022,17 @@ const DATE_TEXT_COMPARISON_OPS: ReadonlySet<string> = new Set([...ORDERING_OPS,
10221022
* gate asks for it, so its answer is the one it gave before (see
10231023
* {@link firstTypeMismatch}'s `options`).
10241024
*/
1025-
function comparesDateTextAgainstUndeclared(source: string, env: Environment, macroElements = true): boolean {
1025+
function comparesDateTextAgainstUndeclared(
1026+
source: string,
1027+
env: Environment,
1028+
macroElements = true,
1029+
scope: 'record' | 'flattened' = 'record',
1030+
): KeptDateTextComparison | null {
10261031
let ast: unknown;
10271032
try {
10281033
ast = env.parse(rewriteNullableTernary(rewriteIndexedHas(source))).ast;
10291034
} catch {
1030-
return true;
1035+
return {};
10311036
}
10321037
/** The CEL type `node` checks to on its own, or `undefined` when it does not check. */
10331038
const typeOf = (node: unknown): string | undefined => {
@@ -1095,21 +1100,41 @@ function comparesDateTextAgainstUndeclared(source: string, env: Environment, mac
10951100
};
10961101
/** An element of the list `receiver` computes: `receiver[0]`. */
10971102
const elementOf = (receiver: unknown): CelNode => ({ op: '[]', args: [receiver, { op: 'value', args: 0n }] });
1098-
let found = false;
1103+
// [#38959 item 4] The comparison that keeps the verdict is reported, so the
1104+
// operator, operands and counterpart named are its own, never the Timestamp
1105+
// typing's first fault elsewhere in the source (`'Due: ' + record.due_date
1106+
// == 'x' && record.due_date < record.title` names `<`, not `+`).
1107+
let kept: KeptDateTextComparison | null = null;
1108+
/** A side's type as the Timestamp typing spells it: a date field's text is a Timestamp there. */
1109+
const spelled = (t: string | undefined): string =>
1110+
t === DATE_TEXT_CEL_TYPE ? 'google.protobuf.Timestamp' : t ?? 'dyn';
10991111
const visit = (v: unknown, bound: ReadonlyMap<string, CelNode>): void => {
1100-
if (found) return;
1112+
if (kept) return;
11011113
if (Array.isArray(v)) { for (const child of v) visit(child, bound); return; }
11021114
if (!isCelNode(v)) return;
11031115
if (DATE_TEXT_COMPARISON_OPS.has(v.op) && Array.isArray(v.args) && v.args.length === 2) {
11041116
// Without `macroElements` a macro variable proves nothing, as before #38959.
1105-
if (!macroElements && bound.size > 0 && readsBound(v.args, bound)) { found = true; return; }
1117+
if (!macroElements && bound.size > 0 && readsBound(v.args, bound)) { kept = { operator: v.op }; return; }
11061118
const [sa, sb] = (v.args as unknown[]).map((operand) => substitute(operand, bound));
11071119
const [a, b] = [sa.node, sb.node];
11081120
const [ta, tb] = [typeOf(a), typeOf(b)];
11091121
// A macro variable whose element does not check proves nothing: keep the verdict.
1110-
if ((sa.read && ta === undefined) || (sb.read && tb === undefined)) { found = true; return; }
1111-
if ((ta === DATE_TEXT_CEL_TYPE && !declared(b, tb)) || (tb === DATE_TEXT_CEL_TYPE && !declared(a, ta))) {
1112-
found = true;
1122+
if ((sa.read && ta === undefined) || (sb.read && tb === undefined)) {
1123+
kept = { operator: v.op, operands: `${spelled(ta)} ${v.op} ${spelled(tb)}` };
1124+
return;
1125+
}
1126+
const dateFirst = ta === DATE_TEXT_CEL_TYPE && !declared(b, tb);
1127+
if (dateFirst || (tb === DATE_TEXT_CEL_TYPE && !declared(a, ta))) {
1128+
const [other, otherType] = dateFirst ? [b, tb] : [a, ta];
1129+
// The counterpart is named only where it is a text field read; a
1130+
// computed text (`isoDate(today())`, `upper(…)`) or a macro's element
1131+
// is no reference to parse.
1132+
const read = otherType === 'string' ? typedFieldRef(other, scope) : null;
1133+
kept = {
1134+
operator: v.op,
1135+
operands: `${spelled(ta)} ${v.op} ${spelled(tb)}`,
1136+
...(read ? { counterpart: read.written } : {}),
1137+
};
11131138
return;
11141139
}
11151140
}
@@ -1125,7 +1150,21 @@ function comparesDateTextAgainstUndeclared(source: string, env: Environment, mac
11251150
visit(v.args, bound);
11261151
};
11271152
visit(ast, new Map());
1128-
return found;
1153+
return kept;
1154+
}
1155+
1156+
/**
1157+
* [#38959 item 4] The comparison {@link comparesDateTextAgainstUndeclared}
1158+
* found keeping the #32595 verdict, as written: its `operator`, its
1159+
* `operands` spelled as the Timestamp typing spells them, and `counterpart`,
1160+
* the text field read it orders the date against (`record.title`, `title`),
1161+
* present only where the counterpart is one. Every member is absent where no
1162+
* comparison is reported (an unparseable source keeps the verdict unnamed).
1163+
*/
1164+
interface KeptDateTextComparison {
1165+
readonly operator?: string;
1166+
readonly operands?: string;
1167+
readonly counterpart?: string;
11291168
}
11301169

11311170
/**
@@ -1431,6 +1470,25 @@ export function firstTypeMismatch(
14311470
*/
14321471
root?: 'record' | 'previous';
14331472
category: 'date-arith' | 'type-mismatch';
1473+
/**
1474+
* [#38959] Set when the `type-mismatch` is the ordering of a date field's
1475+
* text against a text counterpart no declared text names (#32595,
1476+
* {@link comparesDateTextAgainstUndeclared}): the verdict stands, but the
1477+
* run answers that comparison as a text comparison and does not fault, so
1478+
* `validate.ts` serves it under its own code (`date-text-ordering`), not a
1479+
* `type-mismatch*` sentence that says the expression faults.
1480+
*/
1481+
dateTextOrdering?: true;
1482+
/**
1483+
* [#38959 item 4] With `dateTextOrdering`, the comparison that keeps the
1484+
* verdict, as written — its operator, its operands and its text counterpart
1485+
* ({@link KeptDateTextComparison}). `operator`, `operands` and `field` above
1486+
* are the Timestamp typing's first fault, which a mixed source need not
1487+
* place on that comparison (`'Due: ' + record.due_date == 'x' &&
1488+
* record.due_date < record.title` faults first on `+`), and `field` keeps the
1489+
* grade it gives (#30025), so the sentence reads this instead.
1490+
*/
1491+
ordering?: KeptDateTextComparison;
14341492
} | null {
14351493
if (typeof source !== 'string' || !source.trim()) return null;
14361494
// An all-`dyn` record can never fault an overload — skip the parse entirely.
@@ -1481,17 +1539,22 @@ export function firstTypeMismatch(
14811539
* the mismatch kept is the ordering, not a fault the run meets.
14821540
*/
14831541
let keptOrdering = false;
1542+
let kept: KeptDateTextComparison | null = null;
14841543
const confirmAgainstDateText = (
14851544
m: RegExpExecArray,
14861545
recordRoots?: Readonly<Record<string, FieldCelType>>,
14871546
keepUndeclared = true,
14881547
): RegExpExecArray | null => {
14891548
keptOrdering = false;
1549+
kept = null;
14901550
if (!DATE_CEL_TYPES.has(m[1]) && !DATE_CEL_TYPES.has(m[3])) return m;
14911551
const dateTextEnv = buildTypedEnv(bareTypes, scope, 'date-text', recordRoots);
14921552
const r = unsoundOverload(dateTextEnv);
14931553
if (r && textOrBool(r)) return r[1] === DATE_TEXT_CEL_TYPE || r[3] === DATE_TEXT_CEL_TYPE ? m : r;
1494-
keptOrdering = keepUndeclared && comparesDateTextAgainstUndeclared(source, dateTextEnv, options.macroElements ?? true);
1554+
kept = keepUndeclared
1555+
? comparesDateTextAgainstUndeclared(source, dateTextEnv, options.macroElements ?? true, scope)
1556+
: null;
1557+
keptOrdering = kept !== null;
14951558
return keptOrdering ? m : null;
14961559
};
14971560
try {
@@ -1515,6 +1578,7 @@ export function firstTypeMismatch(
15151578
return {
15161579
operator, operands, celType, category: 'type-mismatch',
15171580
field: offendingField(source, bareTypes, celType, scope),
1581+
...(keptOrdering ? { dateTextOrdering: true as const, ordering: kept ?? {} } : {}),
15181582
};
15191583
}
15201584
// [#29959] A flattened condition reads the same field as `record.<field>`
@@ -1559,14 +1623,16 @@ export function firstTypeMismatch(
15591623
// Not for the kept ordering of a date against a text field, which the run
15601624
// answers: the name is what proves the read a record's under
15611625
// `bareNamesUnproven` (#30025), and an index read takes no part in that
1562-
// verdict (#32595, the question item 4 of #38959 leaves open), so only a
1563-
// member read is named there, as before #38959, and
1564-
// `record.due_date > record['title']` keeps the warning it had.
1626+
// verdict (#32595, which stands; item 4 of #38959 gave it its own code,
1627+
// `date-text-ordering`), so only a member read is named there, as before
1628+
// #38959, and `record.due_date > record['title']` keeps the warning grade
1629+
// it had.
15651630
const read = offendingRecordRead(source, fieldCelTypes, celType, !keptOrdering);
15661631
return {
15671632
operator: r[2], operands: `${r[1]} ${r[2]} ${r[3]}`, celType, category: 'type-mismatch',
15681633
field: read?.field ?? null,
15691634
...(read ? { root: read.root } : {}),
1635+
...(keptOrdering ? { dateTextOrdering: true as const, ordering: kept ?? {} } : {}),
15701636
};
15711637
} catch {
15721638
// A parse/other fault is the syntax checker's job (celEngine.compile); this

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

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,84 @@ const PINS: { readonly [C in ExpressionRefusalCode]: readonly [Pin<C>, ...Pin<C>
774774
'Compare a boolean with `true` / `false`, or use a number field.',
775775
},
776776
],
777+
// [#38959 item 4] A date field ordered against a text counterpart (#32595):
778+
// the run answers it as a text comparison, so one sentence at every site,
779+
// graded by the site — the warning a formula field gives, the error a
780+
// record-triggered flow gives — and a counterpart that is no field read
781+
// names none.
782+
'date-text-ordering': [
783+
{
784+
produce: () =>
785+
onlyWarning('predicate', 'record.due > record.name', { scope: 'record', fieldTypes: { due: 'date', name: 'text' } }),
786+
params: { operands: 'google.protobuf.Timestamp > string', operator: '>', reference: 'record.name' },
787+
message:
788+
'date ordered against text `google.protobuf.Timestamp > string` — `>` orders a date field against ' +
789+
'`record.name`, which holds text. The runtime holds a date field as its text (`YYYY-MM-DD`; a datetime as ' +
790+
'its ISO-8601 instant), so this comparison evaluates as a text comparison and does not fault: it answers ' +
791+
'which text sorts first, character by character, not which date is later. To compare dates, parse the text ' +
792+
'first with `date(record.name)`, which reads null where the text is not a date. To compare the texts on ' +
793+
'purpose, write the date side as `string(…)`.',
794+
},
795+
{
796+
produce: () =>
797+
onlyError('predicate', 'name <= due', {
798+
scope: 'flattened', fields: ['due', 'name'], fieldTypes: { due: 'date', name: 'text' }, faultOutcome: 'run-fails',
799+
}),
800+
params: { operands: 'string <= google.protobuf.Timestamp', operator: '<=', reference: 'name' },
801+
message:
802+
'date ordered against text `string <= google.protobuf.Timestamp` — `<=` orders a date field against ' +
803+
'`name`, which holds text. The runtime holds a date field as its text (`YYYY-MM-DD`; a datetime as ' +
804+
'its ISO-8601 instant), so this comparison evaluates as a text comparison and does not fault: it answers ' +
805+
'which text sorts first, character by character, not which date is later. To compare dates, parse the text ' +
806+
'first with `date(name)`, which reads null where the text is not a date. To compare the texts on ' +
807+
'purpose, write the date side as `string(…)`.',
808+
},
809+
{
810+
produce: () =>
811+
onlyWarning('predicate', 'isoDate(today()) < due', { scope: 'flattened', fields: ['due'], fieldTypes: { due: 'date' } }),
812+
params: { operands: 'string < google.protobuf.Timestamp', operator: '<' },
813+
message:
814+
'date ordered against text `string < google.protobuf.Timestamp` — `<` orders a date field against ' +
815+
'a text value. The runtime holds a date field as its text (`YYYY-MM-DD`; a datetime as ' +
816+
'its ISO-8601 instant), so this comparison evaluates as a text comparison and does not fault: it answers ' +
817+
'which text sorts first, character by character, not which date is later. To compare dates, parse the text ' +
818+
'first with `date(…)`, which reads null where the text is not a date. To compare the texts on ' +
819+
'purpose, write the date side as `string(…)`.',
820+
},
821+
// [#38959 item 4, L2 S1] The params are the ordering's own in a mixed
822+
// source: the Timestamp typing faults first on the concatenation (`+`),
823+
// yet the operator, operands and counterpart named are the `<`'s.
824+
{
825+
produce: () =>
826+
onlyWarning('predicate', "'Due: ' + record.due == 'x' && record.due < record.name", {
827+
scope: 'record', fieldTypes: { due: 'date', name: 'text' },
828+
}),
829+
params: { operands: 'google.protobuf.Timestamp < string', operator: '<', reference: 'record.name' },
830+
message:
831+
'date ordered against text `google.protobuf.Timestamp < string` — `<` orders a date field against ' +
832+
'`record.name`, which holds text. The runtime holds a date field as its text (`YYYY-MM-DD`; a datetime as ' +
833+
'its ISO-8601 instant), so this comparison evaluates as a text comparison and does not fault: it answers ' +
834+
'which text sorts first, character by character, not which date is later. To compare dates, parse the text ' +
835+
'first with `date(record.name)`, which reads null where the text is not a date. To compare the texts on ' +
836+
'purpose, write the date side as `string(…)`.',
837+
},
838+
// [L2 S1] A text field read elsewhere in the source is not the
839+
// counterpart: `isoDate(today())` is computed text, so no reference.
840+
{
841+
produce: () =>
842+
onlyError('predicate', "record.name == 'a' && record.due > isoDate(today())", {
843+
scope: 'record', fieldTypes: { due: 'date', name: 'text' }, faultOutcome: 'fail-closed',
844+
}),
845+
params: { operands: 'google.protobuf.Timestamp > string', operator: '>' },
846+
message:
847+
'date ordered against text `google.protobuf.Timestamp > string` — `>` orders a date field against ' +
848+
'a text value. The runtime holds a date field as its text (`YYYY-MM-DD`; a datetime as ' +
849+
'its ISO-8601 instant), so this comparison evaluates as a text comparison and does not fault: it answers ' +
850+
'which text sorts first, character by character, not which date is later. To compare dates, parse the text ' +
851+
'first with `date(…)`, which reads null where the text is not a date. To compare the texts on ' +
852+
'purpose, write the date side as `string(…)`.',
853+
},
854+
],
777855
'field-near-miss': [
778856
{
779857
produce: () => onlyWarning('predicate', "stauts == 'x'", { fields: ['status'], objectName: 'deal' }),
@@ -1012,6 +1090,8 @@ const SWEEP_SOURCES: readonly string[] = [
10121090
"timestamp(record.close_date) + duration('24h')",
10131091
'isoDate(close_date) == "2026-01-01"',
10141092
'record.name > 5',
1093+
// [#38959 item 4] A date field ordered against a text field: `date-text-ordering`.
1094+
'record.close_date < record.name',
10151095
'record.active + 1 > 5',
10161096
"record.account == 'a1' && record.account.name == 'x'",
10171097
"record.account.owner.name == 'x'",
@@ -1153,8 +1233,8 @@ function refusalKey(said: ExprValidationError): string {
11531233
}
11541234

11551235
/**
1156-
* The validateExpression sweep's budget. The case is synchronous: 6,144
1157-
* validateExpression calls (3 roles x 128 inputs x 16 schemas), most of the
1236+
* The validateExpression sweep's budget. The case is synchronous: one
1237+
* validateExpression call per role x input x schema, most of the
11581238
* time in building a typed CEL environment for each call. Its work is the
11591239
* sweep's breadth, which is the claim, so the breadth stays; only re-judging
11601240
* duplicate refusals was cut (see the case). Readings of the case, in ms:

0 commit comments

Comments
 (0)