Skip to content

Commit 03cc2f4

Browse files
committed
fix(cli): the flow-region gate never passes a flow it could not judge, and the boot banner counts refused flows
- findFlowRegionRefusals: a FlowSchema parse failure is a located VALIDATION_ERROR row instead of a silent return. - authoring-rule-command-parity: the OUTSIDE_THE_TABLE pin also asserts the doors' own gate refuses its fixture with the marker; docblock says it measures the registry; test-budget header counts ten rule cases. - validate-flow-region-shape: an assembled-artifact packages[] fixture, asserting exit code, path and that build writes no dist/. - os serve banner: declared flows the engine refused at registration are counted beside the declared count, from getFlowRegistration. Claude-Session: https://claude.ai/code/session_01ADHkmQBbn1k9FtQeh2nJSs Co-authored-by: Claude <noreply@anthropic.com>
1 parent fea2dbb commit 03cc2f4

10 files changed

Lines changed: 326 additions & 13 deletions
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@objectstack/cli': patch
3+
---
4+
5+
fix(cli): the os validate / os build flow-region check never passes a flow it could not judge, and the boot banner counts flows refused at registration
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
- **No silent pass.** The flow-region check `os validate` and `os build` run (the automation engine's registration verdict, ADR-0031) parses each flow with `FlowSchema` before it judges the regions. When that parse failed it used to skip the flow with no row, so the flow passed unjudged. It now refuses it with a `VALIDATION_ERROR` row at the flow's `path`, naming the flow and the schema's issues. No authored stack reaches this branch today: the stack schema has already parsed every flow the check reads, and `FlowSchema` accepts its own output. Nothing refused or accepted today changes.
11+
- **Refused flows in the boot banner.** When the automation engine refuses a declared flow at registration, boot still continues and the per-flow reason is still under Boot diagnostics. The `os serve` / `os dev` banner now also prints one line beside the declared count, for example `⚠ Flows: 2 flow(s) declared, 1 refused at registration`, read from the engine's own record (`getFlowRegistration`). It prints even when every declared flow was refused and nothing registered. A boot with nothing refused prints no such line.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// [#29059] The boot banner counts declared flows the engine REFUSED at
4+
// registration, beside the declared count.
5+
//
6+
// A flow `registerFlow` refuses is logged once at WARN and the boot goes on
7+
// without it (#28893's second ask; that is unchanged here). Before this the
8+
// banner's Flows line counted only what armed, so a refused flow showed only
9+
// as a per-flow line under Boot diagnostics, and a boot whose every declared
10+
// flow was refused printed no Flows line at all.
11+
//
12+
// The count is read off the engine's own record: the host's sync calls
13+
// `recordFlowRefusal` when `registerFlow` throws, and the banner asks
14+
// `getFlowRegistration(name)` for each declared name, the read the metadata
15+
// door already serves. So the engine here is the REAL one (dist, already in
16+
// `KNOWN_UNALIASED_TEST_IMPORTS['@objectstack/cli']`), refusing a real
17+
// malformed region, not a fake that answers `refused` by fiat. Locally: build
18+
// `@objectstack/service-automation` before running this.
19+
20+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
21+
import { AutomationEngine } from '@objectstack/service-automation';
22+
import { collectAutomationSummary } from './serve.js';
23+
import { printServerReady, type ServerReadyOptions } from '../utils/format.js';
24+
25+
const quiet = () => ({ debug() {}, info() {}, warn() {}, error() {} }) as never;
26+
27+
const kernelWith = (automation: unknown) => ({
28+
getService(name: string) {
29+
if (name === 'automation') return automation;
30+
throw new Error(`Service '${name}' not found`);
31+
},
32+
});
33+
34+
const n = (id: string, type = 'assignment', extra: Record<string, unknown> = {}) => ({ id, type, label: id, ...extra });
35+
const e = (id: string, source: string, target: string) => ({ id, source, target, type: 'default' });
36+
37+
/** An autolaunched flow: start → <middle> → end. */
38+
const flow = (name: string, middle: Record<string, unknown>) => ({
39+
name, label: name, type: 'autolaunched', status: 'active',
40+
nodes: [n('start', 'start'), middle, n('end', 'end')],
41+
edges: [e('e1', 'start', String(middle.id)), e('e2', String(middle.id), 'end')],
42+
});
43+
44+
/** A `parallel` with one branch: `validateControlFlow` refuses it at registration. */
45+
const refusedFlow = (name: string) => flow(name, n('fan', 'parallel', { config: { branches: [{ nodes: [n('only')], edges: [] }] } }));
46+
const goodFlow = (name: string) => flow(name, n('work'));
47+
48+
/** Register each flow the way the host's sync does: a refusal is recorded, never thrown on. */
49+
function engineWith(flows: Array<{ name: string }>): AutomationEngine {
50+
const engine = new AutomationEngine(quiet());
51+
for (const def of flows) {
52+
try {
53+
engine.registerFlow(def.name, def as never);
54+
} catch (err) {
55+
engine.recordFlowRefusal(def.name, err);
56+
}
57+
}
58+
return engine;
59+
}
60+
61+
const base: ServerReadyOptions = {
62+
externalBaseOrigin: 'http://localhost:3000',
63+
httpServer: 'composed',
64+
configFile: 'objectstack.config.ts',
65+
isDev: true,
66+
pluginCount: 1,
67+
};
68+
69+
describe('[#29059] the boot banner counts flows refused at registration', () => {
70+
let lines: string[];
71+
let spy: ReturnType<typeof vi.spyOn>;
72+
beforeEach(() => {
73+
lines = [];
74+
// stderr, not stdout (#7915) — the whole banner is a diagnostic.
75+
spy = vi.spyOn(console, 'error').mockImplementation((...args: unknown[]) => {
76+
lines.push(args.join(' '));
77+
});
78+
});
79+
afterEach(() => spy.mockRestore());
80+
81+
const flowsLines = () => lines.filter((l) => l.includes('Flows:'));
82+
83+
it('one of two declared flows refused: the count rides beside the declared count', () => {
84+
const declared = [goodFlow('ok_flow'), refusedFlow('fan_flow')];
85+
const engine = engineWith(declared);
86+
// The engine really refused it: the record is its own, not the test's.
87+
expect(engine.getFlowRegistration('fan_flow').state).toBe('refused');
88+
89+
const summary = collectAutomationSummary(kernelWith(engine), declared.length, declared.map((f) => f.name))!;
90+
expect(summary).toMatchObject({ declaredFlowCount: 2, refusedCount: 1, flowCount: 1 });
91+
92+
printServerReady({ ...base, automation: summary });
93+
expect(flowsLines().filter((l) => l.includes('2 flow(s) declared, 1 refused at registration'))).toHaveLength(1);
94+
});
95+
96+
it('every declared flow refused: the banner still says so, though nothing registered', () => {
97+
const declared = [refusedFlow('fan_flow')];
98+
const summary = collectAutomationSummary(kernelWith(engineWith(declared)), 1, ['fan_flow'])!;
99+
expect(summary).toMatchObject({ declaredFlowCount: 1, refusedCount: 1, flowCount: 0 });
100+
101+
printServerReady({ ...base, automation: summary });
102+
expect(flowsLines().filter((l) => l.includes('1 flow(s) declared, 1 refused at registration'))).toHaveLength(1);
103+
});
104+
105+
it('CONTROL: nothing refused prints no refused line', () => {
106+
const declared = [goodFlow('ok_flow')];
107+
const summary = collectAutomationSummary(kernelWith(engineWith(declared)), 1, ['ok_flow'])!;
108+
expect(summary.refusedCount).toBe(0);
109+
110+
printServerReady({ ...base, automation: summary });
111+
expect(lines.filter((l) => l.includes('refused at registration'))).toEqual([]);
112+
expect(flowsLines()).toHaveLength(1);
113+
});
114+
115+
it('an engine that does not answer the read degrades to a zero count, not a crash', () => {
116+
const older = { getFlowRuntimeStates: () => [{ name: 'ok_flow', enabled: true, bound: false }] };
117+
const summary = collectAutomationSummary(kernelWith(older), 2, ['ok_flow', 'fan_flow'])!;
118+
expect(summary.refusedCount).toBe(0);
119+
});
120+
});

‎packages/cli/src/commands/serve.ts‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5705,9 +5705,13 @@ export default class Serve extends Command {
57055705
// [#22288] Counted by `resolveStackCollection`'s rule, so a flow a
57065706
// package declares is counted: the "declared but the automation engine is
57075707
// not enabled" line used to stay silent for every multi-package app.
5708+
const declaredFlows = resolveStackCollection(config, 'flows');
57085709
const automationSummary = collectAutomationSummary(
57095710
kernel,
5710-
resolveStackCollection(config, 'flows').length,
5711+
declaredFlows.length,
5712+
declaredFlows
5713+
.map((f) => (f as { name?: unknown } | null)?.name)
5714+
.filter((name): name is string => typeof name === 'string' && name !== ''),
57115715
);
57125716

57135717
// ── Seed outcome summary (#3415/#3430) ─────────────────────────
@@ -7241,6 +7245,11 @@ export function resolveBannerConfigRow(opts: {
72417245
export function collectAutomationSummary(
72427246
kernel: any,
72437247
declaredFlowCount: number,
7248+
/**
7249+
* [#29059] The declared flows' names, for the refused-at-registration count.
7250+
* Optional so a caller with only a count keeps its summary; its count is 0.
7251+
*/
7252+
declaredFlowNames: readonly string[] = [],
72447253
): AutomationReadySummary | undefined {
72457254
let automation: any;
72467255
try { automation = kernel?.getService?.('automation'); } catch { /* not registered */ }
@@ -7250,6 +7259,7 @@ export function collectAutomationSummary(
72507259
? {
72517260
enabled: false,
72527261
declaredFlowCount,
7262+
refusedCount: 0,
72537263
flowCount: 0,
72547264
boundCount: 0,
72557265
triggerTypes: [],
@@ -7292,6 +7302,21 @@ export function collectAutomationSummary(
72927302
try { states = automation.getFlowRuntimeStates?.() ?? []; } catch { /* older engine */ }
72937303
if (states.length === 0 && declaredFlowCount === 0) return undefined;
72947304

7305+
// [#29059] Declared flows the engine refused at registration, read off the
7306+
// engine's OWN record through the read it already serves the metadata door
7307+
// (`IAutomationService.getFlowRegistration`), one declared name at a time.
7308+
// No new engine surface: the probe is optional and feature-detected like the
7309+
// ones beside it. The record is written by the `kernel:ready` bind, which
7310+
// has settled by the time the banner prints.
7311+
let refusedCount = 0;
7312+
if (typeof automation.getFlowRegistration === 'function') {
7313+
for (const name of new Set(declaredFlowNames)) {
7314+
try {
7315+
if (automation.getFlowRegistration(name)?.state === 'refused') refusedCount++;
7316+
} catch { /* older engine */ }
7317+
}
7318+
}
7319+
72957320
let triggerTypes: string[] = [];
72967321
try { triggerTypes = automation.getRegisteredTriggerTypes?.() ?? []; } catch { /* older engine */ }
72977322

@@ -7328,6 +7353,7 @@ export function collectAutomationSummary(
73287353
return {
73297354
enabled: true,
73307355
declaredFlowCount,
7356+
refusedCount,
73317357
flowCount: states.length,
73327358
boundCount: states.filter((s) => s.bound).length,
73337359
triggerTypes,
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#29059] `findFlowRegionRefusals` never passes a flow it could not judge.
5+
*
6+
* The walk parses each flow with `FlowSchema` before it asks
7+
* `validateControlFlow` for the region verdict. The stack schema has already
8+
* parsed every flow it reads, and `FlowSchema` is idempotent on its own output,
9+
* so no authored stack reaches the refused-parse branch today; the cases below
10+
* hand the walk bodies the schema refuses, which is the only way to force it.
11+
* Before #29059 the branch was a bare `return`: no row, so `os validate` and
12+
* `os build` passed a flow whose region shape nobody had judged.
13+
*
14+
* What the door does with a row is pinned end to end in
15+
* `test/validate-flow-region-shape.test.ts`; here the subject is the row.
16+
*/
17+
18+
import { describe, expect, it } from 'vitest';
19+
20+
import { findFlowRegionRefusals } from './flow-region-shape.js';
21+
22+
/** A body `FlowSchema` refuses: `nodes` must be an array. */
23+
const unparseable = (name?: string) => ({ ...(name === undefined ? {} : { name }), label: 'Broken', type: 'autolaunched', nodes: 'start', edges: [] });
24+
25+
const located = (rows: ReturnType<typeof findFlowRegionRefusals>) => rows.map(({ path, code, flow }) => ({ path, code, flow }));
26+
27+
describe('[#29059] a flow the flow schema refuses is a row, never a silent pass', () => {
28+
it('the stack\'s own flows: the row names the flow and its path', () => {
29+
const rows = findFlowRegionRefusals({ flows: [unparseable('rgn_broken')] });
30+
expect(located(rows)).toEqual([{ path: 'flows[0]', code: 'VALIDATION_ERROR', flow: 'rgn_broken' }]);
31+
expect(rows[0]!.message).toContain("'rgn_broken'");
32+
// The schema's own issue rides the row, so the author is told what it refused.
33+
expect(rows[0]!.message).toContain('nodes');
34+
});
35+
36+
it('a body with no string name is named by its path', () => {
37+
const rows = findFlowRegionRefusals({ flows: [unparseable()] });
38+
expect(located(rows)).toEqual([{ path: 'flows[0]', code: 'VALIDATION_ERROR', flow: 'flows[0]' }]);
39+
});
40+
41+
it('an artifact\'s packages[] entry: located under its own entry', () => {
42+
const rows = findFlowRegionRefusals({
43+
flows: [unparseable('rgn_top_level_not_walked')],
44+
packages: [{ manifest: { id: 'com.example.a', flows: [] } }, { manifest: { id: 'com.example.b', flows: [unparseable('rgn_broken')] } }],
45+
});
46+
expect(located(rows)).toEqual([{ path: 'packages[1].manifest.flows[0]', code: 'VALIDATION_ERROR', flow: 'rgn_broken' }]);
47+
});
48+
});

‎packages/cli/src/utils/flow-region-shape.ts‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@
1919
*
2020
* Walked the way `findExtensionFieldSuffixRefusals` (`./extension-field-suffix.ts`)
2121
* walks: each `packages[]` entry's flows, or the stack's own flows when it
22-
* declares no packages. A flow the schema refuses is left to the schema step,
23-
* which has already reported it.
22+
* declares no packages.
23+
*
24+
* A flow `FlowSchema` refuses HERE is a row, never a skip (#29059). The stack
25+
* schema has already parsed every flow this walk reads, and `FlowSchema` is
26+
* idempotent on its own output today, so the branch cannot be reached by an
27+
* author. If that ever stops being true the region verdict was never computed,
28+
* and a silent `return` would pass the flow: the false-clean direction this
29+
* gate exists to close. The row says the flow could not be judged, with the
30+
* schema's issues, and the door refuses on it like any other row.
2431
*
2532
* Not judged here: a cycle in the flow's TOP-LEVEL graph. The engine refuses it
2633
* with `detectCycles`, which lives in `@objectstack/service-automation` and is
@@ -37,9 +44,12 @@ export interface FlowRegionRefusalRow {
3744
path: string;
3845
/** The code the CLI's other author-time refusals carry. */
3946
code: 'VALIDATION_ERROR';
40-
/** The flow's name. */
47+
/** The flow's name; its `path` when the body carries no string name. */
4148
flow: string;
42-
/** `Flow '<name>' …: ` followed by the engine's refusal, verbatim. */
49+
/**
50+
* `Flow '<name>' …: ` followed by the engine's refusal, verbatim — or, when
51+
* `FlowSchema` refuses the parsed body, the schema's issues (#29059).
52+
*/
4353
message: string;
4454
}
4555

@@ -54,7 +64,20 @@ export function findFlowRegionRefusals(parsed: Record<string, unknown>): FlowReg
5464
if (!Array.isArray(flows)) continue;
5565
flows.forEach((raw, i) => {
5666
const result = FlowSchema.safeParse(raw);
57-
if (!result.success) return;
67+
if (!result.success) {
68+
const declared = (raw as { name?: unknown } | null)?.name;
69+
const name = typeof declared === 'string' && declared !== '' ? declared : `${at}flows[${i}]`;
70+
const issues = result.error.issues
71+
.map((issue) => `${issue.path.length > 0 ? issue.path.join('.') : '(root)'}: ${issue.message}`)
72+
.join('; ');
73+
rows.push({
74+
path: `${at}flows[${i}]`,
75+
code: 'VALIDATION_ERROR',
76+
flow: name,
77+
message: `Flow '${name}' could not be judged for its region shape: the flow schema refused the parsed body (${issues})`,
78+
});
79+
return;
80+
}
5881
try {
5982
validateControlFlow(result.data);
6083
} catch (err) {

‎packages/cli/src/utils/format.boot-warning-classes.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ const policyRefused = (names: string[], triggerType = 'schedule'): AutomationRea
238238
const summary = (over: Partial<AutomationReadySummary>): AutomationReadySummary => ({
239239
enabled: true,
240240
declaredFlowCount: 0,
241+
refusedCount: 0,
241242
flowCount: 10,
242243
boundCount: 0,
243244
triggerTypes: ['schedule', 'record_change'],

‎packages/cli/src/utils/format.flow-contender-agreement.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ const base: ServerReadyOptions = {
7777
const summaryWith = (armed: Contender, shadowedCount = 1): AutomationReadySummary => ({
7878
enabled: true,
7979
declaredFlowCount: 1,
80+
refusedCount: 0,
8081
flowCount: 1,
8182
boundCount: 1,
8283
triggerTypes: ['record_change'],

‎packages/cli/src/utils/format.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,15 @@ export interface AutomationReadySummary {
10111011
enabled: boolean;
10121012
/** Flows declared in the stack config (used when the engine is absent). */
10131013
declaredFlowCount: number;
1014+
/**
1015+
* [#29059] Declared flows the engine REFUSED at registration, from its own
1016+
* record (`getFlowRegistration(name).state === 'refused'`), counted by
1017+
* distinct declared name. A refused flow is absent from `flowCount` and from
1018+
* every list below, so without this the banner counts only what armed and
1019+
* the refusal shows only as a per-flow line under Boot diagnostics.
1020+
* 0 when the engine is absent or does not answer the read.
1021+
*/
1022+
refusedCount: number;
10141023
/** Flows registered in the engine (0 when `enabled` is false). */
10151024
flowCount: number;
10161025
/** Flows bound to a trigger. */
@@ -1713,6 +1722,18 @@ function printAutomationSummary(a: AutomationReadySummary): string[] {
17131722
}
17141723
return restated;
17151724
}
1725+
// [#29059] Printed BEFORE the `flowCount === 0` return: a boot whose every
1726+
// declared flow was refused registers none, and would otherwise print no
1727+
// Flows line at all. Boot continued either way; this only says so. The
1728+
// engine's per-flow reason stays where it is, under Boot diagnostics.
1729+
if (a.refusedCount > 0) {
1730+
console.error(
1731+
chalk.yellow(
1732+
` ⚠ Flows: ${a.declaredFlowCount} flow(s) declared, ${a.refusedCount} refused at registration — ` +
1733+
`refused flows never run; each one's reason is under Boot diagnostics ('failed to register flow')`,
1734+
),
1735+
);
1736+
}
17161737
if (a.flowCount === 0) return restated;
17171738

17181739
const parts = [`${a.flowCount} flow(s)`, `${a.boundCount} bound to triggers`];

0 commit comments

Comments
 (0)