Skip to content

Commit fb38ffb

Browse files
committed
fix(lint)!: refuse a time-relative start whose objectName is not the swept object
A time-relative run binds a row of config.timeRelative.object and nothing else, while the expression checks type the flow's conditions against the start node's config.objectName. A start naming two objects is now refused with flow-time-relative-object-mismatch, at config.objectName, naming both objects and the fix. The explanatory warning on a sweep of another object names the new rule. Claude-Session: https://claude.ai/code/session_01Utp6CXGZhZVasbhiGEdpZk Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9afcd6a commit fb38ffb

8 files changed

Lines changed: 272 additions & 2 deletions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/lint': minor
3+
---
4+
5+
fix(lint)!: a time-relative flow whose start node names, in `config.objectName`, another object than the one it sweeps (`config.timeRelative.object`) is refused with `flow-time-relative-object-mismatch`: each run binds a row of the swept object, while the start's `objectName` is what its conditions are checked against (#30283)
6+
7+
Clause-②: yes (narrowing) — a new published readiness rule id, `flow-time-relative-object-mismatch`, graded `error`: the author-time gate (`os build`, `os validate`, the package publish and the flow publish door) refuses a time-relative start whose `config.objectName` is set and is not `config.timeRelative.object`, which it passed with no readiness verdict before.
8+
Metadata-protocol: narrowed
9+
Skills-docs: none — `skills/**` and `content/docs/**` teach the time-relative sweep with `timeRelative.object` alone and no `objectName` on its start node, which this rule accepts; the MCP skill text keeps its `sweepObject` advice for `validate_expression`, whose expression verdict this change does not move.
10+
11+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped: the flow schema still admits objectName beside a timeRelative descriptor, and what narrows is the publish door's accept set for one combination of two existing keys. No rewrite keeps what the author meant: the start names two objects, and whether the author meant to sweep the swept object (drop objectName) or the named one (change timeRelative.object) is a judgement no ledger entry can derive. The other categories are closed on facts: the bumped package publishes (not unpublished); no ADR-0087 id covers this combination (flow-record-read-and-decision-type-mismatch-refused prescribes a rewrite of a condition, not of the start node) and this diff adds none (not registered, not already-registered); no published export is removed or retyped (not runtime-export-retired, runtime-interface-only or type-surface-only). -->
12+
13+
**BREAKING** accept-set narrowing at the author-time flow readiness gate, served by `os build`, `os validate`, `POST /api/v1/packages/:id/publish-drafts` and the flow publish door.
14+
15+
- **Before.** A time-relative start could name `config.objectName: 'A'` and sweep `config.timeRelative.object: 'B'`. The run binds only `B`: the engine's binding resolver reads `timeRelative.object` first, and the trigger launches each run with a `B` row as `record` and `B` as the run's object. The expression checks typed the flow's conditions against `A` all the same. Measured both ways: `record.amount > 10`, where only `A` declares `amount`, passed every check and failed every run (`No such key: amount`); `record.priority > 1`, a correct read of a `B` field, was refused as `unknown field priority on A`.
16+
- **Now.** That start is refused at `config.objectName`, naming both objects and the fix. A start whose `objectName` equals `timeRelative.object`, or that names none, is not reported; neither is a start whose `triggerType` routes the flow to the record-change trigger (a `record-` token, or an array holding one), which binds `objectName` and never sweeps. The runtime publish gate judges only the flow being written, so a stored flow that names two objects keeps being served; its own next publish is refused.
17+
- **The `config.objectName` warning on a sweep of another object** (served where a condition's type verdict was softened to a warning) now names `flow-time-relative-object-mismatch` as the verdict that asks for the same fix.
18+
19+
**FROM → TO.** In a time-relative flow sweeping `crm_task`: `config: { objectName: 'crm_opportunity', timeRelative: { object: 'crm_task', … } }` → `config: { timeRelative: { object: 'crm_task', … } }` (the sweep never reads `objectName`, so the run is unchanged), or `objectName: 'crm_task'`. Then fix any condition the expression checks now refuse against `crm_task`. If the flow was meant to sweep `crm_opportunity`, set `timeRelative.object: 'crm_opportunity'` (and its `dateField`) instead.

‎packages/lint/src/authoring-rules.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,10 @@ export const AUTHORING_RULES: readonly AuthoringRule[] = [
14691469
// (`validateFlowApiTriggerSecret`), because it reads a context input this entry
14701470
// has no use for (#20611). None of those verdicts
14711471
// can be changed by installing a package, so there is no reading under which
1472-
// the flow fires. `flow-trigger-unknown-object` deliberately stayed `warning`
1472+
// the flow fires. [#30283] `flow-time-relative-object-mismatch` gates on the
1473+
// same question without being a never-fire verdict: a time-relative start
1474+
// whose `objectName` is not the swept object, which the run never binds while
1475+
// the expression checks type its conditions against it. `flow-trigger-unknown-object` deliberately stayed `warning`
14731476
// (the object may come from another installed package — a hedge this rule
14741477
// cannot decide), as did `flow-draft-status-ambiguous` (draft flows DO fire;
14751478
// that one is ambiguity of intent, not a dead flow). [#24669] The hedge is

‎packages/lint/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export {
143143
FLOW_TRIGGER_UNKNOWN_EVENT,
144144
FLOW_TIME_RELATIVE_DESCRIPTOR_INVALID,
145145
FLOW_TIME_RELATIVE_DESCRIPTOR_UNROUTABLE,
146+
FLOW_TIME_RELATIVE_OBJECT_MISMATCH,
146147
FLOW_TRIGGER_UNROUTABLE,
147148
FLOW_API_TRIGGER_SECRET_MISSING,
148149
FLOW_API_TRIGGER_SIGNATURE_UNUSABLE,

‎packages/lint/src/rule-explanations.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,6 +1993,38 @@ const FLOW_TIME_RELATIVE_DESCRIPTOR_UNROUTABLE_EXPLANATION: RuleExplanation = {
19931993
],
19941994
};
19951995

1996+
const FLOW_TIME_RELATIVE_OBJECT_MISMATCH_EXPLANATION: RuleExplanation = {
1997+
rule: 'flow-time-relative-object-mismatch',
1998+
covers: 'why a time-relative start may not name a second object',
1999+
paragraphs: [
2000+
'A time-relative run binds the object its descriptor sweeps, `config.timeRelative.object`, and ' +
2001+
'nothing else. The engine\'s binding resolver reads that key first, and the time-relative trigger ' +
2002+
'finds the rows of that object whose date field falls in the window, then launches one run per row ' +
2003+
'with the row as `record` and that object as the run\'s object, which is also the object a declared ' +
2004+
'`expand` is read from. No part of the run reads the start node\'s `config.objectName`.',
2005+
'The checks do read it. When the start names an `objectName`, the flow\'s conditions are typed ' +
2006+
'against that object\'s fields, at `os validate`, at the runtime publish gate and in the engine\'s ' +
2007+
'registration pass, so a start naming another object than the one it sweeps is checked against ' +
2008+
'records its runs never hold. Measured both ways: a condition reading a field only the named object ' +
2009+
'declares passes every check and fails every run (`No such key` for `record.FIELD`, `Unknown ' +
2010+
'variable` for a bare name), while a correct read of a field of the swept object is refused as an ' +
2011+
'unknown field on the named object.',
2012+
'Remove `config.objectName`, or set it to the swept object. Either way nothing the run does changes, ' +
2013+
'and the conditions are checked against the record each run holds: a field the swept object does not ' +
2014+
'declare is refused, and a type mismatch fails the publish, as on a record-triggered flow.',
2015+
'Not reported: a start whose `objectName` equals `timeRelative.object` or that names none; a start ' +
2016+
'whose `triggerType` routes the flow to the record-change trigger (a `record-` token, or an array ' +
2017+
'holding one), because that trigger binds `objectName` and the descriptor is never swept; and a ' +
2018+
'descriptor whose `object` is not a string, which `flow-time-relative-descriptor-invalid` refuses.',
2019+
'The finding is an error, because the start node alone settles it and nothing installed changes which ' +
2020+
'object the run binds: it fails `os validate` and `os build`, and the runtime publish gate refuses an ' +
2021+
'active flow write that carries it. That gate judges only the flow being written, against the ' +
2022+
'findings the stored stack already had, so a stored flow that names two objects keeps being served ' +
2023+
'and never blocks another flow\'s save; what is refused is its own publish, until its start names ' +
2024+
'one object.',
2025+
],
2026+
};
2027+
19962028
const FLOW_TRIGGER_UNROUTABLE_EXPLANATION: RuleExplanation = {
19972029
rule: 'flow-trigger-unroutable',
19982030
covers: 'why a record_change flow with no record token never fires',
@@ -5684,6 +5716,7 @@ export const RULE_EXPLANATIONS: Readonly<Record<string, RuleExplanation>> = Obje
56845716
[SHARING_RULE_OBJECT_CONTROLLED_BY_PARENT_EXPLANATION.rule]: SHARING_RULE_OBJECT_CONTROLLED_BY_PARENT_EXPLANATION,
56855717
[FLOW_TIME_RELATIVE_DESCRIPTOR_INVALID_EXPLANATION.rule]: FLOW_TIME_RELATIVE_DESCRIPTOR_INVALID_EXPLANATION,
56865718
[FLOW_TIME_RELATIVE_DESCRIPTOR_UNROUTABLE_EXPLANATION.rule]: FLOW_TIME_RELATIVE_DESCRIPTOR_UNROUTABLE_EXPLANATION,
5719+
[FLOW_TIME_RELATIVE_OBJECT_MISMATCH_EXPLANATION.rule]: FLOW_TIME_RELATIVE_OBJECT_MISMATCH_EXPLANATION,
56875720
[FLOW_TRIGGER_UNROUTABLE_EXPLANATION.rule]: FLOW_TRIGGER_UNROUTABLE_EXPLANATION,
56885721
[FLOW_TRIGGER_UNKNOWN_EVENT_EXPLANATION.rule]: FLOW_TRIGGER_UNKNOWN_EVENT_EXPLANATION,
56895722
[FLOW_API_TRIGGER_SECRET_MISSING_EXPLANATION.rule]: FLOW_API_TRIGGER_SECRET_MISSING_EXPLANATION,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,8 @@ describe('validateStackExpressions (ADR-0032 build-time)', () => {
11831183
]);
11841184
expect(notes(other)[0]!.message).toContain("each run's record is a row of 'crm_task'");
11851185
expect(notes(other)[0]!.message).toContain("Set config.objectName to 'crm_task', or remove it");
1186+
// [#30283] The note names the readiness rule that refuses the start itself.
1187+
expect(notes(other)[0]!.message).toContain('as flow-time-relative-object-mismatch asks of this start');
11861188
// No warning to explain, or no other object: no note.
11871189
for (const [name, startObject, sweepObject, condition] of [
11881190
['tr_other_clean', 'crm_opportunity', 'crm_task', 'size(title) > 5'],

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3280,6 +3280,9 @@ export function runStackExpressionPasses(stack: AnyRec, options: StackExpression
32803280
// the conditions are typed against the start node's `objectName`, while
32813281
// each run's `record` is a row of the swept object. Said once per flow, at
32823282
// the key that makes it so, and only where a warning it explains was served.
3283+
// [#30283] The contradiction itself is the readiness rule's verdict
3284+
// (`flow-time-relative-object-mismatch`, at the same key); this note
3285+
// explains the softened verdict only, and names that rule for the fix.
32833286
if (startObject !== undefined && sweepObject !== undefined && startObject !== sweepObject
32843287
&& runMayFailServed > runMayFailBefore) {
32853288
const startIndex = flowIndex >= 0 && startNode && Array.isArray(flow.nodes) ? flow.nodes.indexOf(startNode) : -1;
@@ -3290,7 +3293,8 @@ export function runStackExpressionPasses(stack: AnyRec, options: StackExpression
32903293
`row of '${sweepObject}', while its conditions are checked against the fields of '${startObject}' (the ` +
32913294
`start node's config.objectName). That is why a type mismatch in its conditions is a warning here and ` +
32923295
`not a refusal: the names hold a '${sweepObject}' row, not the '${startObject}' fields they were checked ` +
3293-
`against. Set config.objectName to '${sweepObject}', or remove it: the conditions are then checked ` +
3296+
`against. Set config.objectName to '${sweepObject}', or remove it, as flow-time-relative-object-mismatch ` +
3297+
`asks of this start: the conditions are then checked ` +
32943298
`against the swept object, and a type mismatch in them is refused, as on a record-triggered flow.`,
32953299
source: startObject,
32963300
severity: 'warning',

‎packages/lint/src/validate-flow-trigger-readiness.test.ts‎

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
FLOW_TRIGGER_UNKNOWN_EVENT,
1111
FLOW_TIME_RELATIVE_DESCRIPTOR_INVALID,
1212
FLOW_TIME_RELATIVE_DESCRIPTOR_UNROUTABLE,
13+
FLOW_TIME_RELATIVE_OBJECT_MISMATCH,
1314
FLOW_TRIGGER_UNROUTABLE,
1415
FLOW_API_TRIGGER_SECRET_MISSING,
1516
FLOW_API_TRIGGER_SIGNATURE_UNUSABLE,
@@ -1466,6 +1467,27 @@ describe('validateFlowTriggerReadiness', () => {
14661467
],
14671468
},
14681469
],
1470+
[
1471+
FLOW_TIME_RELATIVE_OBJECT_MISMATCH,
1472+
'error',
1473+
{
1474+
objects: [{ name: 'task', label: 'Task', fields: {} }, { name: 'project', label: 'Project', fields: {} }],
1475+
flows: [
1476+
{
1477+
name: 'two_objects',
1478+
type: 'schedule',
1479+
status: 'active',
1480+
nodes: [
1481+
{
1482+
id: 'start',
1483+
type: 'start',
1484+
config: { objectName: 'project', timeRelative: { object: 'task', dateField: 'due_at', withinDays: 3 } },
1485+
},
1486+
],
1487+
},
1488+
],
1489+
},
1490+
],
14691491
[
14701492
FLOW_TRIGGER_UNKNOWN_EVENT,
14711493
'error',
@@ -1785,6 +1807,116 @@ describe('validateFlowTriggerReadiness', () => {
17851807
// `apiTriggerVerifierOf` (the reader the engine and the trigger share): ready on
17861808
// the key `config.secretRef` names and nothing else, and never ready when the
17871809
// reader answers `unusable`.
1810+
// [#30283] A time-relative start naming, in `config.objectName`, an object other
1811+
// than the one it sweeps. The run binds the swept object alone; the expression
1812+
// checks type the conditions against `objectName`. One finding, at that key.
1813+
describe('[#30283] a time-relative start whose objectName is not the swept object', () => {
1814+
const objects = [
1815+
{ name: 'crm_opportunity', label: 'Opportunity', sharingModel: 'private', fields: { amount: { type: 'number', required: true } } },
1816+
{ name: 'crm_task', label: 'Task', sharingModel: 'private', fields: { priority: { type: 'number', required: true }, close_date: { type: 'date' } } },
1817+
];
1818+
/** A sweep of `crm_task`; `config` extras ride on the start node. */
1819+
const sweepFlow = (extra: Record<string, unknown>, timeRelative: unknown = { object: 'crm_task', dateField: 'close_date', offsetDays: [3] }) => ({
1820+
name: 'task_due',
1821+
label: 'Task due',
1822+
type: 'schedule',
1823+
status: 'active',
1824+
runAs: 'system',
1825+
nodes: [
1826+
{ id: 'start', type: 'start', label: 'Start', config: { ...extra, timeRelative, organization: FIXTURE_ORG } },
1827+
{ id: 'end', type: 'end', label: 'End' },
1828+
],
1829+
edges: [{ id: 'e1', source: 'start', target: 'end' }],
1830+
});
1831+
const mismatchOf = (findings: ReadonlyArray<{ rule: string }>) =>
1832+
findings.filter((f) => f.rule === FLOW_TIME_RELATIVE_OBJECT_MISMATCH);
1833+
1834+
it('refuses the start, at config.objectName, naming both objects and the fix', () => {
1835+
const findings = validateFlowTriggerReadiness({ objects, flows: [sweepFlow({ objectName: 'crm_opportunity' })] });
1836+
expect(findings.map((f) => [f.rule, f.severity, f.where, f.path])).toEqual([
1837+
[FLOW_TIME_RELATIVE_OBJECT_MISMATCH, 'error', 'flow "task_due" › start node', 'flows[0].nodes[0].config.objectName'],
1838+
]);
1839+
const [f] = findings;
1840+
expect(f.message).toContain("config.objectName 'crm_opportunity'");
1841+
expect(f.message).toContain("('crm_task')");
1842+
expect(f.message).not.toContain('\n');
1843+
expect(f.message.length).toBeLessThanOrEqual(200);
1844+
expect(f.hint).toMatch(/^Remove config\.objectName .*or set it to 'crm_task'/);
1845+
expect(f.hint).not.toContain('\n');
1846+
expect(f.hint.length).toBeLessThanOrEqual(200);
1847+
});
1848+
1849+
it('is silent where the start names one object: the swept one, or none', () => {
1850+
for (const extra of [{ objectName: 'crm_task' }, {}]) {
1851+
expect(validateFlowTriggerReadiness({ objects, flows: [sweepFlow(extra)] }), JSON.stringify(extra)).toEqual([]);
1852+
}
1853+
});
1854+
1855+
it('is silent where the engine binds another trigger, which reads objectName and never sweeps', () => {
1856+
// A `record-*` token outranks the descriptor in the kind resolver, and an
1857+
// array-form record token is routed to the record-change trigger by the
1858+
// engine's pre-check. Each is paired with the shape that fires.
1859+
for (const triggerType of ['record-after-update', ['record-after-create', 'record-after-update']]) {
1860+
const findings = validateFlowTriggerReadiness({
1861+
objects,
1862+
flows: [sweepFlow({ objectName: 'crm_opportunity', triggerType })],
1863+
});
1864+
expect(mismatchOf(findings), JSON.stringify(triggerType)).toEqual([]);
1865+
}
1866+
expect(
1867+
mismatchOf(validateFlowTriggerReadiness({ objects, flows: [sweepFlow({ objectName: 'crm_opportunity', triggerType: 'schedule' })] })),
1868+
).toHaveLength(1);
1869+
});
1870+
1871+
it('leaves a descriptor whose object is not a string to the descriptor rule, and co-fires with it otherwise', () => {
1872+
const noObject = validateFlowTriggerReadiness({
1873+
objects,
1874+
flows: [sweepFlow({ objectName: 'crm_opportunity' }, { object: 7, dateField: 'close_date', offsetDays: [3] })],
1875+
});
1876+
expect(noObject.map((f) => f.rule)).toEqual([FLOW_TIME_RELATIVE_DESCRIPTOR_INVALID]);
1877+
// Two keys, two facts: a bad window beside a string object reports both.
1878+
const both = validateFlowTriggerReadiness({
1879+
objects,
1880+
flows: [sweepFlow({ objectName: 'crm_opportunity' }, { object: 'crm_task', dateField: 'close_date' })],
1881+
});
1882+
expect(both.map((f) => [f.rule, f.path]).sort()).toEqual([
1883+
[FLOW_TIME_RELATIVE_DESCRIPTOR_INVALID, 'flows[0].nodes[0].config.timeRelative'],
1884+
[FLOW_TIME_RELATIVE_OBJECT_MISMATCH, 'flows[0].nodes[0].config.objectName'],
1885+
]);
1886+
});
1887+
1888+
it('closes the measured hole: a condition only the named object can satisfy no longer passes every authoring command', () => {
1889+
// The run binds a `crm_task` row, which has no `amount`: this condition
1890+
// faults every run (`No such key: amount`). Typed against `objectName`,
1891+
// the expression checks find nothing wrong with it, so before this rule
1892+
// the stack passed every command clean.
1893+
const stack = { objects, flows: [sweepFlow({ objectName: 'crm_opportunity', condition: 'record.amount > 10' })] };
1894+
for (const command of AUTHORING_COMMANDS) {
1895+
const errors = runAuthoringRules(command, { normalized: stack, parsed: stack }).filter((f) => f.severity === 'error');
1896+
expect(errors.map((f) => [f.rule, f.path]), command).toEqual([
1897+
[FLOW_TIME_RELATIVE_OBJECT_MISMATCH, 'flows[0].nodes[0].config.objectName'],
1898+
]);
1899+
}
1900+
});
1901+
1902+
it('the runtime publish gate refuses the write, judged on the flow alone', () => {
1903+
const gated = runRuntimeAuthoringRules({ type: 'flow', item: sweepFlow({ objectName: 'crm_opportunity' }) });
1904+
expect(gated.rulesRun).toContain('validateFlowTriggerReadiness');
1905+
expect(gated.errors.map((f) => [f.rule, f.path])).toEqual([
1906+
[FLOW_TIME_RELATIVE_OBJECT_MISMATCH, 'flows[0].nodes[0].config.objectName'],
1907+
]);
1908+
expect(runRuntimeAuthoringRules({ type: 'flow', item: sweepFlow({}) }).errors).toEqual([]);
1909+
});
1910+
1911+
it('`os explain flow-time-relative-object-mismatch` carries what the verdict does not say', () => {
1912+
expect(FLOW_TIME_RELATIVE_OBJECT_MISMATCH).toBe('flow-time-relative-object-mismatch');
1913+
const text = explanationOf(FLOW_TIME_RELATIVE_OBJECT_MISMATCH);
1914+
for (const fact of ['No part of the run reads', 'No such key', 'refused as an unknown field', 'nothing the run does changes', 'that trigger binds `objectName`', 'what is refused is its own publish']) {
1915+
expect(text, fact).toContain(fact);
1916+
}
1917+
});
1918+
});
1919+
17881920
describe('[#30009] api trigger readiness reads the hook\'s one verifier (config.signature)', () => {
17891921
const DOCUSIGN = { signs: 'body', header: 'X-DocuSign-Signature-1', algorithm: 'hmac-sha256', encoding: 'base64' };
17901922
const STRIPE = {

0 commit comments

Comments
 (0)