Skip to content

Commit f278fec

Browse files
committed
test(runtime): pin the flow publish door refusing record. / previous. date arithmetic; changeset narrowed, formula and spec minor
Claude-Session: https://claude.ai/code/session_01FEkQ5pb2t8Z8C64PkPyVt1 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 4426723 commit f278fec

2 files changed

Lines changed: 58 additions & 2 deletions

File tree

‎.changeset/34946-flow-record-date-arithmetic.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
---
2-
'@objectstack/formula': patch
2+
'@objectstack/formula': minor
3+
'@objectstack/spec': minor
34
---
45

56
fix(formula)!: a flow condition that does date arithmetic on `record.FIELD` or `previous.FIELD` is now refused, as the bare field name already was
67

78
Clause-②: no (narrowing)
8-
Metadata-protocol: none
9+
Metadata-protocol: narrowed
910

1011
<!-- adr-0087: registered flow-condition-record-date-arithmetic-refused -->
1112

‎packages/runtime/src/domains/meta-flow-condition-record-date-text.test.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ const loan = {
6262
fields: {
6363
title: { name: 'title', label: 'Title', type: 'text' },
6464
borrow_date: { name: 'borrow_date', label: 'Borrowed', type: 'date' },
65+
// [#34946] Required, so the null-guard gate draws no second finding on a comparison of it.
66+
due_date: { name: 'due_date', label: 'Due', type: 'date', required: true },
6567
picked_up_at: { name: 'picked_up_at', label: 'Picked up', type: 'datetime' },
6668
},
6769
};
@@ -150,3 +152,56 @@ describe('[#34662] the flow publish door refuses timestamp() over a date field r
150152
}
151153
}, 60_000);
152154
});
155+
156+
/** [#34946] The door's date-arithmetic findings on a refused publish. */
157+
const dateArithmeticIssues = (err: any) =>
158+
(err?.issues ?? []).filter((i: any) => i.rule === 'expression-invalid' && /^date arithmetic/.test(i.message));
159+
160+
/**
161+
* [#34946] The flow publish door refuses date arithmetic on a date field read
162+
* through `record.` / `previous.` in a flow condition, as it refuses the bare
163+
* name. The business case: an administrator publishes a record-triggered flow
164+
* on a loan that runs once the loan is a day past due (`record.due_date + 1 > 5`
165+
* written as if the date were a number). The run holds the field as its
166+
* `YYYY-MM-DD` text, the evaluator cannot add a number to it, and the flow
167+
* failed on every run while the door published it; the bare spelling was
168+
* refused. A `datetime` field takes exactly the bare name's verdict too, and an
169+
* ordering against `today()` still publishes.
170+
*/
171+
describe('[#34946] the flow publish door refuses date arithmetic on a date field read through record. / previous.', () => {
172+
it('⭐ LIT — refuses the bare name, `record.` and `previous.` alike, with INVALID_METADATA / 422, leaving the draft', async () => {
173+
const rig = await boot();
174+
for (const [name, read] of [
175+
['loan_due_bare', 'due_date'],
176+
['loan_due_record', 'record.due_date'],
177+
['loan_due_previous', 'previous.due_date'],
178+
] as const) {
179+
const err: any = await rig.publish(flowOn(name, `${read} + 1 > 5`));
180+
expect(err, `${read}: the publish was admitted`).toBeInstanceOf(Error);
181+
expect({ code: err.code, status: err.status }, read).toEqual({ code: 'INVALID_METADATA', status: 422 });
182+
const issues = dateArithmeticIssues(err);
183+
expect(issues, `${read}: ${JSON.stringify(err.issues)}`).toHaveLength(1);
184+
expect(issues[0].message).toContain(`date arithmetic \`google.protobuf.Timestamp + int\` — \`${read}\` is a date`);
185+
expect(await rig.state(name), read).toEqual(['draft']);
186+
}
187+
}, 60_000);
188+
189+
it('⭐ CONTROL — a datetime field\'s root reads take the bare name\'s refusal, and an ordering against today() publishes', async () => {
190+
const rig = await boot();
191+
for (const [name, read] of [
192+
['loan_picked_bare', 'picked_up_at'],
193+
['loan_picked_record', 'record.picked_up_at'],
194+
['loan_picked_previous', 'previous.picked_up_at'],
195+
] as const) {
196+
const err: any = await rig.publish(flowOn(name, `${read} + 1 > 5`));
197+
expect({ code: err?.code, status: err?.status }, read).toEqual({ code: 'INVALID_METADATA', status: 422 });
198+
const issues = dateArithmeticIssues(err);
199+
expect(issues, `${read}: ${JSON.stringify(err?.issues)}`).toHaveLength(1);
200+
expect(issues[0].message).toContain(`date arithmetic \`google.protobuf.Timestamp + int\` — \`${read}\` is a date`);
201+
expect(await rig.state(name), read).toEqual(['draft']);
202+
}
203+
const err = await rig.publish(flowOn('loan_due_ordering', 'record.due_date < today()'));
204+
expect(err?.issues ?? err, 'record.due_date < today(): the door refused').toBeUndefined();
205+
expect(await rig.state('loan_due_ordering')).toEqual(['active']);
206+
}, 60_000);
207+
});

0 commit comments

Comments
 (0)