Skip to content

Commit eca6aa5

Browse files
committed
test: pin the subflow target refusal at the publish door
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q4EjjQkY5yXZrN9BEA3rEK
1 parent e569126 commit eca6aa5

2 files changed

Lines changed: 133 additions & 4 deletions

File tree

‎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/metadata-protocol/src/protocol.runtime-authoring-gate.test.ts‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import {
5555
HIERARCHY_SCOPE_CAPABILITY_REQUIRED,
5656
HIERARCHY_SCOPE_RESOLVER_SERVICE,
5757
PUBLIC_FORM_INTAKE_UNAVAILABLE,
58+
evaluateRuntimeAuthoringGate,
5859
stampHtmlPageRequires,
5960
} from './runtime-authoring-gate.js';
6061

@@ -5755,3 +5756,83 @@ describe('ai_context author defects at save (ADR-0160 D1)', () => {
57555756
expect((active.advisories ?? []).map((a: any) => a.rule)).toEqual(['ai-context-field-unknown']);
57565757
});
57575758
});
5759+
5760+
// [#35143] A `subflow` / `map` call to a flow the deployment does not hold is
5761+
// refused at the publish door, judged against every flow the deployment holds:
5762+
// the registry's, the stored rows in every state, the automation engine's, and
5763+
// the batch's own drafts. No source readable, no judgement.
5764+
describe('runtime authoring gate on a subflow call to an unknown flow (#35143)', () => {
5765+
let warn: ReturnType<typeof vi.spyOn>;
5766+
beforeEach(() => {
5767+
warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
5768+
});
5769+
afterEach(() => warn.mockRestore());
5770+
5771+
const calling = (name: string, flowName: string) => ({
5772+
name,
5773+
label: name,
5774+
type: 'autolaunched',
5775+
status: 'active',
5776+
nodes: [
5777+
{ id: 'start', type: 'start', label: 'Start' },
5778+
{ id: 'call', type: 'subflow', label: 'Call', config: { flowName } },
5779+
],
5780+
edges: [{ id: 'e1', source: 'start', target: 'call' }],
5781+
});
5782+
5783+
/** A protocol whose automation engine holds `engineFlows`, and whose registry lists `registryFlows`. */
5784+
const protocolWith = (engineFlows: readonly string[] | undefined, registryFlows: readonly string[] = []) => {
5785+
const { engine, rows } = makeStubEngine();
5786+
const objectsOf = engine.registry.listItems;
5787+
engine.registry.listItems = (type: string) =>
5788+
type === 'flow' ? registryFlows.map((name) => ({ name })) : objectsOf(type);
5789+
const services = new Map<string, unknown>();
5790+
if (engineFlows !== undefined) services.set('automation', { listFlows: async () => [...engineFlows] });
5791+
const protocol = new ObjectStackProtocolImplementation(engine, () => services as Map<string, any>, 'env_test');
5792+
return { protocol: protocol as any, rows };
5793+
};
5794+
const publish = (protocol: any, item: { name: string }) =>
5795+
protocol.saveMetaItem({ type: 'flow', name: item.name, item });
5796+
5797+
it('refuses an active save calling a flow nothing in the deployment holds', async () => {
5798+
const { protocol, rows } = protocolWith(['child'], ['packaged_child']);
5799+
const err = await publish(protocol, calling('parent', 'missing_child')).catch((e: any) => e);
5800+
expect(err).toBeInstanceOf(Error);
5801+
expect(err.status).toBe(422);
5802+
expect(err.code).toBe('INVALID_METADATA');
5803+
const issue = err.issues.find((i: any) => i.rule === 'flow-subflow-unknown');
5804+
expect(issue, `issues: ${JSON.stringify(err.issues)}`).toBeDefined();
5805+
expect(issue.path).toBe('flows[0].nodes[1].config.flowName');
5806+
expect(err.rulesRun).toContain('validateFlowSubflowTargets');
5807+
expect(flowRows(rows)).toEqual([]);
5808+
});
5809+
5810+
it("lets a call through to the engine's flow, an installed package's flow, or a stored draft", async () => {
5811+
const { protocol } = protocolWith(['engine_child'], ['packaged_child']);
5812+
expect((await publish(protocol, calling('a', 'engine_child'))).success).toBe(true);
5813+
expect((await publish(protocol, calling('b', 'packaged_child'))).success).toBe(true);
5814+
await protocol.saveMetaItem({ type: 'flow', name: 'draft_child', item: calling('draft_child', 'a'), mode: 'draft' });
5815+
expect((await publish(protocol, calling('c', 'draft_child'))).success).toBe(true);
5816+
// …and a flow published earlier is a stored active row.
5817+
expect((await publish(protocol, calling('d', 'a'))).success).toBe(true);
5818+
});
5819+
5820+
it('judges nothing when no automation service states its flows', async () => {
5821+
const { protocol } = protocolWith(undefined, ['packaged_child']);
5822+
expect((await publish(protocol, calling('parent', 'missing_child'))).success).toBe(true);
5823+
});
5824+
5825+
it('a flow the same batch publishes resolves; without it the call is refused', () => {
5826+
const body = calling('parent', 'batch_child');
5827+
const judge = (pending?: { flows: unknown[] }) => evaluateRuntimeAuthoringGate({
5828+
type: 'flow',
5829+
name: 'parent',
5830+
state: 'active',
5831+
body,
5832+
deploymentFlowNames: ['other'],
5833+
...(pending !== undefined ? { pending: pending as never } : {}),
5834+
});
5835+
expect(((judge().error as any)?.issues ?? []).map((i: { rule: string }) => i.rule)).toContain('flow-subflow-unknown');
5836+
expect(judge({ flows: [{ name: 'batch_child' }] }).error).toBeNull();
5837+
});
5838+
});

0 commit comments

Comments
 (0)