Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/34616-flow-trigger-dependency-closure.md
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion content/docs/deployment/validating-metadata.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 47 additions & 1 deletion packages/cli/src/utils/artifact-packages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })`
Expand Down Expand Up @@ -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<string, string>) => ({
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<string, string>) =>
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([]);
});
});
16 changes: 9 additions & 7 deletions packages/lint/src/rule-explanations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down Expand Up @@ -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 ' +
Expand Down
78 changes: 78 additions & 0 deletions packages/lint/src/validate-flow-trigger-readiness.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown> }).config.objectName = objectName;
return flow;
};
/** Package B's stack as `packageBodyAsStack` builds it, with A in `packages[]`. */
const packageBStack = (
bManifest: Record<string, unknown>,
packages: Array<Record<string, unknown>>,
flows: unknown[] = [flowOn('exp_report')],
) => ({ objects: [candidateObject], flows, manifest: bManifest, packages });
const pkgA = { manifest: { id: 'pkg_expense', objects: [expenseObject] } };
const pkgB = (dependencies?: Record<string, string>) => ({
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)', () => {
Expand Down
75 changes: 71 additions & 4 deletions packages/lint/src/validate-flow-trigger-readiness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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<string, AnyRec>();
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;
}
Expand All @@ -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,
Expand All @@ -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
Expand Down
Loading