@@ -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