@@ -59,6 +59,7 @@ import { withDisabledExtensionsFolded } from './metadata-diagnostics.js';
5959import { unresolvedConnectorSteps , type ProbeAutomation } from './build-probes.js' ;
6060import type { PackagedRuleCopyRefusal , RuntimeAuthoringIssue , RuntimeAuthoringVerdict , RuntimePendingDeclarations } from './runtime-authoring-gate.js' ;
6161import { savedItemNameRefusal } from '@objectstack/metadata/view-container-name' ;
62+ import { isMissingTableError } from '@objectstack/metadata/errors' ;
6263import { PLURAL_TO_SINGULAR , SINGULAR_TO_PLURAL } from '@objectstack/spec/shared' ;
6364import type { IObjectQLEngine } from '@objectstack/spec/contracts' ;
6465import type { StoredObjectExtension } from '@objectstack/lint/runtime' ;
@@ -110,6 +111,18 @@ export interface AuthoringGateHost {
110111 formRestoreRefusal : ( type : string , item : unknown , name : string , binding : string | null ) => Promise < Error | undefined > ;
111112 /** [#34776] The automation engine's sealed node-type vocabulary ({@link sealedFlowNodeTypeVocabulary}). */
112113 sealedFlowNodeTypeVocabulary : ( ) => readonly string [ ] | undefined ;
114+ /**
115+ * The names of every flow the automation engine holds
116+ * ({@link automationFlowNames}). Optional: a host that does not state it
117+ * gets no `subflow` / `map` target judgement at the publish gate.
118+ */
119+ automationFlowNames ?: ( ) => Promise < readonly string [ ] | undefined > ;
120+ /**
121+ * The environment's `sys_metadata` rows, read as the stored-collection
122+ * fold reads them. Optional for the same reason; read by
123+ * {@link deploymentFlowNamesOf} for the stored flows of every state.
124+ */
125+ findEnvironmentRows ?: ObjectStackProtocolImplementation [ 'findEnvironmentRows' ] ;
113126}
114127
115128/** The body of `ObjectStackProtocolImplementation#restoredBodyDerivation`; the method's docblock there is its contract. */
@@ -341,7 +354,7 @@ export function withTargetFoldedWithout(
341354 * The members {@link judgeRuntimeAuthoringRules} reads: the host facts and
342355 * collections every judgement of the shared rules is made against.
343356 */
344- type RuntimeRulesHost = Pick < AuthoringGateHost , 'authoringChannel' | 'engine' | 'foldStoredCollection' | 'hierarchyResolverMounted' | 'orgWallEnforced' | 'resolveSduiManifest' | 'resolveWritePackageScope' | 'rlsMembershipResolverKeys' | 'sealedFlowNodeTypeVocabulary' | 'tenancyPostureInForce' > ;
357+ type RuntimeRulesHost = Pick < AuthoringGateHost , 'authoringChannel' | 'automationFlowNames' | ' engine' | 'findEnvironmentRows ' | 'foldStoredCollection' | 'hierarchyResolverMounted' | 'orgWallEnforced' | 'resolveSduiManifest' | 'resolveWritePackageScope' | 'rlsMembershipResolverKeys' | 'sealedFlowNodeTypeVocabulary' | 'tenancyPostureInForce' > ;
345358
346359/** The body of `ObjectStackProtocolImplementation#assertRuntimeAuthoringRules`; the method's docblock there is its contract. */
347360export async function assertRuntimeAuthoringRules (
@@ -634,6 +647,14 @@ export async function judgeRuntimeAuthoringRules(
634647 // flow write only, and passed in so the gate stays pure.
635648 const flowNodeTypeVocabulary = singular === 'flow' ? this . sealedFlowNodeTypeVocabulary ( ) : undefined ;
636649
650+ // [#35143] Every flow the deployment holds, by name, on a flow write only:
651+ // the universe a `subflow` / `map` call is judged against, since the gate's
652+ // own snapshot holds just the written flow. `undefined` when one source
653+ // could not be read, and then no call is judged.
654+ const deploymentFlowNames = singular === 'flow'
655+ ? await deploymentFlowNamesOf . call ( this , listRegisteredCollection ( 'flow' , 'flows' ) )
656+ : undefined ;
657+
637658 // [#26188] Is a hierarchy resolver mounted — a host fact of the same kind,
638659 // read here per publish and passed in so the gate stays pure.
639660 const hierarchyResolverMounted = this . hierarchyResolverMounted ( ) ;
@@ -685,6 +706,8 @@ export async function judgeRuntimeAuthoringRules(
685706 ...( rlsMembershipResolverKeys !== undefined ? { rlsMembershipResolverKeys } : { } ) ,
686707 // With it the gate refuses a flow node no executor of this deployment runs.
687708 ...( flowNodeTypeVocabulary !== undefined ? { flowNodeTypeVocabulary } : { } ) ,
709+ // [#35143] With it the gate refuses a subflow / map call to a flow the deployment does not hold.
710+ ...( deploymentFlowNames !== undefined ? { deploymentFlowNames } : { } ) ,
688711 // [#26188] With it the gate refuses a hierarchy scope no resolver enforces.
689712 ...( hierarchyResolverMounted !== undefined ? { hierarchyResolverMounted } : { } ) ,
690713 // [#28448] With it the gate refuses a rule copy that changes what the package owns.
@@ -695,6 +718,59 @@ export async function judgeRuntimeAuthoringRules(
695718 return verdict ;
696719}
697720
721+ /**
722+ * [#35143] The names of every flow this deployment holds, the universe the
723+ * publish gate judges a `subflow` / `map` node's `config.flowName` against
724+ * (`validateFlowSubflowTargets`): the registry's flows (`registered`, every
725+ * installed package's, a disabled package's included), the stored flow rows
726+ * of EVERY state (a draft counts, so two new flows that call each other can be
727+ * published one at a time), and every flow the automation engine holds (a flow
728+ * registered straight into the engine has no metadata row). The batch's own
729+ * flow drafts are added by the gate ({@link evaluateRuntimeAuthoringGate}).
730+ *
731+ * Union only: every source can only make more names resolvable, never fewer.
732+ * `undefined`, and so no judgement, when the host cannot state one of the
733+ * sources: no stored-row reader or engine reader, or a read that fails (said
734+ * once, at `warn`). Judging against a partial universe would refuse a call to
735+ * a flow the missing source holds.
736+ */
737+ async function deploymentFlowNamesOf (
738+ this : Pick < AuthoringGateHost , 'automationFlowNames' | 'findEnvironmentRows' > ,
739+ registered : readonly unknown [ ] ,
740+ ) : Promise < readonly string [ ] | undefined > {
741+ if ( typeof this . findEnvironmentRows !== 'function' || typeof this . automationFlowNames !== 'function' ) return undefined ;
742+ const engineNames = await this . automationFlowNames ( ) ;
743+ if ( engineNames === undefined ) return undefined ;
744+ const names = new Set < string > ( engineNames ) ;
745+ for ( const item of registered ) {
746+ const name = ( item as { name ?: unknown } | null ) ?. name ;
747+ if ( typeof name === 'string' && name !== '' ) names . add ( name ) ;
748+ }
749+ try {
750+ for ( const type of [ 'flow' , 'flows' ] ) {
751+ // [ADR-0131 D6] The environment's rows, every state, as the
752+ // stored-collection fold reads them (that fold reads `active` only).
753+ const rows = await this . findEnvironmentRows ( 'sys_metadata' , {
754+ where : { type } ,
755+ context : { isSystem : true } ,
756+ } ) ;
757+ for ( const row of ( rows ?? [ ] ) as Array < { name ?: unknown } > ) {
758+ if ( typeof row ?. name === 'string' && row . name !== '' ) names . add ( row . name ) ;
759+ }
760+ }
761+ } catch ( error ) {
762+ if ( ! isMissingTableError ( error , 'sys_metadata' ) ) {
763+ console . warn (
764+ `[Protocol] the runtime authoring gate could not read the stored flows: `
765+ + `${ ( error as { message ?: string } | null ) ?. message ?? String ( error ) } . `
766+ + `This write is NOT blocked; a subflow or map step's called flow is not judged for it.` ,
767+ ) ;
768+ return undefined ;
769+ }
770+ }
771+ return [ ...names ] ;
772+ }
773+
698774/**
699775 * [#32666] The flows of the package an object write belongs to — the subjects
700776 * the object write is judged against (`RuntimeStackContext.flows`).
@@ -982,6 +1058,37 @@ function draftConnectorAdvisories(
9821058 * a type, so "no executor" is not a verdict anyone may act on (AGENTS.md
9831059 * "Startup registry reads").
9841060 */
1061+ /**
1062+ * [#35143] The names of every flow the automation engine holds
1063+ * (`IAutomationService.listFlows`), read per publish and recorded nowhere.
1064+ * `undefined` when no automation service is registered (no flow runs here at
1065+ * all) or its read fails; then no `subflow` / `map` call is judged.
1066+ */
1067+ export async function automationFlowNames (
1068+ this : { readonly getServicesRegistry ?: ( ) => Map < string , any > } ,
1069+ ) : Promise < readonly string [ ] | undefined > {
1070+ let automation : unknown ;
1071+ try {
1072+ automation = this . getServicesRegistry ?.( ) . get ( 'automation' ) ;
1073+ } catch {
1074+ return undefined ;
1075+ }
1076+ const list = ( automation as { listFlows ?: ( ) => unknown } | undefined ) ?. listFlows ;
1077+ if ( typeof list !== 'function' ) return undefined ;
1078+ let names : unknown ;
1079+ try {
1080+ names = await list . call ( automation ) ;
1081+ } catch ( error ) {
1082+ console . warn (
1083+ `[Protocol] the runtime authoring gate could not list the automation engine's flows: `
1084+ + `${ ( error as { message ?: string } | null ) ?. message ?? String ( error ) } . `
1085+ + `This write is NOT blocked; a subflow or map step's called flow is not judged for it.` ,
1086+ ) ;
1087+ return undefined ;
1088+ }
1089+ return Array . isArray ( names ) ? names . filter ( ( n ) : n is string => typeof n === 'string' ) : undefined ;
1090+ }
1091+
9851092export function sealedFlowNodeTypeVocabulary (
9861093 this : { readonly getServicesRegistry ?: ( ) => Map < string , any > } ,
9871094) : readonly string [ ] | undefined {
0 commit comments