From f2f2a84525c77232d7c6b40dc4c1d4169f178ee9 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 04:36:43 +0000 Subject: [PATCH 1/2] fix(lint): flow trigger rule counts the objects of a manifest's declared dependencies The CLI's per-package authoring pass hands each package's stack the artifact's packages[] as resolution context, but validateFlowTriggerReadiness read only stack.objects. A flow in package B on an object its declared dependency A owns warned flow-trigger-unknown-object, and os lint --strict failed a flow the runtime publish gate accepts. With no closure stated, the rule now adds the objects of B's dependency closure, walked by resolvePackageClosure (the publish gate's own walk) over the packages[] entries the artifact carries. An undeclared sibling and a name no closure package provides still warn; a stated closure is unchanged. flow-input-unknown-object reads the same name set and gets the same answer. Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01ADHkmRfW5u1LRmhWwaYHRp --- .../34616-flow-trigger-dependency-closure.md | 10 +++ .../cli/src/utils/artifact-packages.test.ts | 48 +++++++++++- packages/lint/src/rule-explanations.ts | 16 ++-- .../validate-flow-trigger-readiness.test.ts | 78 +++++++++++++++++++ .../src/validate-flow-trigger-readiness.ts | 75 +++++++++++++++++- 5 files changed, 215 insertions(+), 12 deletions(-) create mode 100644 .changeset/34616-flow-trigger-dependency-closure.md diff --git a/.changeset/34616-flow-trigger-dependency-closure.md b/.changeset/34616-flow-trigger-dependency-closure.md new file mode 100644 index 00000000000..d287af72aba --- /dev/null +++ b/.changeset/34616-flow-trigger-dependency-closure.md @@ -0,0 +1,10 @@ +--- +'@objectstack/lint': patch +--- + +fix(lint): `flow-trigger-unknown-object` and `flow-input-unknown-object` count the objects of the packages a manifest declares in `dependencies` + +The CLI's per-package pass judges each package of a multi-package artifact with the artifact's `packages[]` as resolution context. The flow trigger rule never read it, so a flow in package B on an object its declared dependency A owns warned `flow-trigger-unknown-object`, and `os lint --strict` failed a flow the runtime publish gate accepts (the gate judges the write against B's closure, which holds A's objects). The rule now counts the objects of B's dependency closure (the gate's own transitive walk, read off `packages[]`) as defined. A sibling package B did not declare still warns, and so does a name no package in the closure provides. Under a closure the publish gate states, nothing changes. + +Clause-②: no +Metadata-protocol: none diff --git a/packages/cli/src/utils/artifact-packages.test.ts b/packages/cli/src/utils/artifact-packages.test.ts index ce32ab60931..4a373dae4b1 100644 --- a/packages/cli/src/utils/artifact-packages.test.ts +++ b/packages/cli/src/utils/artifact-packages.test.ts @@ -41,7 +41,7 @@ import { describe, expect, it } from 'vitest'; import { validateObjectReferences } from '@objectstack/lint'; -import { artifactPackages, packageBodyAsStack } from './artifact-packages.js'; +import { artifactPackages, packageBodyAsStack, runPerPackageAuthoringRules } from './artifact-packages.js'; /** * A two-package artifact in the shape `composeStacks(…, { manifest: 'preserve' })` @@ -144,3 +144,49 @@ describe('packageBodyAsStack — the per-package leg resolves a sibling package expect(stack.manifest).toBe(artifactPackages(ARTIFACT)[0].body); }); }); + +/** + * [#34616] The per-package pass judges a flow in package B on an object B's + * declared dependency A owns. The runtime publish gate judges that write + * against B's closure, which holds A's objects, and accepts it, so the + * author-time door must not advise against it either: under `os lint --strict` + * the advisory failed the build. + */ +describe('runPerPackageAuthoringRules — a flow on a declared dependency\'s object (#34616)', () => { + const EXPENSE_BODY = { + id: 'com.example.expense', + objects: [{ name: 'exp_report', label: 'Expense report', fields: { name: { type: 'text' } } }], + }; + const psaBody = (dependencies?: Record) => ({ + id: 'com.example.psa', + ...(dependencies ? { dependencies } : {}), + flows: [ + { + name: 'report_submitted', + type: 'autolaunched', + status: 'active', + nodes: [ + { id: 'start', type: 'start', config: { objectName: 'exp_report', triggerType: 'record-after-create' } }, + { id: 'end', type: 'end' }, + ], + edges: [{ id: 'e1', source: 'start', target: 'end' }], + }, + ], + }); + const triggerFindings = (dependencies?: Record) => + runPerPackageAuthoringRules({ + command: 'lint', + parsed: { packages: [{ manifest: EXPENSE_BODY }, { manifest: psaBody(dependencies) }] }, + unionFindings: [], + }).findings.filter((f) => f.rule === 'flow-trigger-unknown-object'); + + it('CONTROL — without the dependency the pass advises, at the dependent package', () => { + expect(triggerFindings().map((f) => [f.severity, f.where])).toEqual([ + ['warning', "package 'com.example.psa' — flow \"report_submitted\" › start node"], + ]); + }); + + it('with the dependency declared the pass has nothing to say about the trigger object', () => { + expect(triggerFindings({ 'com.example.expense': '^1.0.0' })).toEqual([]); + }); +}); diff --git a/packages/lint/src/rule-explanations.ts b/packages/lint/src/rule-explanations.ts index ad337d8e42a..36e172e7309 100644 --- a/packages/lint/src/rule-explanations.ts +++ b/packages/lint/src/rule-explanations.ts @@ -2388,9 +2388,10 @@ const FLOW_TRIGGER_UNKNOWN_OBJECT_EXPLANATION: RuleExplanation = { '`config.objectName`, and a time-relative sweep queries the exact name in `config.timeRelative.object`. ' + 'Names match exactly — `app_candidate`, not `candidate` — so when no object answers to that name the ' + 'flow never fires, or the sweep matches nothing, and the runtime says nothing about it.', - 'The rule asks whether this stack defines the object. One it does not define may be declared by ' + - 'another installed package, which a build of this stack cannot see, so the finding is a warning and ' + - 'can be ignored when such a package declares the object; a `sys_` name is a platform object and is ' + + 'The rule asks whether this stack defines the object, counting the objects of the packages its ' + + 'manifest declares in `dependencies` when the artifact carries them. One it does not define may be ' + + 'declared by another installed package, which a build of this stack cannot see, so the finding is a ' + + 'warning and can be ignored when such a package declares the object; a `sys_` name is a platform object and is ' + 'not judged. Of the findings that say a flow never fires, it is the only one that stays advisory: ' + 'the others are settled by contracts this repository ships. At the runtime publish gate a write that ' + 'names no package gets it as a save advisory, judged against the live object registry.', @@ -2418,10 +2419,11 @@ const FLOW_INPUT_UNKNOWN_OBJECT_EXPLANATION: RuleExplanation = { 'scope before the run exists, so a name no object answers to refuses every start that supplies ' + 'the input. Names match exactly — `app_candidate`, not `candidate`. Every door that starts the flow ' + 'by name enforces the declaration.', - 'The rule asks whether this stack defines the object. One it does not define may be declared by ' + - 'another installed package, which a build of this stack cannot see, so the finding is a warning and ' + - 'can be ignored when such a package declares the object; a `sys_` name is a platform object and is ' + - 'not judged. A start that omits the input is not affected, so this is not a verdict that the flow ' + + 'The rule asks whether this stack defines the object, counting the objects of the packages its ' + + 'manifest declares in `dependencies` when the artifact carries them. One it does not define may be ' + + 'declared by another installed package, which a build of this stack cannot see, so the finding is a ' + + 'warning and can be ignored when such a package declares the object; a `sys_` name is a platform ' + + 'object and is not judged. A start that omits the input is not affected, so this is not a verdict that the flow ' + 'never runs.', 'A write into a package is judged against that package\'s closure instead: its own objects, the objects ' + 'of the packages its manifest declares in `dependencies`, and platform objects. An object outside it ' + diff --git a/packages/lint/src/validate-flow-trigger-readiness.test.ts b/packages/lint/src/validate-flow-trigger-readiness.test.ts index 399bab51da5..2cc3d8b5565 100644 --- a/packages/lint/src/validate-flow-trigger-readiness.test.ts +++ b/packages/lint/src/validate-flow-trigger-readiness.test.ts @@ -135,6 +135,84 @@ describe('validateFlowTriggerReadiness', () => { expect(findings).toEqual([]); }); + // #34616 — the CLI's per-package pass hands each package's stack the + // artifact's `packages[]` as resolution context. A name a package the + // manifest declares in `dependencies` provides is inside the publish gate's + // closure, so it is defined here too; a sibling it did not declare is not. + describe('[#34616] a declared dependency carried in packages[] provides the object', () => { + const expenseObject = { name: 'exp_report', label: 'Expense report', fields: {} }; + const flowOn = (objectName: string) => { + const flow = recordFlow({ status: 'active' }); + (flow.nodes[0] as { config: Record }).config.objectName = objectName; + return flow; + }; + /** Package B's stack as `packageBodyAsStack` builds it, with A in `packages[]`. */ + const packageBStack = ( + bManifest: Record, + packages: Array>, + flows: unknown[] = [flowOn('exp_report')], + ) => ({ objects: [candidateObject], flows, manifest: bManifest, packages }); + const pkgA = { manifest: { id: 'pkg_expense', objects: [expenseObject] } }; + const pkgB = (dependencies?: Record) => ({ + id: 'pkg_psa', + ...(dependencies ? { dependencies } : {}), + }); + + it('a flow on a declared dependency\'s object is not flagged', () => { + const b = pkgB({ pkg_expense: '^1.0.0' }); + expect(validateFlowTriggerReadiness(packageBStack(b, [pkgA, { manifest: b }]))).toEqual([]); + }); + + it('the same flow still warns when the manifest does not declare the dependency', () => { + const b = pkgB(); + const findings = validateFlowTriggerReadiness(packageBStack(b, [pkgA, { manifest: b }])); + expect(findings.map((f) => [f.rule, f.severity, f.path])).toEqual([ + [FLOW_TRIGGER_UNKNOWN_OBJECT, 'warning', 'flows[0].nodes[0].config.objectName'], + ]); + }); + + it('the closure is transitive: a dependency of a dependency provides the object', () => { + const mid = { manifest: { id: 'pkg_finance', dependencies: { pkg_expense: '^1.0.0' }, objects: [] } }; + const b = pkgB({ pkg_finance: '^1.0.0' }); + expect(validateFlowTriggerReadiness(packageBStack(b, [pkgA, mid, { manifest: b }]))).toEqual([]); + }); + + it('a declared dependency the artifact does not carry provides nothing', () => { + const b = pkgB({ pkg_expense: '^1.0.0' }); + const findings = validateFlowTriggerReadiness(packageBStack(b, [{ manifest: b }])); + expect(findings.map((f) => f.rule)).toEqual([FLOW_TRIGGER_UNKNOWN_OBJECT]); + }); + + it('a name outside the dependency\'s objects keeps its finding', () => { + const b = pkgB({ pkg_expense: '^1.0.0' }); + const findings = validateFlowTriggerReadiness( + packageBStack(b, [pkgA, { manifest: b }], [flowOn('exp_reprot')]), + ); + expect(findings.map((f) => f.rule)).toEqual([FLOW_TRIGGER_UNKNOWN_OBJECT]); + expect(findings[0].message).toContain("'exp_reprot'"); + }); + + it('a start input declared a record of a declared dependency\'s object is not flagged', () => { + const b = pkgB({ pkg_expense: '^1.0.0' }); + const inputFlow = recordFlow({ + name: 'close_report', type: 'screen', status: 'active', + variables: [{ name: 'reportId', type: 'text', isInput: true, objectName: 'exp_report' }], + nodes: [{ id: 'start', type: 'start' }, { id: 'end', type: 'end' }], + }); + expect(validateFlowTriggerReadiness(packageBStack(b, [pkgA, { manifest: b }], [inputFlow]))).toEqual([]); + const undeclared = validateFlowTriggerReadiness(packageBStack(pkgB(), [pkgA, { manifest: pkgB() }], [inputFlow])); + expect(undeclared.map((f) => f.rule)).toEqual([FLOW_INPUT_UNKNOWN_OBJECT]); + }); + + it('under a stated closure nothing is added: the stack is the closure', () => { + const b = pkgB({ pkg_expense: '^1.0.0' }); + const findings = validateFlowTriggerReadiness(packageBStack(b, [pkgA, { manifest: b }]), { + packageScope: { packageId: 'pkg_psa', dependencies: ['pkg_expense'] }, + }); + expect(findings.map((f) => [f.rule, f.severity])).toEqual([[FLOW_TRIGGER_UNKNOWN_OBJECT, 'error']]); + }); + }); + // #29442 (#29425 ruling A) — a start input declared a record reference // names the object every start door loads it from. describe('a start input declared a record reference (variables[].objectName)', () => { diff --git a/packages/lint/src/validate-flow-trigger-readiness.ts b/packages/lint/src/validate-flow-trigger-readiness.ts index 41937700936..89cc72686ac 100644 --- a/packages/lint/src/validate-flow-trigger-readiness.ts +++ b/packages/lint/src/validate-flow-trigger-readiness.ts @@ -168,7 +168,11 @@ // an object outside its package's closure. A `sys_`-prefixed name stays // unjudged under a closure too, exactly as without one. The CLI commands // and a write that names no package state no closure and keep the advisory -// unchanged. +// unchanged, with one narrowing (#34616): a name that a package the stack's +// manifest declares in `dependencies` provides, read off the artifact's +// `packages[]`, is defined, as it is inside the publish gate's closure. So +// the CLI's per-package pass no longer warns on a dependency's object; a +// sibling package the manifest did not declare still warns. // - `warning` / `error` — `flow-input-unknown-object` (#29442), on the same // question and the same closure split as `flow-trigger-unknown-object`: a // start input declared a record reference (`variables[].objectName`) names @@ -213,8 +217,9 @@ import { apiTriggerVerifierOf, resolveFlowTriggerKind, } from '@objectstack/spec/automation'; +import { resolvePackageClosure } from '@objectstack/metadata-core'; import { walkFlowNodes } from './flow-walk.js'; -import { closureDependencyRemedy, recordsOf, suggestName } from './object-graph.js'; +import { closureDependencyRemedy, packagesOf, recordsOf, suggestName } from './object-graph.js'; import type { UserTextParams } from './finding-user-text.js'; export type FlowTriggerReadinessSeverity = 'error' | 'warning'; @@ -559,6 +564,61 @@ function plainRecord(value: unknown): AnyRec | undefined { return value !== null && typeof value === 'object' && !Array.isArray(value) ? (value as AnyRec) : undefined; } +/** + * [#34616] The objects the packages this stack's manifest declares in + * `dependencies` (transitively) provide, read off the artifact's `packages[]` + * — the resolution context the CLI's per-package pass hands every package's + * stack (`packageBodyAsStack`, ADR-0130 D4). + * + * The per-package pass judges one package's collections, so a flow in package + * B on an object its declared dependency A owns read as a name "this stack does + * not define" and warned, and `os lint --strict` failed a flow the runtime + * publish gate accepts: the gate judges the same write against B's closure + * (#24669, ruling #9612), and A's objects are in it. This is that closure, by + * the gate's own walk ({@link resolvePackageClosure}), with `packages[]` as the + * package registry. So the author-time door and the publish door give the same + * answer for a dependency's object. + * + * ⛔ The closure, not every entry of `packages[]`. A sibling package B did not + * declare is outside what the publish gate lets B bind a flow to, so its object + * keeps the advisory here: the remedy (declare the dependency) is the one the + * gate names when it refuses. + * + * Empty when there is no `packages[]`, no `manifest.id`, or no declared + * dependency the artifact carries. A dependency the artifact does not carry + * contributes nothing: its objects are not in this stack to read, and the + * advisory's hedge ("another installed package") still covers it. + */ +function dependencyClosureObjectNames(stack: AnyRec): string[] { + const entries = packagesOf(stack); + if (entries.length === 0) return []; + const manifest = stack.manifest; + if (!manifest || typeof manifest !== 'object' || Array.isArray(manifest)) return []; + const ownId = nonEmptyString((manifest as AnyRec).id); + if (!ownId) return []; + const carried = new Map(); + for (const entry of entries) { + const body = entry.manifest; + if (!body || typeof body !== 'object' || Array.isArray(body)) continue; + const id = nonEmptyString((body as AnyRec).id); + if (id && !carried.has(id)) carried.set(id, body as AnyRec); + } + const closure = resolvePackageClosure(ownId, (id) => { + if (id === ownId) return { manifest }; + const body = carried.get(id); + return body ? { manifest: body } : undefined; + }); + if (!closure) return []; + const names: string[] = []; + for (const dep of closure.dependencies) { + for (const obj of recordsOf(carried.get(dep)?.objects)) { + const name = nonEmptyString(obj.name); + if (name) names.push(name); + } + } + return names; +} + function nonEmptyString(value: unknown): string | undefined { return typeof value === 'string' && value !== '' ? value : undefined; } @@ -582,7 +642,9 @@ function startNodeOf(flow: AnyRec): { node: AnyRec; index: number } | undefined * gate narrowed `stack.objects` to (`AuthoringRuleContext.packageScope`), * present only when one was in force. Stated, an unknown trigger object is * outside that closure and `flow-trigger-unknown-object` is an `error` (see - * the Severity section at the top of this file). The CLI never sets it. + * the Severity section at the top of this file). The CLI never sets it; + * without it, a declared dependency's objects carried in `packages[]` count + * as defined (#34616, `dependencyClosureObjectNames`). */ export function validateFlowTriggerReadiness( stack: AnyRec, @@ -592,12 +654,17 @@ export function validateFlowTriggerReadiness( const flows = recordsOf(stack.flows); if (flows.length === 0) return findings; + const closure = options.packageScope; const objectNames = new Set( recordsOf(stack.objects) .map((o) => (typeof o.name === 'string' ? o.name : undefined)) .filter((n): n is string => !!n), ); - const closure = options.packageScope; + // [#34616] With no closure stated (the CLI doors), a name a declared + // dependency carried in `packages[]` provides is defined: the publish gate's + // closure holds it. Under a stated closure `stack.objects` already IS the + // closure, so nothing is added there. + if (!closure) for (const name of dependencyClosureObjectNames(stack)) objectNames.add(name); /** * [#24669] `flow-trigger-unknown-object` at one of its two positions, for a From 87e47ab9486b0d407c2a2aa3fa875e8b94985052 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 05:11:40 +0000 Subject: [PATCH 2/2] docs(validating-metadata): the per-package walk resolves a flow's object through the declared dependency closure Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01ADHkmRfW5u1LRmhWwaYHRp --- content/docs/deployment/validating-metadata.mdx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/content/docs/deployment/validating-metadata.mdx b/content/docs/deployment/validating-metadata.mdx index ff349ada78d..37d0ca5ba61 100644 --- a/content/docs/deployment/validating-metadata.mdx +++ b/content/docs/deployment/validating-metadata.mdx @@ -785,7 +785,12 @@ matrix answers the first question only. page, action, app, dashboard or flow (the [orphan-key table](/docs/protocol/kernel/i18n-standard#orphan-keys-and-option-keys) lists every rung) — while the collections being judged stay that package's - alone. It is de-duplicated against the union run, so what it reports is the + alone. A flow's trigger object and a start input's record object are the one + place it is narrower: they resolve only through the packages the manifest + declares in `dependencies` (transitively), the closure the publish gate + judges the same flow against, so a flow on a declared dependency's object is + clean and one on an undeclared sibling's object still warns + `flow-trigger-unknown-object` (#34616). It is de-duplicated against the union run, so what it reports is the set of per-package findings no union finding already carried under the same rule, `where`, message and non-top-level position — the leading `collection[N]` index is neutralised, because a package body re-bases its