Skip to content

Commit d33183a

Browse files
fix(lint)!: the publish gate refuses a subflow or map step that calls a flow the deployment does not hold (#38594)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Jianguo** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbJg9RAhiuDxvothojbXXC9Z)_ Fixes #35143 Supersedes #38241 (closed, 7256687325) Clause-②: yes (narrowing) Metadata-protocol: narrowed Skills-docs: follow-up #38259 — skills/objectstack-automation/SKILL.md (the `subflow` row says `os validate` warns `flow-subflow-unknown`; it does not say the publish refuses a call to a flow nothing in the deployment holds), skills/objectstack-automation/evals/flows-triggers-approvals.json (the eval that names `flow-subflow-unknown`) ## 维护者速读 - 用户能看到什么变化:搭建者(包括 AI)发布一个流程时,如果其中“调用子流程”或“逐项调用流程”的步骤写了一个整个环境里都不存在的流程名,发布现在会直接被拒并说明原因;以前能发布成功,但每次运行到这一步都会失败。命令行校验仍然只给警告。 - 为什么做:属于“开源框架先拦住云端构建检查才拦得住的问题”这一族收尾(流程族最后两条),替写流程的搭建者挡住“发布成功、运行必失败”。 - 出错会怎样:这是一次收紧——以前能发布的这类流程下次发布会被拒;被调用的流程只要以草稿形式存在、或在同一批次发布、或在同一个软件包安装里(顺序不限)、或由已安装的软件包提供,都不会被拒;用另一个命名空间安装的软件包副本若有流程调用同包流程,安装会被整体拒绝并回滚(改名没有改到调用处,以前装得上但这一步必失败);撤回本改动即恢复原样。 - 要你做什么:无 ## What changes The card's last two open lines, re-verified on `main` (1208460) first. **F1, option label in decision-node and edge conditions: already covered on `main`, no change here.** `flow-condition-option-label` reads every edge condition and every `decision` node's `conditions[].expression` (and query filter operands) since #37491 (`optionLabelsBeyondStart` in `validate-flow-trigger-readiness.ts`, at `error`, same id, runtime gate and CLI). Its positive and negative pins are in `flow-publish-checks-second-batch.test.ts`, describe "past the start condition". The card gets a line saying so. **F6, a `subflow` / `map` step calling a flow that does not exist: now refused at the publish gate.** It was a CLI-only warning because the gate's per-write snapshot holds just the written flow. The gate now judges the call against the names of every flow the deployment holds, which the host states on a flow publish: - every installed package's flows (the registry, read with `includeDisabledPackages`, so a disabled package's are included); - the stored flow rows of **every state**, drafts included, so two new flows that call each other can still be published one at a time; - the flows the same publish batch carries (`pending.flows`), so a package that ships a flow with its caller publishes; - the flows the same unmanaged package install writes (`copyPlanFlowNames`, new in this head), so a package whose flow calls a sibling it declares later installs; - every flow the automation engine holds (`listFlows`), so a flow registered straight into the engine with no metadata row resolves. A call that names none of them, and is not the written flow itself, is an `error` (`flow-subflow-unknown`): `execute` answers `Flow 'X' not found` on every run. Severity per door: - **CLI** (`os validate` / `lint` / `compile` / `build`): `warning`, unchanged. The stack is one app, and another installed package may ship the called flow. - **Runtime publish gate, names stated and non-empty**: `error`. The set is the whole deployment, so "held nowhere" is decided, the #24668 reading of a whole collection. - **Runtime publish gate, no names or an empty set**: no verdict. That covers no automation service, a failed store read or a failed `listFlows` (each logged once at `warn`) and an empty set. A missing `sys_metadata` table is no stored flow: the other sources still decide. An empty set with no closure is no universe (#24668). - **Package closure**: the set is never narrowed to the written package's closure. So a call the engine's package-scoped resolution would refuse (ADR-0150 D3, `outside-closure`) is not judged here. This rule never refuses a call the engine would accept. Wiring: - `@objectstack/lint`: `validateFlowSubflowTargets(stack, { deploymentFlowNames })`, the `AuthoringRuleContext.deploymentFlowNames` input, and `runRuntimeAuthoringRules({ deploymentFlowNames })`. The rule's registry entry moves to `tier: 'gating'`, `surfaces: CLI_AND_RUNTIME`, `runtimeTypes: ['flow']`. Its runtime pass judges nothing without stated names. The rule's explanation text is updated. - `@objectstack/metadata-protocol`: `evaluateRuntimeAuthoringGate({ deploymentFlowNames })` adds the batch's flow drafts. `judgeRuntimeAuthoringRules` reads the names only on a flow write whose body calls another flow (`flowCallsAnotherFlow` in `runtime-authoring-gate.ts`; `deploymentFlowNamesOf`, `automationFlowNames`, `registeredFlowsWithDisabled` in `protocol-authoring-gate.ts`), through the host's existing `servicesRegistry`; the registry is listed with its disabled packages, since the served listing drops their items. The stored names are one `sys_metadata` read, `type` `$in` both spellings, projected to `fields: ['name']`. `saveMetaItem` takes a server-only `copyPlanFlowNames` (`protocol-door-requests.ts`), which `importUnmanagedPackage` states on each flow write and the save door hands the gate as `pending.flows`. `protocol.ts` moves no line: one docblock (the `pending` field) is reworded in place. - `@objectstack/spec`: the ADR-0087 entry `publish-refuses-flows-that-save-and-do-not-run` now counts eight errors at the publish gate, seven of them also on the CLI: its `surface` names the `subflow` / `map` refusal, the warnings sentence says which door each warning is silent at, the acceptance line is no longer seven, and the reason says what holds for a package install. No rule is added, so no "author-time rules (N)" count moves. ## Rework on contract review 7238045522 (FAIL at `bc21970eab`) This PR continues #38241 (seat 6's branch `claude/issue-35143-flows-leftovers`, whose dev ran out of budget). It starts at that head, merges `main`, and closes every open item of the review: - **M1** (an unmanaged install refused a package whose flow calls a sibling declared after it): `importUnmanagedPackage` states its plan's flow names on each flow write (`copyPlanFlowNames`), which reach the gate as `pending.flows`, the batch's channel. Pinned in `package-unmanaged-install.test.ts`, describe "a flow calling a sibling flow of the same package": a package declaring `crm_parent` (calls `crm_child`) before `crm_child`, on a protocol whose automation service holds another flow, installs both; the control (a call to a flow nothing holds) is still refused 422 and leaves no row and no base. `duplicatePackage` is unchanged: it copies stored rows, which the gate's stored read already holds (the review's own reading). - **S1** (every flow body read for names, on every flow publish): one read, both type spellings, `fields: ['name']`; none at all for a flow that calls no other flow, or only itself. Pinned on the shared harness. - **S2** (the entry still counted seven): `surface`, `reason` and `acceptanceCriteria` rewritten as above. - **S3** (three no-verdict exits unpinned): one pin each through `saveMetaItem` on the shared harness: a store read that throws (accepted, one `warn`), a `listFlows` that throws (accepted, one `warn`), and a missing `sys_metadata` table (no `warn`; a call to an engine or registry flow is accepted and a call to nothing is still refused). - **N1**: the `sealedFlowNodeTypeVocabulary` docblock is back above its function. N2–N5 are left as the review graded them (no effect on correctness); see the acceptance notes. ## Patch round on contract review 7257069704 (PASS, S4 open at `a7c00fdd85`) - **S4** (the texts said a disabled package's flows count; the gate read the served registry listing, which drops them): the first closing condition. The names read lists the registry with `includeDisabledPackages: true` (`registeredFlowsWithDisabled`), so a call to a disabled package's flow is let through, as a draft is: the flow is held, and runs once its package is enabled. The docblock, the changeset and this body now say what the code does. Pinned through `saveMetaItem`; removing the option fails the pin. - **N6, N7, N8** in the same commit: the entry's `reason` gives the right cause (the install states its flow names) and says the rename covers prefixed names only; the `pending` docblocks, the lint docblocks and the `os explain` text name a package install's flows and a disabled package's; the changeset's Exports bullet names `saveMetaItem`'s `copyPlanFlowNames` and no longer names `evaluateRuntimeAuthoringGate`. N9 and N10 stand as accepted. ## Why #35143 "Done when": each line is a rule with its pins, or a line on the card saying which rule covers it. F1 is the second case and F6 is now the first. The hosted copy of the subflow check can be deleted. ## Tests <details><summary>Lint: new pins in flow-publish-checks-second-batch.test.ts (describe flow-subflow-unknown)</summary> - CLI: still exactly one `warning`. - Runtime gate refuses a call to a name the stated set lacks: `error`, path `flows[0].nodes[1].config.flowName`, message opening, `rulesRun` names the rule. - A `map` call inside a loop body: `error` at `flows[0].nodes[1].config.body.nodes[0].config.flowName`. - Silent: a name the stated set holds, the written flow calling itself. - No verdict: no stated names, an empty set. </details> <details><summary>Metadata-protocol: the describe in protocol.runtime-authoring-gate.test.ts (the shared harness), end to end through saveMetaItem</summary> - 422 `INVALID_METADATA`, issue `flow-subflow-unknown` at the path, nothing stored. - Accepted: a flow only the automation engine holds, an installed package's flow (registry), a stored draft, a stored active flow. - No automation service: accepted (no verdict). - New (S4): a flow only a DISABLED package ships (listed by the registry only with `includeDisabledPackages`) resolves; a call to nothing in the same case is still a 422. - New (S1): the stored names are read once, `{ where: { type: { $in: ['flow', 'flows'] } }, fields: ['name'] }`; a flow calling only itself, and a flow with no call, read nothing. - New (S3): a store read that throws, accepted with one `warn` naming the cause; a `listFlows` that throws, the same; a missing `sys_metadata` table, no `warn`, engine and registry flows still resolve and a call to nothing is still a 422. - `evaluateRuntimeAuthoringGate`: a flow in `pending.flows` resolves; without it the call is refused. </details> <details><summary>Metadata-protocol: new describe in package-unmanaged-install.test.ts (M1)</summary> - A package declaring `crm_parent` (a `subflow` step calling `crm_child`) before `crm_child`, with an automation service holding `other_flow`: installs, both flows stored active. - Control: `crm_parent` calling `crm_nowhere`: refused 422 with `flow-subflow-unknown`, no active row left, the base `com.example.crm-copy` removed. - Reading, not pinned: the same package installed with `targetNamespace: 'crm2'` is refused 422 (`flow 'crm2_parent' could not be written … flows[0].nodes[1].config.flowName [flow-subflow-unknown]`) and rolled back, because the rename does not rewrite `config.flowName`; see the acceptance notes. </details> <details><summary>Ablations (each fix removed on disk from the committed head, then restored with git checkout HEAD)</summary> - `importUnmanagedPackage` states no `copyPlanFlowNames`: "installs a package that declares the calling flow before the flow it calls" fails (1 failed / 1 passed). - The names read for every flow write (the `flowCallsAnotherFlow` guard dropped): "reads the stored names once …" fails (1 failed / 7 passed). - At 93f3643, the registry read without `includeDisabledPackages`: "lets a call through to a disabled package's flow …" fails (1 failed). </details> <details><summary>Suites (head 93f3643, main merged at 3014176; under os-verify-lock)</summary> - `@objectstack/lint` test: 246 files / 9962 tests passed. typecheck exit 0. - `@objectstack/metadata-protocol` test: 372 passed / 9 skipped files, 23660 passed / 45 skipped tests. typecheck exit 0. `protocol.runtime-authoring-gate.test.ts` + `package-unmanaged-install.test.ts`: 383/383. - `@objectstack/spec` `src/migrations`: 5 files / 209 tests. - Dogfood battery: head 93f3643, `pnpm --filter @objectstack/dogfood test` under the lock after a clean closure build (exit 0): VERDICT command-exit 0, Test Files 495 passed / 3 skipped (498), Tests 4187 passed / 68 skipped (4255), no failure. </details> ## Acceptance notes - Not judged: whether the engine's package-scoped name resolution lets the calling flow reach the called one (ADR-0150 D3). The set is the whole deployment, so an `outside-closure` call still fails at run time. Judging that would need the resolver's verdict at the door. - A call to a stored draft, or an archived or deprecated row, is let through. The step fails until that flow is active. This keeps two new flows that call each other publishable one at a time. - The stored read for names is not filtered for legacy organization rows. An extra name can only let a call through. - A package install under another namespace (`targetNamespace`) renames its flows but not the `config.flowName` that calls them, so a package whose flow calls a sibling is now refused and rolled back unless the deployment holds the old name. On `main` it installed with a step that fails on every run. Making the rename follow flow names is outside this card; reported to the seat as a finding. - A plan flow name counts even if that flow's own write then fails: the install then rolls back whole, so no caller is left pointing at it. - Not addressed, as graded (nits): N2 `listFlows` is read with no seal; N3 the empty-set exit depends on the door; N4 the "did you mean" suggestion draws on the unfiltered stored read; N5 `rulesRun` names the rule on a write where it judged nothing. ## Verification - Read first: `packages/metadata-protocol/src/protocol-package-commits.ts` `importUnmanagedPackage` (`copyPlanFlowNames`) with `protocol-save.ts` (where it becomes `pending.flows`); `packages/metadata-protocol/src/protocol-authoring-gate.ts` `deploymentFlowNamesOf` (the union, the projected read, the no-verdict exits), `packages/lint/src/authoring-rules.ts` the `validateFlowSubflowTargets` entry (runtime pass with no names = nothing), `packages/lint/src/validate-flow-trigger-readiness.ts` `validateFlowSubflowTargets`. - Two minutes: `pnpm --filter @objectstack/metadata-protocol exec vitest run src/protocol.runtime-authoring-gate.test.ts src/package-unmanaged-install.test.ts -t '35143|sibling flow'`. Expect 11 passed, among them a 422 naming `flow-subflow-unknown` and a package install of a caller before its callee. <details><summary>Gates (head 93f3643)</summary> - `dispatch-gates --ran` at 93f3643, run after the closure build: 103 derived, 102 run (all exit 0), 1 NOT MEASURED, 0 unrun (`✓ dispatch-gates --ran: 103 derived famil(ies) accounted for`). - `check:dual-build-cjs-loads` exit 3: needs a full workspace build. Left to CI. - `overlap-check` (`--exclude-pr=38241`) at a7c00fd: clean against origin/main 3014176 and the two open PRs sharing a file (#38550, #38497). The 93f3643 commit touches only files of this PR. - `protocol.ts` moves no line, so `check:facade-delegation-only`'s ceiling is untouched (exit 0 in the sweep). </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes (CI-owned run). - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: only a migration entry's text, no generated artifact moves. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QsR2jSjBfkaFUVwRa3pdUK <!-- signed: repo:objectstack#1 · zhuangjianguo · session_01QsR2jSjBfkaFUVwRa3pdUK --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c1fb1fe commit d33183a

16 files changed

Lines changed: 644 additions & 43 deletions
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
'@objectstack/lint': minor
3+
'@objectstack/metadata-protocol': minor
4+
'@objectstack/spec': patch
5+
---
6+
7+
fix(lint)!: the publish gate refuses a subflow or map step that calls a flow the deployment does not hold
8+
9+
Clause-②: yes (narrowing)
10+
Metadata-protocol: narrowed
11+
12+
<!-- adr-0087: not-required (already-registered publish-refuses-flows-that-save-and-do-not-run) the same subflow-target rule at one more door; this change extends that entry's text from a CLI warning to an error at the runtime publish gate, judged against every flow the deployment holds -->
13+
14+
**BREAKING** accept-set narrowing, shipped as `minor`: an active publish of a flow whose `subflow` or `map` step names a flow that no part of the deployment holds was accepted before and is refused now (`422 INVALID_METADATA`, rule `flow-subflow-unknown`), with the fix named. The schema is unchanged, stored flows are not rewritten or refused at boot, and drafts are not gated.
15+
16+
A `subflow` or `map` step runs the flow its `config.flowName` names. When the engine holds no flow of that name, the step fails on every run (`Flow 'X' not found`). `flow-subflow-unknown` reported this only as a CLI warning, because the publish gate judged one flow at a time and could not tell a call to another stored flow from a call to a missing one.
17+
18+
- **The refusal.** On a flow publish the host now states the names of every flow the deployment holds: every installed package's flows (a disabled package's included), the stored flow rows in every state (a draft counts), the flows the same publish batch or package install carries, and every flow the automation engine holds (a flow registered straight into the engine has no metadata row). A call naming none of them, and not the written flow itself, is an `error` at the publish gate. The names are read only for a flow that calls another flow, and the stored ones in one read of the `name` column.
19+
- **A package install.** An unmanaged install writes its flows one at a time and states the package's flow names on each, so a flow calling a sibling the package declares after it installs. A copy installed under another namespace renames its flows whose names carry the source prefix, but not the `config.flowName` that calls them, so its install is refused, and rolled back whole, unless the deployment holds the old name.
20+
- **No verdict.** When the host cannot read one of those sources (no automation service, a failed store read, said once at `warn`), or the set is empty, the gate does not judge the call.
21+
- **Not judged.** Whether the engine's package-scoped name resolution (ADR-0150 D3) lets the calling flow reach the called one: the set is the whole deployment, never narrowed to the written package's dependency closure.
22+
- **The CLI.** `os validate` / `lint` / `compile` / `build` still report `flow-subflow-unknown` as a warning: the stack is one app, and another installed package may ship the called flow.
23+
- **Exports.** `@objectstack/lint`: `validateFlowSubflowTargets` takes an optional second argument (`FlowSubflowTargetOptions`, `deploymentFlowNames`); `AuthoringRuleContext` gains `deploymentFlowNames`; `runRuntimeAuthoringRules` takes an optional `deploymentFlowNames`. `@objectstack/metadata-protocol`: `saveMetaItem`'s request gains an optional, server-only `copyPlanFlowNames` (the flows the same package install writes; set by the unmanaged install, forwarded by no HTTP door). All optional; an omitted value keeps the earlier behaviour.
24+
25+
FROM → TO:
26+
27+
- `{ type: 'subflow', config: { flowName: 'notfy_owner' } }` (no such flow) → `{ type: 'subflow', config: { flowName: 'notify_owner' } }`
28+
29+
One-line fix: name a flow the deployment holds, or save the called flow first (a draft is enough) and publish the caller after it.

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

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,19 @@ export interface AuthoringRuleContext {
522522
* contradict (AGENTS.md "Startup registry reads").
523523
*/
524524
flowNodeTypeVocabulary?: ReadonlySet<string>;
525+
/**
526+
* The names of every flow the deployment holds: every installed package's
527+
* flows (a disabled package's included), the stored flow rows in every
528+
* state (drafts included), the flows the written item's publish batch or
529+
* package install carries, and every flow the automation
530+
* engine holds. Set only by the runtime publish gate, and only when its host
531+
* could read all of them; ABSENT on the three CLI commands, whose stack is
532+
* one app. Read by `validateFlowSubflowTargets` only: present and non-empty,
533+
* a `subflow` / `map` call naming none of them is refused; absent or empty
534+
* at the runtime gate, that rule judges nothing there (the written flow
535+
* alone is no universe).
536+
*/
537+
deploymentFlowNames?: ReadonlySet<string>;
525538
}
526539

527540
export interface AuthoringRule {
@@ -1739,20 +1752,27 @@ export const AUTHORING_RULES: readonly AuthoringRule[] = [
17391752
// GET → edit → PUT passes, and a secretless `api` flow is refused at `/meta`
17401753
// with this id instead of being stored for the engine to refuse at
17411754
// registration.
1742-
// #35143 — a `subflow` / `map` node calling a flow this stack does not
1743-
// define. CLI only: the runtime gate's flow snapshot holds just the written
1744-
// flow, so every call to another stored flow would read as unknown there.
1745-
// Advisory, with the sibling unknown-object hedge: another installed package
1746-
// may ship the called flow.
1755+
// #35143 — a `subflow` / `map` node calling a flow that does not exist.
1756+
// One verdict per door (the rule's docblock): on the CLI a `warning`, since
1757+
// another installed package may ship the called flow; at the runtime publish
1758+
// gate an `error`, judged against the deployment's flow names the host
1759+
// states (`deploymentFlowNames`), because the gate's own flow snapshot holds
1760+
// just the written flow. With no stated names, or none, the runtime gate's
1761+
// pass judges nothing: a call to another stored flow cannot be told from a
1762+
// call to a missing one there.
17471763
{
17481764
name: 'validateFlowSubflowTargets',
1749-
tier: 'advisory',
1765+
tier: 'gating',
17501766
input: 'normalized',
17511767
commands: ALL,
17521768
source: 'packages/lint/src/validate-flow-trigger-readiness.ts',
1753-
surfaces: CLI_ONLY,
1754-
surfaceReason: RUNTIME_NEEDS_FULL_SNAPSHOT,
1755-
run: (stack) => validateFlowSubflowTargets(stack),
1769+
surfaces: CLI_AND_RUNTIME,
1770+
runtimeTypes: ['flow'],
1771+
run: (stack, ctx) => {
1772+
if (ctx.runtimeWriteType === undefined) return validateFlowSubflowTargets(stack);
1773+
if (ctx.deploymentFlowNames === undefined || ctx.deploymentFlowNames.size === 0) return [];
1774+
return validateFlowSubflowTargets(stack, { deploymentFlowNames: ctx.deploymentFlowNames });
1775+
},
17561776
},
17571777
{
17581778
name: 'validateFlowApiTriggerSecret',

‎packages/lint/src/flow-publish-checks-second-batch.test.ts‎

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,11 +615,59 @@ describe('flow-subflow-unknown', () => {
615615
).toEqual([]);
616616
});
617617

618-
it('runs on the CLI commands and not on the runtime publish gate', () => {
618+
it('stays a warning on the CLI commands', () => {
619619
const cli = runAuthoringRules('validate', { normalized: stack(calling('missing_child')) } as never);
620-
expect(rulesOf(cli)).toContain(FLOW_SUBFLOW_UNKNOWN);
621-
const verdict = runRuntimeAuthoringRules({ type: 'flow', item: calling('missing_child'), context: { objects: [DEAL] } });
622-
expect(rulesOf([...verdict.errors, ...verdict.advisories])).not.toContain(FLOW_SUBFLOW_UNKNOWN);
620+
expect(cli.filter((f) => f.rule === FLOW_SUBFLOW_UNKNOWN).map((f) => f.severity)).toEqual(['warning']);
621+
});
622+
623+
const publish = (item: AnyRec, deploymentFlowNames?: readonly string[]) =>
624+
runRuntimeAuthoringRules({
625+
type: 'flow',
626+
item,
627+
context: { objects: [DEAL] },
628+
...(deploymentFlowNames !== undefined ? { deploymentFlowNames } : {}),
629+
});
630+
631+
it('the runtime publish gate refuses a call to a flow the deployment does not hold', () => {
632+
const verdict = publish(calling('missing_child'), ['child', 'other']);
633+
const refused = verdict.errors.filter((f) => f.rule === FLOW_SUBFLOW_UNKNOWN);
634+
expect(refused).toHaveLength(1);
635+
expect(refused[0]).toMatchObject({ severity: 'error', path: 'flows[0].nodes[1].config.flowName' });
636+
expect(refused[0].message).toContain("calls flow 'missing_child', but no flow of this deployment");
637+
expect(verdict.rulesRun).toContain('validateFlowSubflowTargets');
638+
});
639+
640+
it('refuses a map call nested in a loop body too', () => {
641+
const nested = flow('parent', {}, [
642+
{
643+
id: 'each',
644+
type: 'loop',
645+
label: 'Each',
646+
config: {
647+
collection: { dialect: 'cel', source: '[1]' },
648+
iteratorVariable: 'i',
649+
body: {
650+
nodes: [{ id: 'fan', type: 'map', label: 'Fan', config: { collection: '{{items}}', flowName: 'nope' } }],
651+
edges: [],
652+
},
653+
},
654+
},
655+
]);
656+
const direct = validateFlowSubflowTargets(stack(nested), { deploymentFlowNames: new Set(['child']) });
657+
expect(direct.map((f) => [f.rule, f.severity, f.path])).toEqual([
658+
[FLOW_SUBFLOW_UNKNOWN, 'error', 'flows[0].nodes[1].config.body.nodes[0].config.flowName'],
659+
]);
660+
});
661+
662+
it('the runtime publish gate lets a call through to a flow the deployment holds, or to the written flow itself', () => {
663+
expect(rulesOf(publish(calling('child'), ['child']).errors)).not.toContain(FLOW_SUBFLOW_UNKNOWN);
664+
expect(rulesOf(publish(calling('parent'), ['child']).errors)).not.toContain(FLOW_SUBFLOW_UNKNOWN);
665+
});
666+
667+
it('the runtime publish gate judges nothing with no stated flow names, or an empty set', () => {
668+
for (const verdict of [publish(calling('missing_child')), publish(calling('missing_child'), [])]) {
669+
expect(rulesOf([...verdict.errors, ...verdict.advisories])).not.toContain(FLOW_SUBFLOW_UNKNOWN);
670+
}
623671
});
624672
});
625673

‎packages/lint/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ export {
188188
} from './validate-flow-trigger-readiness.js';
189189
export type {
190190
FlowTriggerReadinessFinding,
191+
FlowSubflowTargetOptions,
191192
FlowTriggerReadinessSeverity,
192193
} from './validate-flow-trigger-readiness.js';
193194

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7185,9 +7185,11 @@ const FLOW_SUBFLOW_UNKNOWN_EXPLANATION: RuleExplanation = {
71857185
paragraphs: [
71867186
'A `subflow` or `map` step runs another flow by the name in `config.flowName`. When no flow has that ' +
71877187
'name, the step fails on every run, and every run of the calling flow fails with it.',
7188-
'A warning, and on the CLI only. Another installed package may ship the called flow, which this stack ' +
7189-
'cannot see. And the runtime publish gate judges one flow per write, so a call to another stored flow ' +
7190-
'could not be told from a call to a missing one there.',
7188+
'On the CLI it is a warning: another installed package may ship the called flow, which this stack ' +
7189+
'cannot see. At publish it is an error, judged against every flow the deployment holds: every ' +
7190+
'installed package\'s flows (a disabled package\'s too), the stored flows in every state (a draft ' +
7191+
'counts), the flows published in the same batch or installed in the same package, and the flows the ' +
7192+
'automation engine holds. Save the called flow first, then publish the one that calls it.',
71917193
],
71927194
};
71937195

‎packages/lint/src/runtime-gate.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,16 @@ export function runRuntimeAuthoringRules(args: {
14791479
* same value in every pass. Omitted, a flow node's type is not judged.
14801480
*/
14811481
flowNodeTypeVocabulary?: readonly string[];
1482+
/**
1483+
* On a `flow` write: the names of every flow the deployment holds, as the
1484+
* host read them (every installed package's flows, a disabled package's
1485+
* included, the stored flow rows in every state, the flows of the batch or
1486+
* package install, the automation engine's flows).
1487+
* Handed to the rules as `AuthoringRuleContext.deploymentFlowNames`, the
1488+
* same value in every pass, so it moves no baseline. Omitted, or empty, a
1489+
* `subflow` / `map` call to another flow is not judged at this door.
1490+
*/
1491+
deploymentFlowNames?: readonly string[];
14821492
}): RuntimeGateResult {
14831493
const rules = runtimeAuthoringRulesFor(args.type);
14841494
const empty: RuntimeGateResult = { errors: [], advisories: [], rulesRun: [] };
@@ -1551,6 +1561,11 @@ export function runRuntimeAuthoringRules(args: {
15511561
...(args.flowNodeTypeVocabulary !== undefined && args.flowNodeTypeVocabulary.length > 0
15521562
? { flowNodeTypeVocabulary: new Set(args.flowNodeTypeVocabulary) }
15531563
: {}),
1564+
// The deployment's flow names, stated by the host on a flow write; the
1565+
// same value in every pass, so it moves no baseline.
1566+
...(args.deploymentFlowNames !== undefined && args.deploymentFlowNames.length > 0
1567+
? { deploymentFlowNames: new Set(args.deploymentFlowNames) }
1568+
: {}),
15541569
};
15551570
const added = addedFindings(rules, snapshots, ctx, args.type, args.item);
15561571

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

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,21 +1920,53 @@ function signatureUnusableFinding(
19201920
* the engine to run that flow by name, and the engine finds none, so the step
19211921
* fails every run (`subflow 'X' failed`).
19221922
*
1923-
* Its OWN exported rule, run on the CLI only, for the reason
1924-
* `flow-trigger-unknown-object` carries a hedge plus one more: the runtime
1925-
* publish gate judges a flow write over a snapshot whose `flows` holds only
1926-
* the written item, so a call to any other stored flow would read as unknown
1927-
* there. On the CLI the stack is one app; a flow another installed package
1928-
* ships is a legitimate target, so the finding is advisory, as that sibling's
1929-
* is without a stated closure.
1923+
* Its OWN exported rule, with one verdict per door, decided by #5762's
1924+
* question (is what this rule reads enough to know?):
1925+
*
1926+
* - On the CLI the stack is one app. A flow another installed package ships
1927+
* is a legitimate target the stack cannot see, so the finding is a
1928+
* `warning`, as `flow-trigger-unknown-object`'s is without a stated closure.
1929+
* - At the runtime publish gate the snapshot's `flows` holds only the written
1930+
* item, so that snapshot alone cannot judge a call. The host states the
1931+
* names of every flow the deployment holds instead
1932+
* (`deploymentFlowNames`: every installed package's flows, a disabled
1933+
* package's included, the stored rows in every state, drafts included,
1934+
* this publish batch's or package install's own flows, and every flow the
1935+
* automation engine holds). A name in none of those is a
1936+
* flow the engine cannot find, so every run of the step fails: `error`.
1937+
* The set is the whole deployment, never narrowed to the written package's
1938+
* closure, so a call this rule lets through may still be one the engine's
1939+
* package-scoped name resolution refuses (ADR-0150 D3); this rule does not
1940+
* judge that. A draft counts as held, so two new flows that call each
1941+
* other can be published one at a time.
1942+
* - At the runtime gate with no stated names, or an empty set, it judges
1943+
* nothing: no deployment state was handed over, and the written flow
1944+
* alone is no universe (the #24668 reading of an empty set with no
1945+
* closure).
19301946
*/
19311947
export const FLOW_SUBFLOW_UNKNOWN = 'flow-subflow-unknown';
19321948

1933-
export function validateFlowSubflowTargets(stack: AnyRec): FlowTriggerReadinessFinding[] {
1949+
export interface FlowSubflowTargetOptions {
1950+
/**
1951+
* The names of every flow the deployment holds, as the runtime publish
1952+
* gate's host states them (`AuthoringRuleContext.deploymentFlowNames`).
1953+
* Present and non-empty, a call that names none of them, nor a flow of
1954+
* this stack, is an `error`. Absent, the CLI's `warning` verdict applies.
1955+
*/
1956+
readonly deploymentFlowNames?: ReadonlySet<string>;
1957+
}
1958+
1959+
export function validateFlowSubflowTargets(
1960+
stack: AnyRec,
1961+
options: FlowSubflowTargetOptions = {},
1962+
): FlowTriggerReadinessFinding[] {
19341963
const findings: FlowTriggerReadinessFinding[] = [];
19351964
const flows = recordsOf(stack.flows);
19361965
if (flows.length === 0) return findings;
1937-
const known = new Set<string>();
1966+
const deployment = options.deploymentFlowNames !== undefined && options.deploymentFlowNames.size > 0
1967+
? options.deploymentFlowNames
1968+
: undefined;
1969+
const known = new Set<string>(deployment);
19381970
for (const flow of flows) {
19391971
const name = nonEmptyString(flow.name);
19401972
if (name) known.add(name);
@@ -1954,6 +1986,23 @@ export function validateFlowSubflowTargets(stack: AnyRec): FlowTriggerReadinessF
19541986
if (!called || known.has(called)) continue;
19551987
const nodeId = nonEmptyString(node.id) ?? String(node.type);
19561988
const nodeWhere = regionTrail ? `${regionTrail} › node "${nodeId}"` : `node "${nodeId}"`;
1989+
if (deployment) {
1990+
findings.push({
1991+
severity: 'error',
1992+
rule: FLOW_SUBFLOW_UNKNOWN,
1993+
where: `flow "${flowName}" › ${nodeWhere}`,
1994+
path: `${path}.config.flowName`,
1995+
message:
1996+
`${String(node.type)} node '${nodeId}' calls flow '${called}', but no flow of this deployment (an ` +
1997+
`installed package's, a stored flow or a draft) has that name, so the engine finds none and the ` +
1998+
`step fails on every run` +
1999+
suggestName(called, known),
2000+
hint:
2001+
`Set config.flowName to the exact name of a flow this deployment holds, or save the called flow ` +
2002+
`first (a draft is enough) and publish this one after it`,
2003+
});
2004+
continue;
2005+
}
19572006
findings.push({
19582007
severity: 'warning',
19592008
rule: FLOW_SUBFLOW_UNKNOWN,

0 commit comments

Comments
 (0)