Skip to content

Commit 8b550f8

Browse files
fix(formula): a flow value envelope's date-text refusal says the run fails when the value is computed (#35358)
<!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgRuogP8Tp8XyFXLc92Bxvo6)_ repo:objectstack#5 · os-bill · session_01Utp6CZiaBg6rk7dpy1s9Me Fixes #34660 Clause-②: no Metadata-protocol: none ## 维护者速读 1. 流程作者在流程的赋值或记录写入步骤里把日期字段当文本计算时,校验和发布时的报错原来说“条件运行时流程会失败”,现在改为说“计算这个值时流程会在这一步停下”。 2. 这一步根本没有条件,旧说法会让作者去找一个不存在的条件,这是流程报错文案的体验问题。 3. 出错时只是这条报错的措辞或代码不对,同样的写法仍然被拒绝,流程条件处的报错不受影响,回滚即可恢复原样。 4. 无。 ## What changes - `packages/formula/src/validate.ts`: a flow value envelope (`ExprSchemaHint.flowValueEnvelope`: an `assignment` value, a `create_record` / `update_record` `fields.*` value) now takes its own date-text outcome arm, `value-run-may-fail`, instead of the flow-condition `run-may-fail` arm. Its fault clause reads: "this faults wherever `record.borrow_date` holds that text when the value is computed, and a flow value that cannot be computed fails the run: the flow stops at this step and the work the flow exists to do is not done (it does not read null)." The head (what the call or arithmetic is), the fix hint, the grade (error) and the location are unchanged; both doors still prefix the value-envelope sentence. - `packages/formula/src/expression-refusal.ts`: two codes join the closed set (params map with docblocks, `CODE_TABLE`): `date-text-call-value-run-may-fail` and `date-text-arithmetic-value-run-may-fail`. The names follow the ledger's one site-qualified precedent, `type-mismatch-sweep-run-fails`: family, then the site (`value`), then the outcome. The outcome stays `run-may-fail`, since the envelope faults only where the field holds the text when the value is computed. `DATE_TEXT_FAMILY_RE` already matches both codes and is unchanged. - Flow conditions keep `date-text-call-run-may-fail` / `date-text-arithmetic-run-may-fail` / `-run-fails` and their sentence byte for byte (the existing per-code message pins are untouched and green). - Changeset: `@objectstack/formula` patch. ## Tests - `validate-date-text-arithmetic.test.ts`: a new top-level describe pins the shared entry both doors call. For an `assignment`-value source and an `update_record` `fields.*` source it checks the new code, the value clause, no "condition" anywhere in the message, and the fix hint kept. CONTROL: a flow condition over the same field keeps the `-run-may-fail` code and its condition sentence. CONTROL: the accept set is unchanged (taught shift, datetime field, no field types). The #34451 block's three code expectations move to the new codes. - `expression-refusal-codes.test.ts`: one exact pin (code, params, whole message) per new code; the sweep gains a flow value-envelope schema so its positive control reaches both new codes. The sweep budget docblock records the re-measure (see Acceptance notes). ## Acceptance notes - **One verdict for lint and `registerFlow`.** Both doors reach the same call. `@objectstack/lint`'s `checkDeclaredValue` and `@objectstack/service-automation`'s `valueEnvelopeRefusals` (`dag-traversal.ts`) each call `validateExpression('value', envelope, { fieldTypes, flowValueEnvelope: true })` and prefix the message. The formula pin covers that call. The door suites live outside this claim's file surface; they assert the fix hint and the prefix, never the code or the condition wording, and they stay green. A one-shot measurement through both built doors gave the same clause from each (Verification). - **A1 holds.** No code reader outside `packages/formula` keys on the `-run-may-fail` codes for value envelopes. `git grep` of `date-text-call-run-may-fail` / `date-text-arithmetic-run-may-fail` outside `packages/formula/src` finds only CHANGELOGs. `EXPRESSION_REFUSAL_CODES` has no consumer outside the package, and no i18n pack, docs catalogue, skill or eval names these codes. - **A2 holds.** Clause-② stays `no`. The same sources are refused at the same grade; only the code and the outcome sentence change, and the accept-set CONTROL pins this. New members of the closed refusal-code set are added under a `no` declaration, as with earlier code additions. - **Sweep budget.** The sweep grew from 15 schemas to 16. Measured locally (4 vCPU, file alone): 192 to 225 ms with the new schema, 186 to 267 ms for the base 15 in the same session. The 16th schema stands down on every source but a date field's value, so the 16000 ms budget stands, and the docblock records the reading. - Seen, not fixed here: `registerFlow`'s multi-refusal header always explains template braces ("Predicates … must not wrap references in `{…}` template braces …"), whatever the listed refusal is. A date-text verdict is listed under that header too. Reported to the seat as a finding. ## 席位核对 - Read first: `packages/formula/src/validate.ts` (`dateArmFault`, the `value-run-may-fail` branch; `flowValueEnvelopeDateTextIssue`), then `packages/formula/src/expression-refusal.ts` (the two new ledger rows). - Two-minute check: `pnpm --filter @objectstack/formula exec vitest run src/validate-date-text-arithmetic.test.ts src/expression-refusal-codes.test.ts`. Expect 141 tests passed, including the `(#34660)` describe. ## Verification <details><summary>Red leg (tests committed alone at 240b77b, source at base)</summary> ```text × refuses the measured expression under the value-run-may-fail arm, with the addDays shift × refuses the bare call, a previous.FIELD read, and date-text arithmetic over record.FIELD × an assignment value: the value arm's code and sentence, at the same grade, with the fix hint kept × an update_record fields.* value: the value arm's code and sentence, at the same grade, with the fix hint kept × has a pin for every code, and no pin for a code outside the set AssertionError: expected [ 'date-text-call-run-may-fail' ] to deeply equal [ 'date-text-call-value-run-may-fail' ] Test Files 2 failed (2) · Tests 5 failed | 134 passed (139) os-verify-lock: VERDICT command-exit 1 ``` </details> <details><summary>Green leg and package suites (head 2cd098b)</summary> ```text vitest run src/validate-date-text-arithmetic.test.ts src/expression-refusal-codes.test.ts Test Files 2 passed (2) · Tests 141 passed (141) · VERDICT command-exit 0 pnpm --filter @objectstack/formula test Test Files 68 passed (68) · Tests 1888 passed (1888) · VERDICT command-exit 0 pnpm --filter @objectstack/formula typecheck check:test-typecheck: OK · VERDICT command-exit 0 service-automation src/builtin/assignment-value-envelope.test.ts: Tests 76 passed (76) lint src/validate-expressions.test.ts: Tests 515 passed (515) · VERDICT command-exit 0 ``` </details> <details><summary>Both doors, measured on the built packages (one-shot, not committed)</summary> ```text == assignment `timestamp(record.borrow_date)` lint: error flows[0].nodes[1].config.assignments.due lint clause: this faults wherever `record.borrow_date` holds that text when the value is computed, and a flow value that cannot be computed fails the run: the flow stops at this step and the work the flow exists to do is not done (it does not read null). registerFlow clause: (identical) == update_record `record.due_date - record.borrow_date` lint: error flows[0].nodes[1].config.fields.due_date registerFlow clause: (identical to lint) ``` </details> <details><summary>Derived gates (head 2cd098b)</summary> ```text dispatch-gates --commands --repo objectstack-ai/objectstack: 65 commands derived (5 changed paths vs merge base 81c0947) 64 exit 0; 1 exit 3 PREREQUISITE NOT MET: pnpm check:dual-build-cjs-loads (workspace dist not built), NOT MEASURED locally, CI Lint & Repo Gates runs it --ran: 65 derived famil(ies) accounted for — 64 run, 1 NOT-MEASURED (1 DERIVED from a recorded exit 3), 0 UNRUN pnpm check:nul-bytes: exit 0 (in the derived set) overlap-check --branch=claude/issue-34660-value-envelope-refusal-wording: origin/main merges cleanly, 0 PR heads share a file, VERDICT clean exit 0 test:repo (vitest repo project): not run locally, CI Test Core runs it ``` </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 27eea3e commit 8b550f8

5 files changed

Lines changed: 191 additions & 22 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@objectstack/formula': patch
3+
---
4+
5+
fix(formula): a flow value envelope's date-text refusal says the run fails when the value is computed, not when a condition runs
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A flow value envelope (an `assignment` value, or a `create_record` / `update_record` `fields.*` value) that hands a `date` field's text to a call it cannot take (`timestamp(record.borrow_date)`) or does arithmetic on it (`record.due_date - record.borrow_date`) is refused by `os validate` and by `registerFlow`. The refusal reused the flow-condition sentence: "this faults wherever `record.borrow_date` holds that text when the condition runs, and a flow condition that cannot be evaluated fails the run: the flow stops at this condition …". A value slot has no condition. It now reads "… when the value is computed, and a flow value that cannot be computed fails the run: the flow stops at this step and the work the flow exists to do is not done (it does not read null)."
11+
12+
- **Two codes join `ExpressionRefusalCode`** (`EXPRESSION_REFUSAL_CODES`), with the params of the code each splits from: `date-text-call-value-run-may-fail` (params of `date-text-call`) and `date-text-arithmetic-value-run-may-fail` (params of `date-text-arithmetic`). `validateExpression` serves them where `ExprSchemaHint.flowValueEnvelope` is set, in place of `date-text-call-run-may-fail` / `date-text-arithmetic-run-may-fail`. A consumer keyed to the old codes on a value envelope re-keys to the new ones.
13+
- **Unchanged:** the same sources are refused, at the same grade (an error), at the same location, with the same leading value-envelope sentence and the same fix hint. A flow condition keeps `date-text-call-run-may-fail` / `date-text-arithmetic-run-may-fail` and `-run-fails`, byte for byte.

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

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,26 @@ const PINS: { readonly [C in ExpressionRefusalCode]: readonly [Pin<C>, ...Pin<C>
464464
'`(datetime(b) - datetime(a)).getMinutes()` / `.getHours()`.',
465465
},
466466
],
467+
// [#34660] A flow value envelope: the run fails when the value is computed, and no condition runs there.
468+
'date-text-arithmetic-value-run-may-fail': [
469+
{
470+
produce: () =>
471+
onlyError('value', { dialect: 'cel', source: 'record.end_at - record.start_at' }, {
472+
fieldTypes: { start_at: 'datetime', end_at: 'datetime' },
473+
flowValueEnvelope: true,
474+
}),
475+
params: { operands: 'DateText - DateText', reference: 'record.start_at' },
476+
message:
477+
'date arithmetic `DateText - DateText` — `record.start_at` is a date field, and the runtime holds a date field ' +
478+
'as its text (`YYYY-MM-DD`, or an ISO-8601 instant for a date-time), which CEL can\'t do arithmetic on: ' +
479+
'this faults wherever `record.start_at` holds that text when the value is computed, and ' +
480+
'a flow value that cannot be computed fails the run: the flow stops at this step and the work the flow ' +
481+
'exists to do is not done (it does not read null). ' +
482+
'Use `daysBetween(a, b)` for the span in whole days, and `daysFromNow(n)` / `addDays(d, n)` / `addMonths(d, n)` to shift a date. ' +
483+
'For a span in hours or minutes, wrap each side in `datetime(…)` and read the Duration: ' +
484+
'`(datetime(b) - datetime(a)).getMinutes()` / `.getHours()`.',
485+
},
486+
],
467487
// [#32595] A call handed a date field's text that no overload accepts.
468488
'date-text-call': [
469489
{
@@ -585,6 +605,30 @@ const PINS: { readonly [C in ExpressionRefusalCode]: readonly [Pin<C>, ...Pin<C>
585605
'Parse the text into a timestamp first: `isoDate(date(start_at))`.',
586606
},
587607
],
608+
// [#34660] The same call in a flow value envelope, with the optional `shift` clause.
609+
'date-text-call-value-run-may-fail': [
610+
{
611+
produce: () =>
612+
onlyError('value', { dialect: 'cel', source: "isoDate(timestamp(record.borrow_date) + duration('168h'))" }, {
613+
fieldTypes: { borrow_date: 'date' },
614+
flowValueEnvelope: true,
615+
}),
616+
params: {
617+
call: 'timestamp(record.borrow_date)',
618+
reference: 'record.borrow_date',
619+
rewrite: 'date(record.borrow_date)',
620+
shift: 'isoDate(addDays(record.borrow_date, N))',
621+
},
622+
message:
623+
'`timestamp(record.borrow_date)` — `record.borrow_date` is a date field, and the runtime holds a date field as its text ' +
624+
'(`YYYY-MM-DD`, or an ISO-8601 instant for a date-time), which this call does not accept: ' +
625+
'this faults wherever `record.borrow_date` holds that text when the value is computed, and ' +
626+
'a flow value that cannot be computed fails the run: the flow stops at this step and the work the flow ' +
627+
'exists to do is not done (it does not read null). ' +
628+
'Parse the text into a timestamp first: `date(record.borrow_date)`. ' +
629+
'To shift it by N whole days and keep it a date, write `isoDate(addDays(record.borrow_date, N))`.',
630+
},
631+
],
588632
'date-duration-value': [
589633
{
590634
produce: () =>
@@ -954,6 +998,9 @@ const SWEEP_SCHEMAS: readonly (ExprSchemaHint | undefined)[] = [
954998
// [#29959] A flattened (flow) condition with no declared outcome reaches
955999
// `type-mismatch-run-may-fail`, bare and through `record.`.
9561000
{ scope: 'flattened', objectName: 'deal', fields: ['amount', 'name', 'active'], fieldTypes: { name: 'text', active: 'boolean' } },
1001+
// [#34660] A flow value envelope with a date field reaches the date-text
1002+
// verdicts' `-value-run-may-fail` codes.
1003+
{ fieldTypes: { close_date: 'date' }, flowValueEnvelope: true },
9571004
{ fields: ['status'] },
9581005
{ fieldTypes: { account: 'lookup' }, traversalHydration: true },
9591006
];
@@ -1011,8 +1058,8 @@ function refusalKey(said: ExprValidationError): string {
10111058
}
10121059

10131060
/**
1014-
* The validateExpression sweep's budget. The case is synchronous: 5,760
1015-
* validateExpression calls (3 roles x 128 inputs x 15 schemas), most of the
1061+
* The validateExpression sweep's budget. The case is synchronous: 6,144
1062+
* validateExpression calls (3 roles x 128 inputs x 16 schemas), most of the
10161063
* time in building a typed CEL environment for each call. Its work is the
10171064
* sweep's breadth, which is the claim, so the breadth stays; only re-judging
10181065
* duplicate refusals was cut (see the case). Readings of the case, in ms:
@@ -1025,6 +1072,11 @@ function refusalKey(said: ExprValidationError): string {
10251072
* - Local, 4 vCPU, this file alone: 757 to 830 before the cut, 534 to 645
10261073
* after it. Pinned to one CPU shared with two busy loops: 2542 to 3063
10271074
* before, 1961 to 2137 after.
1075+
* - Local, 4 vCPU, this file alone, when the flow value-envelope schema
1076+
* joined (15 schemas to 16): 192 to 225 with it, 186 to 267 for the 15
1077+
* in the same session. That schema stands down on every source but a
1078+
* date field's value, so the 16th adds nothing measurable and the budget
1079+
* stands.
10281080
*
10291081
* The rule follows `packages/cli/test/hook-timeout-override-refusal.test.ts`:
10301082
* 3x the slowest reading, rounded up to the next second. 3 x 5034 = 15102, so

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ export interface ExpressionRefusalParams {
191191
* `reference` is the field as written, when it is known. A flattened (flow)
192192
* condition is `date-text-arithmetic-run-fails` / `-run-may-fail`; a
193193
* fail-closed site is `date-text-arithmetic-fail-closed`, an advisory rule's
194-
* `date-text-arithmetic-fail-open`.
194+
* `date-text-arithmetic-fail-open`, and a flow value envelope's
195+
* `date-text-arithmetic-value-run-may-fail`.
195196
*/
196197
'date-text-arithmetic': { readonly operands: string; readonly reference?: string };
197198
/**
@@ -210,6 +211,16 @@ export interface ExpressionRefusalParams {
210211
'date-text-arithmetic-run-fails': { readonly operands: string; readonly reference?: string };
211212
/** [#30016] ERROR: `date-text-arithmetic`, at a `date-arithmetic-run-may-fail` site. */
212213
'date-text-arithmetic-run-may-fail': { readonly operands: string; readonly reference?: string };
214+
/**
215+
* [#34660] ERROR: `date-text-arithmetic` in a flow VALUE envelope
216+
* (`ExprSchemaHint.flowValueEnvelope`: an `assignment` value, a
217+
* `create_record` / `update_record` `fields.*` value) — it faults, and so
218+
* fails the run at the step, wherever the field holds that text when the
219+
* value is computed. No condition runs at a value slot, so its sentence is
220+
* not `-run-may-fail`'s. The `sweep` precedent names the site before the
221+
* outcome (`type-mismatch-sweep-run-fails`); `value` is this site.
222+
*/
223+
'date-text-arithmetic-value-run-may-fail': { readonly operands: string; readonly reference?: string };
213224
/**
214225
* [#30250] ERROR: `date-arithmetic` at a site that FAILS CLOSED (an `error`
215226
* validation rule, a field write rule, an option `visibleWhen`, a hook
@@ -237,13 +248,16 @@ export interface ExpressionRefusalParams {
237248
* checks clean and faults on the `YYYY-MM-DD` text, `date(…)` in place of the
238249
* call, with the optional `shift` clause. A flattened (flow) condition is
239250
* `date-text-call-run-fails` / `-run-may-fail`; a fail-closed site is
240-
* `date-text-call-fail-closed`, an advisory rule's `date-text-call-fail-open`.
251+
* `date-text-call-fail-closed`, an advisory rule's `date-text-call-fail-open`,
252+
* and a flow value envelope's `date-text-call-value-run-may-fail`.
241253
*/
242254
'date-text-call': DateTextCallParams;
243255
/** [#32595] ERROR: `date-text-call`, at a `date-arithmetic-run-fails` site. */
244256
'date-text-call-run-fails': DateTextCallParams;
245257
/** [#32595] ERROR: `date-text-call`, at a `date-arithmetic-run-may-fail` site. */
246258
'date-text-call-run-may-fail': DateTextCallParams;
259+
/** [#34660] ERROR: `date-text-call`, at a `date-text-arithmetic-value-run-may-fail` site (a flow value envelope). */
260+
'date-text-call-value-run-may-fail': DateTextCallParams;
247261
/** [#32595] ERROR: `date-text-call`, at a `date-arithmetic-fail-closed` site. */
248262
'date-text-call-fail-closed': DateTextCallParams;
249263
/** [#32595] ERROR: `date-text-call`, at a `date-arithmetic-fail-open` site. */
@@ -359,13 +373,15 @@ const CODE_TABLE = {
359373
'date-arithmetic-run-may-fail': true,
360374
'date-text-arithmetic-run-fails': true,
361375
'date-text-arithmetic-run-may-fail': true,
376+
'date-text-arithmetic-value-run-may-fail': true,
362377
'date-arithmetic-fail-closed': true,
363378
'date-text-arithmetic-fail-closed': true,
364379
'date-arithmetic-fail-open': true,
365380
'date-text-arithmetic-fail-open': true,
366381
'date-text-call': true,
367382
'date-text-call-run-fails': true,
368383
'date-text-call-run-may-fail': true,
384+
'date-text-call-value-run-may-fail': true,
369385
'date-text-call-fail-closed': true,
370386
'date-text-call-fail-open': true,
371387
'date-duration-value': true,

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

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,11 @@ describe('a flow value envelope typed for the date-text family alone (#34451)',
442442
/** The expression cloud measured in an `update_record` node's `fields.due_date`. */
443443
const MEASURED = "isoDate(timestamp(record.borrow_date) + duration('168h'))";
444444

445-
it('refuses the measured expression under the run-may-fail arm, with the addDays shift', () => {
445+
it('refuses the measured expression under the value-run-may-fail arm, with the addDays shift', () => {
446446
const r = validateExpression('value', { dialect: 'cel', source: MEASURED }, ENVELOPE);
447447
expect(r.warnings).toEqual([]);
448448
expect(r.errors.map((e) => ({ code: e.code, params: e.params }))).toEqual([{
449-
code: 'date-text-call-run-may-fail',
449+
code: 'date-text-call-value-run-may-fail',
450450
params: {
451451
call: 'timestamp(record.borrow_date)',
452452
reference: 'record.borrow_date',
@@ -458,9 +458,9 @@ describe('a flow value envelope typed for the date-text family alone (#34451)',
458458
});
459459

460460
it('refuses the bare call, a previous.<field> read, and date-text arithmetic over record.<field>', () => {
461-
expect(codes('timestamp(record.borrow_date)')).toEqual(['date-text-call-run-may-fail']);
462-
expect(codes('timestamp(previous.borrow_date)')).toEqual(['date-text-call-run-may-fail']);
463-
expect(codes("record.borrow_date - duration('24h')")).toEqual(['date-text-arithmetic-run-may-fail']);
461+
expect(codes('timestamp(record.borrow_date)')).toEqual(['date-text-call-value-run-may-fail']);
462+
expect(codes('timestamp(previous.borrow_date)')).toEqual(['date-text-call-value-run-may-fail']);
463+
expect(codes("record.borrow_date - duration('24h')")).toEqual(['date-text-arithmetic-value-run-may-fail']);
464464
});
465465

466466
it('CONTROL: a datetime field under timestamp(), and the taught shift, stay clean', () => {
@@ -492,6 +492,70 @@ describe('a flow value envelope typed for the date-text family alone (#34451)',
492492
});
493493
});
494494

495+
// [#34660] A value slot computes a value; no condition runs there. The
496+
// envelope's date-text verdict names the value being computed and the step,
497+
// under its own codes, while a flow condition over the same source keeps the
498+
// `-run-may-fail` codes and sentence. One entry serves both doors:
499+
// `@objectstack/lint`'s `validateStackExpressions` (`checkDeclaredValue`) and
500+
// `@objectstack/service-automation`'s `registerFlow` (`valueEnvelopeRefusals`)
501+
// each call `validateExpression('value', envelope, { fieldTypes,
502+
// flowValueEnvelope: true })` for every `assignment` value and every
503+
// `create_record` / `update_record` `fields.*` value, and prefix the message
504+
// with the value-envelope sentence; this pins that call, so the two doors keep
505+
// one verdict.
506+
describe('a flow value envelope\'s date-text verdict names the value, not a condition (#34660)', () => {
507+
/** The object a record-triggered flow binds as `record`: a loan. */
508+
const fieldTypes = { title: 'text', borrow_date: 'date', due_date: 'date', picked_up_at: 'datetime' };
509+
/** The hint both doors hand the shared entry, for an `assignment` value and a `fields.*` value alike. */
510+
const DOOR_HINT: ExprSchemaHint = { fieldTypes, flowValueEnvelope: true };
511+
/** The same object's flow condition with no declared outcome: the `-run-may-fail` arm. */
512+
const CONDITION: ExprSchemaHint = { fields: Object.keys(fieldTypes), fieldTypes };
513+
/** What each slot computes: an `assignment` value `due`, an `update_record` `fields.loan_days`. */
514+
const SLOTS = [
515+
["an assignment value", "isoDate(timestamp(record.borrow_date) + duration('168h'))", 'date-text-call-value-run-may-fail'],
516+
['an update_record fields.* value', 'record.due_date - record.borrow_date', 'date-text-arithmetic-value-run-may-fail'],
517+
] as const;
518+
const VALUE_CLAUSE =
519+
'this faults wherever `record.borrow_date` holds that text when the value is computed, and a flow value that ' +
520+
'cannot be computed fails the run: the flow stops at this step and the work the flow exists to do is not done ' +
521+
'(it does not read null).';
522+
523+
it.each(SLOTS)('%s: the value arm\'s code and sentence, at the same grade, with the fix hint kept', (_slot, source, code) => {
524+
const r = validateExpression('value', { dialect: 'cel', source }, DOOR_HINT);
525+
expect(r.ok).toBe(false);
526+
expect(r.warnings).toEqual([]);
527+
expect(r.errors.map((e) => e.code)).toEqual([code]);
528+
const { message } = r.errors[0];
529+
expect(message).toContain(VALUE_CLAUSE);
530+
expect(message).not.toMatch(/condition/);
531+
expect(message).toMatch(code.startsWith('date-text-call-')
532+
? /Parse the text into a timestamp first: `date\(record\.borrow_date\)`\./
533+
: /Use `daysBetween\(a, b\)` for the span in whole days/);
534+
});
535+
536+
it('CONTROL: a flow condition reading the same field keeps the run-may-fail codes and their condition sentence', () => {
537+
for (const [source, code] of [
538+
['timestamp(record.borrow_date) < now()', 'date-text-call-run-may-fail'],
539+
["record.due_date - record.borrow_date > duration('24h')", 'date-text-arithmetic-run-may-fail'],
540+
] as const) {
541+
const r = validateExpression('predicate', source, CONDITION);
542+
expect(r.errors.map((e) => e.code), source).toEqual([code]);
543+
expect(r.errors[0].message, source).toContain(
544+
'this faults wherever `record.borrow_date` holds that text when the condition runs, and a flow condition that ' +
545+
'cannot be evaluated fails the run: the flow stops at this condition and the work the flow exists to do is ' +
546+
'not done (it does not read null).',
547+
);
548+
}
549+
});
550+
551+
it('CONTROL: what the envelope accepts is unchanged — the taught shift, a datetime field, and no field types', () => {
552+
for (const source of ['isoDate(addDays(record.borrow_date, 7))', "isoDate(timestamp(record.picked_up_at) + duration('168h'))"]) {
553+
expect(validateExpression('value', { dialect: 'cel', source }, DOOR_HINT), source).toEqual({ ok: true, errors: [], warnings: [] });
554+
}
555+
expect(validateExpression('value', { dialect: 'cel', source: SLOTS[0][1] }).errors).toEqual([]);
556+
});
557+
});
558+
495559
describe('a flow condition\'s record.<field> / previous.<field> read takes the date-text family as its bare name does (#34662)', () => {
496560
/** A record-triggered flow's condition over a loan: the hint `@objectstack/lint` hands a start, edge or decision condition. */
497561
const fieldTypes = { title: 'text', borrow_date: 'date', due_date: 'date', picked_up_at: 'datetime' };

0 commit comments

Comments
 (0)