Skip to content

Commit 54b491a

Browse files
fix(lint)!: refuse a time-relative start whose objectName is not the object it sweeps (#30393)
<!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgQkhZiM9XtP8WTGmWoj9hrq)_ domain:server#2 · os-bill · session_01Utp6CXGZhZVasbhiGEdpZk Fixes #30283 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. Metadata-protocol: narrowed 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. ## 维护者速读 - 改了什么:时间相对(定时扫描)流程的开始节点如果 `objectName` 写的对象和 `timeRelative.object`(真正被扫描的对象)不一样,发布和 `os validate` 现在直接拦下(新规则 `flow-time-relative-object-mismatch`,error),提示里写明两个对象和改法:删掉 `objectName` 或改成被扫描对象。 - 为什么改:运行时每次拿到的 `record` 只是被扫描对象的一行,`objectName` 从不被读,但条件检查却按 `objectName` 的字段来做。实测两个方向都错:只有 `objectName` 对象才有的字段写进条件,所有检查全过、每次运行都报 `No such key` 失败;反过来正确读被扫描对象的字段,却被当成未知字段拒掉。 - 风险与回滚:只收窄这一种自相矛盾的写法(BREAKING 与作者该怎么改已写进 changeset);删掉 `objectName` 不改变任何运行行为;仓里的示例、文档、技能都没有这种写法;已存的此类流程照常运行,只是下次发布会被拦;回滚即撤 PR。 - 先看:`packages/lint/src/validate-flow-trigger-readiness.ts` 的 1b-iii 判决块(只判引擎真正绑到时间相对触发器的流程);同文件 `FLOW_TIME_RELATIVE_OBJECT_MISMATCH` 的说明与严重度段;`packages/lint/src/rule-explanations.ts` 新条目。 - 两分钟验证:`pnpm --filter @objectstack/lint exec vitest run --maxWorkers=2 src/validate-flow-trigger-readiness.test.ts -t "30283"`,预期 7 个用例通过,其中 "closes the measured hole" 在三个命令下都只报这一条 error。 - 需要你做的:无,席位落地(收窄面由席位安排 CONTRACT_REVIEW_TIER 复审)。 ## What changes - **Lint — new readiness rule `flow-time-relative-object-mismatch`** (`validateFlowTriggerReadiness`, block 1b-iii). On a time-relative start whose `config.objectName` is a string and is not `config.timeRelative.object` (a string), one `error` at `flows[i].nodes[j].config.objectName`: the verdict names both objects ("each run's record is a 'B' row, and 'A' is never bound"), the `fix:` line says remove `objectName` or set it to the swept object. Judged only where the engine binds the time-relative trigger: `resolveFlowTriggerKind(flow) === 'time_relative'` and no array-form record token (the engine's `deriveTriggerBinding` pre-check routes that shape to the record-change trigger, which does bind `objectName`). A `record-*` token outranks the descriptor in the resolver, so that flow is not judged either. A descriptor whose `object` is not a string is left to `flow-time-relative-descriptor-invalid`; a bad window beside a string object reports both, at two keys. - **Severity: `error`**, on the file's own criterion (is this stack enough to know?). Both names sit on the one start node, and which one the run binds is a hardcoded read in the engine's binding resolver (`timeRelative.object` first), so nothing installed changes the answer. The file header, the severity section and the `authoring-rules.ts` entry comment say so. Not a never-fire verdict: the sweep binds and runs; the rule is not added to the never-fire id list. - **`os explain flow-time-relative-object-mismatch`** (`rule-explanations.ts`): what the run binds, what the checks type against, the measured outcome both ways, the fix, what is not reported, and the gate reach (the runtime publish gate judges only the written flow, so a stored flow keeps being served and its own next publish is refused). - **Barrel:** `FLOW_TIME_RELATIVE_OBJECT_MISMATCH` is exported from `@objectstack/lint` (`rule-id-barrel-exports.test.ts` holds it). - **`validate-expressions.ts` — the `config.objectName` warning** on a sweep of another object (from #30026) keeps its explanation and now names the readiness rule as the verdict asking for the same fix ("as flow-time-relative-object-mismatch asks of this start"); it does not repeat the verdict. - **Tests** (`validate-flow-trigger-readiness.test.ts`): a severity-table row; a `[#30283]` block with seven cases: the refusal (rule, severity, where, path, both names, one-line message and fix of at most 200 characters); silence on the swept object and on no `objectName`; silence where the engine binds another trigger (`record-after-update`, array form), paired with the shape that fires; the descriptor-rule split and co-firing; the measured hole through every authoring command (`validate`, `build`, `lint` answer exactly this one error); the runtime publish gate refusing the write on the flow alone; the `os explain` facts. `validate-expressions.test.ts`: the note names the rule. - **Changeset** `.changeset/30283-time-relative-object-mismatch.md`, `minor` on `@objectstack/lint`, BREAKING with what an author does, ADR-0087 `not-required (no-migration-prescription)`: no rewrite keeps intent, because whether the author meant the swept object or the named one is a judgement. ## Acceptance notes - **Measurement that decided `error` (on `9afcd6a6`).** Objects `crm_opportunity { amount }` and `crm_task { priority, close_date }`, a start with `objectName: 'crm_opportunity'` sweeping `crm_task`. Author time (lint `validateStackExpressions` + readiness): `record.amount > 10` and `amount > 10` → no finding at all; `record.priority > 1` → `unknown field priority on crm_opportunity` (error); the same two conditions with no `objectName` → `unknown field amount on crm_task` and clean, respectively. Run time (`AutomationEngine.execute` with the context `time-relative-trigger.ts` builds: a `crm_task` row as `record`, `object: 'crm_task'`): `record.amount > 10` → run fails `No such key: amount`; `amount > 10` → `Unknown variable: amount`; `record.priority > 1` → run succeeds, while the engine's registration pass logs `unknown field priority on crm_opportunity`. So the contradiction hides a run-failing condition from every gate and refuses a correct one. The binding itself was read from source, not run: `deriveTriggerBinding` (`plugin-extension-api.ts`) takes `timeRelative.object` before `objectName`, and `expandDeclaredLookups` reads the run's `object`. - **Corpus.** `git grep` over `examples/`, `skills/`, `content/docs/` (outside the generated references) and the MCP skill text: no time-relative start carries an `objectName` (the showcase `showcase_task_due_reminder` sweep names none). The dogfood battery below is the executed check. - **MCP `validate_expression`'s `sweepObject` advice** (`packages/mcp/src/skill-md.ts`, `mcp-http-tools.ts`) still says a mismatch of `sweepObject` and `objectName` makes the expression verdict a warning. That stays true of the expression verdict; the publish gate now also refuses the start. Outside this card's surface; noted, not changed. - **The engine's registration advisory pass** (`flow-registration-checks.ts`) still types a time-relative flow's conditions against `objectName`, logging the misleading `unknown field` warn measured above. After this rule such a flow cannot be published, so the warn is reachable only for a flow stored before; noted, not touched. ## Verification All readings on head ``d3580892` (`fb38ffb0` the change, `b4c229b6` merged with `main` at `8589756a`, `d3580892` the changeset's author paragraph)` (this branch merged with `main` at `8589756a`) unless named. <details><summary>Build, typecheck, tests</summary> - Build: `pnpm --filter '@objectstack/dogfood^...' build` (lint included), VERDICT command-exit 0; the seven packages `check:dual-build-cjs-loads` reads that lie outside that closure, VERDICT command-exit 0. - `@objectstack/lint` on `d3580892`: `pnpm test` 8014/8014 (193 files); `pnpm typecheck` 0 (with `check:test-typecheck`). - `pnpm lint` (`eslint . --no-inline-config`) on `d3580892`: exit 0. </details> <details><summary>Ablations (each through scripts/ablation-replace.mjs; restored blob == HEAD, `git diff HEAD` empty)</summary> - A1, the verdict (lint suite imports `src`): the mismatch condition gated off (`'ABLATE-30283' === 'on' &&`). 6 red, among them `closes the measured hole …: validate: expected [] to deeply equal [ [ 'flow-time-relative-object-mismatch', 'flows[0].nodes[0].config.objectName' ] ]` (the pre-fix answer: no error from any rule) and the severity row `flow-time-relative-object-mismatch is error`. - A2, the routing guard: `resolveFlowTriggerKind(flow) === 'time_relative' && !isArrayRecordTriggered` replaced by a constant true. 1 red: `is silent where the engine binds another trigger, which reads objectName and never sweeps`. </details> <details><summary>Derived gates</summary> - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` on `d3580892`: 57 families (the same list as on `b4c229b6`), all 57 exit 0 (exit code captured per line before any pipe). - Three were red on the first pass and are recorded at their re-run: `check-adr-0087-registration` (the changeset carried a FROM/TO rewrite beside `no-migration-prescription`; fixed in `d3580892`, the author paragraph is now prose), `check-plugin-teardown-shape --self-test` (its pinned fixture commit was outside this shallow clone; that commit fetched, 48 cases pass), `check:dual-build-cjs-loads` (PREREQUISITE NOT MET: seven unrelated packages had no `dist/`; built, then exit 0). - `--ran` reconciliation: "57 derived famil(ies) accounted for — 57 run, 0 NOT-MEASURED". </details> <details><summary>Dogfood (the narrowing arm's battery, on the final head)</summary> - `pnpm --filter @objectstack/dogfood test` under the lock on `b4c229b6` (no shard, no path; `d3580892` changes only the changeset text): Test Files 419 passed, 3 skipped (422); Tests 3492 passed, 36 skipped (3528); VERDICT command-exit 0. No fixture or example flow carries the refused shape. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Utp6CXGZhZVasbhiGEdpZk --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6CXGZhZVasbhiGEdpZk)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7d7babb commit 54b491a

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+
**What an author does.** Nothing for a time-relative start that names no `objectName`, or names the object it sweeps. A start that names two objects says which one the author meant, and nothing mechanical can: for the swept one, remove `config.objectName` (the sweep never reads it, so the run is unchanged) or set it to the value of `config.timeRelative.object`, then correct any condition the expression checks now refuse against that object; for the named one, point `config.timeRelative.object` (and its `dateField`) at it instead. The refusal names both objects.

‎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
@@ -1994,6 +1994,38 @@ const FLOW_TIME_RELATIVE_DESCRIPTOR_UNROUTABLE_EXPLANATION: RuleExplanation = {
19941994
],
19951995
};
19961996

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