Skip to content

Commit 52faf73

Browse files
committed
fix(lint): name every new refusal of a sweep-only flow, and count only the warning the time-relative note explains
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CaUg3ibF939L2RFB5D
1 parent 6bbf8e9 commit 52faf73

3 files changed

Lines changed: 43 additions & 9 deletions

File tree

‎.changeset/30026-time-relative-sweep-typing.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
'@objectstack/mcp': minor
44
---
55

6-
fix(lint)!: a time-relative flow whose start node names no `objectName` has its conditions typed against the object it sweeps (`timeRelative.object`), so a text-vs-number comparison there is refused like on a sweep of the start node's object; a sweep of another object is told why it only warns; and `validate_expression` takes the swept object (#30026)
6+
fix(lint)!: a time-relative flow whose start node names no `objectName` has its conditions typed against the object it sweeps (`timeRelative.object`), so a text-vs-number comparison, a read of a field the swept object does not declare and date arithmetic there are refused like on a sweep of the start node's object; a sweep of another object is told why it only warns; and `validate_expression` takes the swept object (#30026)
77

8-
Clause-②: yes (narrowing) — the author-time gate (`os build`, `os validate`, the package publish and the flow publish door) refuses a `type-mismatch` in the start, edge and `decision` conditions of a time-relative flow whose start node names no `objectName`, which it passed with no type verdict at all before. Added beside it (the widening half): the optional `sweepObject` input of the `validate_expression` MCP tool.
8+
Clause-②: yes (narrowing) — the author-time gate (`os build`, `os validate`, the package publish and the flow publish door) refuses, in the start, edge and `decision` conditions of a time-relative flow whose start node names no `objectName`, a `type-mismatch` (`type-mismatch-run-fails`), a `record.FIELD` read of a field the swept object does not declare (`unknown field`), and date arithmetic (`date-arithmetic-run-fails` / `date-text-arithmetic-run-fails`), which it passed with no verdict at all before. Added beside it (the widening half): the optional `sweepObject` input of the `validate_expression` MCP tool.
99
Metadata-protocol: narrowed
1010
Skills-docs: updated here — the MCP skill text in `packages/mcp/src/skill-md.ts` (the new `sweepObject` input); `skills/**` teaches no time-relative flow condition with a text-vs-number comparison, so no skill or eval moves.
1111

12-
<!-- adr-0087: not-required (already-registered flow-record-read-and-decision-type-mismatch-refused) the entry already prescribes this exact rewrite for a time-relative flow's conditions: the same refusal code, the same replacement and the same reason (each run's record is a row of the swept object); this change extends it to a sweep whose start names no objectName -->
12+
<!-- adr-0087: not-required (already-registered flow-record-read-and-decision-type-mismatch-refused) the entry already prescribes this exact rewrite for a time-relative flow's conditions: the same refusal code, the same replacement and the same reason (each run's record is a row of the swept object); this change extends it to a sweep whose start names no objectName; the unknown-field and date-arithmetic arms are the verdicts every flow with a typed object already gets, served here for the same reason and with the rewrite in their own message, and the entry's surface text is widened to this shape in the spec lane -->
1313

1414
**BREAKING** accept-set narrowing at the author-time expression gate, served by `os build`, `os validate` and `POST /api/v1/packages/:id/publish-drafts`.
1515

1616
- **Before.** A time-relative flow was typed only against its start node's `objectName`. A start that named none, with the swept object in `timeRelative.object` (the key the descriptor requires), got no type verdict on its conditions at all: `title > 5` on a text field published clean, and every run the sweep launched failed at that condition.
17-
- **Now.** The conditions of such a flow are typed against `timeRelative.object`: each run's record is a row of that object, so a text-vs-number comparison in its start, edge or `decision` conditions is refused as `type-mismatch-run-fails`, the verdict a sweep of the start node's object already gets. Field reads, the shadowing warning and the root check are judged against the same object.
17+
- **Now.** The conditions of such a flow are typed against `timeRelative.object`: each run's record is a row of that object, so its start, edge and `decision` conditions get every verdict a sweep of the start node's object already gets. Three of them are new refusals there: a text-vs-number comparison (`type-mismatch-run-fails`), a `record.FIELD` read of a field the swept object does not declare (`unknown field FIELD on OBJECT`; the run fails on the missing key), and arithmetic on a date field (`date-arithmetic-run-fails`, or `date-text-arithmetic-run-fails` against text). The shadowing and near-miss warnings and the root check are judged against the same object.
1818
- **A sweep of another object** (the start node's `objectName` is not `timeRelative.object`) keeps the `type-mismatch-run-may-fail` warning, and the flow now gets one more warning, at its start node's `config.objectName`, saying why: the conditions are checked against that object's fields while each run's record is a row of the swept one. It is served only on a flow that got a warning it explains.
1919
- **`validate_expression` (MCP).** New optional input `sweepObject` (site `flow_condition` with `triggerKind: 'time_relative'` only; a tool error anywhere else): the flow's `timeRelative.object`. When it is another object than `objectName`, a type mismatch is the gate's warning instead of the run-fails error. A call that does not pass it answers as before.
2020
- **Correction to the 18.x changeset of the flow-condition type check.** It described a time-relative flow whose `timeRelative.object` "is omitted" as sweeping the start node's object. That shape never binds: `TimeRelativeTriggerSchema` requires `object`, and the gate refuses its absence (`flow-time-relative-descriptor-invalid`). Such a flow now gets the warning, not the run-fails verdict, on its conditions, since no run of it binds a row.
2121

22-
**FROM → TO.** In a time-relative flow whose start names no `objectName`, sweeping `crm_opportunity` with a text field `title`: `title > 5` (or `record.title > 5`, or a decision branch `title * 2 > 10`) → `size(title) > 5` for its length, a number field for a value, or `double(title) > 5` only when every value is numeric text. A flow whose start names one object and sweeps another: set the start node's `objectName` to the swept object, or remove it.
22+
**FROM → TO.** In a time-relative flow whose start names no `objectName`, sweeping `crm_opportunity` with a text field `title` and a date field `close_date`: `title > 5` (or `record.title > 5`, or a decision branch `title * 2 > 10`) → `size(title) > 5` for its length, a number field for a value, or `double(title) > 5` only when every value is numeric text. `record.nope > 1`, where `crm_opportunity` declares no `nope` → the field's declared name, or the object that declares it as `timeRelative.object`. `close_date + 1 > …` → `addDays(close_date, 1) > …` to shift a date (`addMonths(d, n)` and `daysFromNow(n)` likewise), or `daysBetween(a, b)` for a span in whole days. A flow whose start names one object and sweeps another: set the start node's `objectName` to the swept object, or remove it.

‎packages/lint/src/validate-expressions.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,37 @@ describe('validateStackExpressions (ADR-0032 build-time)', () => {
11911191
] as const) {
11921192
expect(notes(validateStackExpressions({ objects, flows: [flowOf(name, startObject, sweepObject, condition)] })), name).toEqual([]);
11931193
}
1194+
// A date verdict is an error whatever the outcome: the sweep softens
1195+
// nothing there, so there is nothing to explain.
1196+
const dateOnly = validateStackExpressions({ objects, flows: [flowOf('tr_other_date', 'crm_opportunity', 'crm_task', 'close_date + 1 > 3')] });
1197+
expect(dateOnly.filter(i => /^date arithmetic/.test(i.message)).map(i => i.severity)).toEqual(['error', 'error']);
1198+
expect(notes(dateOnly)).toEqual([]);
1199+
});
1200+
1201+
// [#30026] Typed against the swept object, a sweep-only flow gets every
1202+
// verdict a sweep of the start object gets, not only the type check: a
1203+
// `record.FIELD` read of a field the swept object does not declare, and
1204+
// date arithmetic. Before, it got none of them.
1205+
it('refuses an unknown record.FIELD read and date arithmetic on a time-relative flow typed only by its swept object (#30026)', () => {
1206+
const objects = [{ name: 'crm_opportunity', fields: { title: { type: 'text', required: true }, close_date: { type: 'date' } } }];
1207+
const sweepOnly = (condition: string) => ({
1208+
name: 'tr_sweep_only',
1209+
nodes: [
1210+
{
1211+
id: 'start', type: 'start',
1212+
config: { condition, schedule: '0 * * * *', timeRelative: { object: 'crm_opportunity', dateField: 'close_date', offsetDays: 3 } },
1213+
},
1214+
{ id: 'end', type: 'end' },
1215+
],
1216+
edges: [{ id: 'e1', source: 'start', target: 'end' }],
1217+
});
1218+
const unknown = validateStackExpressions({ objects, flows: [sweepOnly('record.nope > 1')] });
1219+
expect(unknown.map(i => i.severity)).toEqual(['error']);
1220+
expect(unknown[0]!.message).toMatch(/^unknown field `nope` on `crm_opportunity`/);
1221+
const date = validateStackExpressions({ objects, flows: [sweepOnly('close_date + 1 > 3')] });
1222+
expect(date.map(i => i.severity)).toEqual(['error']);
1223+
expect(date[0]!.message).toMatch(/^date arithmetic/);
1224+
expect(date[0]!.message).toContain(': this faults at runtime, and a flow condition');
11941225
});
11951226

11961227
// [#30026] Typed against the swept object, a well-typed sweep-only flow

‎packages/lint/src/validate-expressions.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,9 +2201,12 @@ export function validateStackExpressions(stack: AnyRec): ExprIssue[] {
22012201
*/
22022202
export function runStackExpressionPasses(stack: AnyRec, options: StackExpressionOptions): ExprIssue[] {
22032203
const issues: ExprIssue[] = [];
2204-
// [#30026] How many `-run-may-fail` warnings {@link check} has served: a
2205-
// flow whose own count moved is one an author is told why of, where the
2206-
// reason is the flow's own (the time-relative note in the flow walk).
2204+
// [#30026] How many `type-mismatch-run-may-fail` warnings {@link check} has
2205+
// served: a flow whose own count moved is one an author is told why of,
2206+
// where the reason is the flow's own (the time-relative note in the flow
2207+
// walk). Only that code: the date verdicts' `-run-may-fail` arm is an error
2208+
// whatever the outcome, so a sweep of another object does not soften it and
2209+
// there is nothing to explain.
22072210
let runMayFailServed = 0;
22082211
// [#22019] See {@link StackExpressionOptions.runtimeWriteType}: on an object
22092212
// write only the passes over the object's own body judge: the field-formula
@@ -2535,7 +2538,7 @@ export function runStackExpressionPasses(stack: AnyRec, options: StackExpression
25352538
issues.push({ where, message: e.message, source: e.source, severity: 'error' });
25362539
}
25372540
for (const w of res.warnings) {
2538-
if (w.code.endsWith('-run-may-fail')) runMayFailServed++;
2541+
if (w.code === 'type-mismatch-run-may-fail') runMayFailServed++;
25392542
issues.push({ where, message: w.message, source: w.source, severity: 'warning' });
25402543
}
25412544
if (objectName && traversalHydration) refuseStoredMetadataBodyHop(where, raw, objectName, 'rule');

0 commit comments

Comments
 (0)