@@ -32,7 +32,7 @@ import { HttpDispatcher } from './http-dispatcher.js';
3232import { executeEndpointTarget , type EndpointExecutionContext } from './endpoint-executor.js' ;
3333import { endpointPackageOf , flowHolderForCaller , flowServiceForCaller , flowSlotView , flowWalkReads } from './flow-slot-view.js' ;
3434import { SchemaRegistry , type PackageScopedRegistry } from '@objectstack/objectql' ;
35- import { admitAutomationAddress , bareNameRefusal } from './domains/automation-address.js' ;
35+ import { admitAutomationAddress , bareNameAdmission , bareNameRefusal } from './domains/automation-address.js' ;
3636
3737const CRM = 'com.crm.pkg' ;
3838const HR = 'com.hr.pkg' ;
@@ -418,22 +418,19 @@ describe('a start\'s record-read walk reads each callee from the calling flow\'s
418418} ) ;
419419
420420/**
421- * [#32183, ADR-0150 D3; epic ruling R4-G] The flow doors #31696 opened read
422- * every holder of a flow name, a disabled package's included, so a disable
423- * moves none of their answers: each answers as `main` does, where the
424- * registry's holder read did not yet leave a disabled package out.
425- *
426- * Read only through the served holders, a disable would move them. With CRM
427- * disabled, HR's own flow action would reach the bare service (the bare read
428- * no longer refuses), whose bare entries still refuse the name two engine
429- * slots hold; a package whose closure holds both would run HR's flow. Both
430- * moves wait for #32670, the served judgment at the send and run doors.
421+ * [ADR-0150 D3, #33386; seat ruling 6884403301] The flow doors #31696 opened
422+ * judge the SERVED holders of a name two packages hold: a disabled package
423+ * holds no name. Its slot stays armed and keyed in the engine (amendment 7),
424+ * so a disable never re-points a slot; it only moves which slot a door
425+ * reaches. Replaces the R4-G parity pin (`main` held these doors over every
426+ * holder, a disabled package's included).
431427 *
432428 * Over a real `SchemaRegistry` (its `disablePackage`, its served filter) and
433- * an engine double holding one slot per holder, as the engine holds them after
434- * a runtime disable. Pinned as parity: for every non-empty set of disabled
435- * holders, in both registration orders, every door answers what it answers
436- * with nothing disabled. The CONTROLs say what that answer is.
429+ * an engine double holding one slot per holder whose BARE entries judge the
430+ * served holders, as the engine's do after this change (service-automation
431+ * `engine.ts` `resolveFlowKey`, pinned there): one served holder runs that
432+ * slot, two refuse naming them, none is no flow. Every row of the PR's
433+ * Clause-② table for these doors is asserted per registration order.
437434 */
438435
439436/** Depends on both holders. */
@@ -465,13 +462,25 @@ function registryOf(order: readonly string[], disabled: readonly string[]): Sche
465462 return registry ;
466463}
467464
468- /** One slot per holder, the bare entries refusing the shared name, as the engine's do. */
469- function engineWithBothSlots ( ) {
470- const refusal = ( ) => Object . assign ( new Error ( `Flow '${ FLOW } ' is held by several packages` ) , { code : 'RESOURCE_CONFLICT' , status : 409 } ) ;
465+ /** One slot per holder; the bare entries judge the served holders, as the engine's do. */
466+ function engineWithBothSlots ( registry : SchemaRegistry ) {
467+ const served = ( ) => registry . packageScopedHoldersOf ( 'flow' , FLOW , null ) ;
468+ const refusal = ( holders : string [ ] ) => Object . assign ( new Error ( `Flow '${ FLOW } ' is held by ${ holders . join ( ' and ' ) } ` ) , {
469+ code : 'RESOURCE_CONFLICT' , status : 409 , refusal : { candidates : holders . map ( ( packageId ) => ( { kind : 'package' , packageId } ) ) } ,
470+ } ) ;
471+ const bareSlot = ( name : string ) : string | null => {
472+ if ( name !== FLOW ) return null ;
473+ const holders = served ( ) ;
474+ if ( holders . length > 1 ) throw refusal ( holders ) ;
475+ return holders [ 0 ] ?? null ;
476+ } ;
471477 return {
472478 handlerReady : true ,
473- getFlow : vi . fn ( async ( name : string ) => { if ( name === FLOW ) throw refusal ( ) ; return null ; } ) ,
474- execute : vi . fn ( async ( name : string ) => { if ( name === FLOW ) throw refusal ( ) ; return { success : true } ; } ) ,
479+ getFlow : vi . fn ( async ( name : string ) => { const pkg = bareSlot ( name ) ; return pkg ? { name, label : `${ pkg } flow` } : null ; } ) ,
480+ execute : vi . fn ( async ( name : string ) => {
481+ const pkg = bareSlot ( name ) ;
482+ return pkg ? { success : true , output : { ran : pkg } } : { success : false , error : `Flow '${ name } ' not found` } ;
483+ } ) ,
475484 flowSlotKey : vi . fn ( ( pkg : string | null , name : string ) => ( name === FLOW && pkg !== null && HOLDERS . includes ( pkg ) ? `${ pkg } /${ FLOW } ` : undefined ) ) ,
476485 getFlowSlot : vi . fn ( ( pkg : string | null , name : string ) => ( name === FLOW && pkg !== null && HOLDERS . includes ( pkg ) ? { name, label : `${ pkg } flow` } : null ) ) ,
477486 executeSlot : vi . fn ( async ( pkg : string | null ) => ( { success : true , output : { ran : pkg } } ) ) ,
@@ -482,35 +491,38 @@ function engineWithBothSlots() {
482491/** What a thrown refusal names, or its message. */
483492const refusalOf = ( err : any ) => [ 'refused' , err ?. refusal ?. candidates ?. map ( ( c : any ) => c . packageId ?? c . kind ) ?? String ( err ?. message ) ] ;
484493
494+ /** A run's answer: the slot it ran, or no flow. */
495+ const ranOf = ( result : any ) => ( result ?. success ? [ 'ran' , result . output . ran ] : [ 'no flow' ] ) ;
496+
485497/** Every door's answer, per caller and per namespace. */
486498async function answersOf ( registry : SchemaRegistry ) {
487499 const out : Record < string , unknown > = { } ;
488500 for ( const caller of CALLERS ) {
489- const engine = engineWithBothSlots ( ) ;
501+ const engine = engineWithBothSlots ( registry ) ;
490502 try {
491503 const service = flowServiceForCaller ( engine , registry , FLOW , caller ) ;
492- await service . execute ( FLOW ) ;
493- out [ `action ${ caller } ` ] = [ 'ran' , engine . executeSlot . mock . calls . map ( ( c ) => c [ 0 ] ) ] ;
504+ out [ `action ${ caller } ` ] = ranOf ( await service . execute ( FLOW ) ) ;
494505 } catch ( err ) {
495506 out [ `action ${ caller } ` ] = refusalOf ( err ) ;
496507 }
497508 out [ `holder ${ caller } ` ] = flowHolderForCaller ( registry , FLOW , caller ) ;
498- const walk = flowWalkReads ( engineWithBothSlots ( ) , async ( ) => registry ) ;
509+ const walk = flowWalkReads ( engineWithBothSlots ( registry ) , async ( ) => registry ) ;
499510 try {
500511 const callee = await walk . callee ( FLOW , caller ?? null ) ;
501- out [ `callee ${ caller } ` ] = [ 'read' , callee . packageId , ( callee . flow as { label ?: string } | null ) ?. label ] ;
512+ out [ `callee ${ caller } ` ] = callee . flow === null ? [ 'no flow' ] : [ 'read' , callee . packageId , ( callee . flow as { label ?: string } | null ) ?. label ] ;
502513 } catch ( err ) {
503514 out [ `callee ${ caller } ` ] = refusalOf ( err ) ;
504515 }
505516 }
506- out . root = await flowWalkReads ( engineWithBothSlots ( ) , async ( ) => registry ) . rootPackage ( FLOW ) ;
517+ out . root = await flowWalkReads ( engineWithBothSlots ( registry ) , async ( ) => registry ) . rootPackage ( FLOW ) ;
507518 out . endpoint = endpointPackageOf ( registry , API ) ;
508- out . bare = bareNameRefusal ( registry , 'flow' , FLOW ) ?. candidates . map ( ( c : any ) => c . packageId ?? c . kind ) ;
519+ out . durable = bareNameRefusal ( registry , 'flow' , FLOW ) ?. candidates . map ( ( c : any ) => c . packageId ?? c . kind ) ;
509520 const addressOf = ( admitted : ReturnType < typeof admitAutomationAddress > ) => {
510521 if ( admitted === undefined ) return 'bare path' ;
511522 if ( 'packageId' in admitted ) return [ 'slot' , admitted . packageId ] ;
512523 return [ admitted . status , 'refusal' in admitted ? admitted . refusal . candidates . map ( ( c : any ) => c . packageId ?? c . kind ) : undefined ] ;
513524 } ;
525+ out . bare = addressOf ( bareNameAdmission ( registry , 'flow' , FLOW ) ) ;
514526 for ( const namespace of NAMESPACES ) {
515527 out [ `address ${ namespace } ` ] = addressOf ( admitAutomationAddress ( registry , { kind : 'namespace' , namespace } , { type : 'flow' , name : FLOW } ) ) ;
516528 }
@@ -519,27 +531,101 @@ async function answersOf(registry: SchemaRegistry) {
519531}
520532
521533const ORDERS = [ HOLDERS , [ ...HOLDERS ] . reverse ( ) ] ;
522- const DISABLED_SETS = [ [ CRM ] , [ HR ] , [ CRM , HR ] ] ;
523534
524- describe ( 'the #31696 flow doors read every holder: a disable moves no answer (ADR-0150 D3, R4-G, #32183)' , ( ) => {
525- it . each ( ORDERS . flatMap ( ( order ) => DISABLED_SETS . map ( ( disabled ) => [ order . join ( ' then ' ) , disabled . join ( ' and ' ) , order , disabled ] as const ) ) ) (
526- 'registered %s, %s disabled: every door answers as with nothing disabled' ,
527- async ( _o , _d , order , disabled ) => {
528- expect ( await answersOf ( registryOf ( order , disabled ) ) ) . toEqual ( await answersOf ( registryOf ( order , [ ] ) ) ) ;
529- } ,
530- ) ;
531-
532- it . each ( ORDERS . map ( ( order ) => [ order . join ( ' then ' ) , order ] as const ) ) ( 'CONTROL — registered %s, nothing disabled: what `main` answers' , async ( _o , order ) => {
533- const answers = await answersOf ( registryOf ( order , [ ] ) ) ;
534- expect ( answers [ `action ${ HR } ` ] ) . toEqual ( [ 'ran' , [ HR ] ] ) ;
535- expect ( answers [ `action ${ OPS } ` ] ) . toEqual ( [ 'ran' , [ CRM ] ] ) ;
536- expect ( answers [ `action ${ BOTH } ` ] ) . toEqual ( [ 'refused' , [ ...order ] ] ) ;
537- expect ( answers [ 'action undefined' ] ) . toEqual ( [ 'refused' , `Flow '${ FLOW } ' is held by several packages` ] ) ;
538- expect ( answers [ `callee ${ HR } ` ] ) . toEqual ( [ 'read' , HR , `${ HR } flow` ] ) ;
539- expect ( answers [ `holder ${ BOTH } ` ] ) . toBeUndefined ( ) ;
540- expect ( answers . bare ) . toEqual ( [ ...order ] ) ;
541- expect ( answers . endpoint ) . toBeUndefined ( ) ;
542- expect ( answers [ 'address crm' ] ) . toEqual ( [ 'slot' , CRM ] ) ;
543- expect ( answers [ 'address hr' ] ) . toEqual ( [ 'slot' , HR ] ) ;
535+ /** The answers with `off` disabled and `on` the one served holder. */
536+ function oneServed ( off : string , on : string , order : readonly string [ ] ) {
537+ return {
538+ // the bare caller and the caller whose closure holds both: the served holder's slot (amendments 1, 5)
539+ 'action undefined' : [ 'ran' , on ] ,
540+ [ `action ${ BOTH } ` ] : [ 'ran' , on ] ,
541+ // caller-first (amendment 4): the disabled holder's own action gets no flow, never the closure holder's
542+ [ `action ${ off } ` ] : [ 'no flow' ] ,
543+ [ `action ${ on } ` ] : [ 'ran' , on ] ,
544+ // reached only through the disabled holder, or reaching neither: refused naming the served holder only (amendment 6)
545+ [ `action ${ OPS } ` ] : off === CRM ? [ 'refused' , [ on ] ] : [ 'ran' , CRM ] ,
546+ [ `action ${ NONE } ` ] : [ 'refused' , [ on ] ] ,
547+ 'holder undefined' : on ,
548+ [ `holder ${ BOTH } ` ] : on ,
549+ [ `holder ${ off } ` ] : undefined ,
550+ [ `holder ${ on } ` ] : on ,
551+ [ `holder ${ OPS } ` ] : off === CRM ? undefined : CRM ,
552+ [ `holder ${ NONE } ` ] : undefined ,
553+ // the walk reads the slot the run executes (amendment 8)
554+ 'callee undefined' : [ 'read' , on , `${ on } flow` ] ,
555+ [ `callee ${ BOTH } ` ] : [ 'read' , on , `${ on } flow` ] ,
556+ [ `callee ${ off } ` ] : [ 'no flow' ] ,
557+ [ `callee ${ on } ` ] : [ 'read' , on , `${ on } flow` ] ,
558+ [ `callee ${ OPS } ` ] : off === CRM ? [ 'refused' , [ on ] ] : [ 'read' , CRM , `${ CRM } flow` ] ,
559+ [ `callee ${ NONE } ` ] : [ 'refused' , [ on ] ] ,
560+ root : on ,
561+ // durable coordinates stay judged over every holder (amendment 7)
562+ endpoint : undefined ,
563+ durable : [ ...order ] ,
564+ bare : [ 'slot' , on ] ,
565+ // an address naming the disabled holder is never another package's flow (amendment 2)
566+ [ `address ${ off === CRM ? 'crm' : 'hr' } ` ] : [ 409 , [ on ] ] ,
567+ [ `address ${ on === CRM ? 'crm' : 'hr' } ` ] : [ 'slot' , on ] ,
568+ 'address ops' : [ 409 , [ on ] ] ,
569+ 'address none' : [ 409 , [ on ] ] ,
570+ 'address _env' : [ 409 , [ on ] ] ,
571+ } ;
572+ }
573+
574+ describe ( 'the #31696 flow doors judge the served holders (ADR-0150 D3, #33386)' , ( ) => {
575+ describe . each ( ORDERS . map ( ( order ) => [ order . join ( ' then ' ) , order ] as const ) ) ( 'registered %s' , ( _o , order ) => {
576+ it ( 'CONTROL — nothing disabled: what `main` answers' , async ( ) => {
577+ const answers = await answersOf ( registryOf ( order , [ ] ) ) ;
578+ expect ( answers [ `action ${ HR } ` ] ) . toEqual ( [ 'ran' , HR ] ) ;
579+ expect ( answers [ `action ${ OPS } ` ] ) . toEqual ( [ 'ran' , CRM ] ) ;
580+ expect ( answers [ `action ${ BOTH } ` ] ) . toEqual ( [ 'refused' , [ ...order ] ] ) ;
581+ expect ( answers [ 'action undefined' ] ) . toEqual ( [ 'refused' , [ ...order ] ] ) ;
582+ expect ( answers [ `action ${ NONE } ` ] ) . toEqual ( [ 'refused' , [ ...order ] ] ) ;
583+ expect ( answers [ `callee ${ HR } ` ] ) . toEqual ( [ 'read' , HR , `${ HR } flow` ] ) ;
584+ expect ( answers [ 'callee undefined' ] ) . toEqual ( [ 'refused' , [ ...order ] ] ) ;
585+ expect ( answers [ `holder ${ BOTH } ` ] ) . toBeUndefined ( ) ;
586+ expect ( answers . root ) . toBeNull ( ) ;
587+ expect ( answers . durable ) . toEqual ( [ ...order ] ) ;
588+ expect ( answers . bare ) . toEqual ( [ 409 , [ ...order ] ] ) ;
589+ expect ( answers . endpoint ) . toBeUndefined ( ) ;
590+ expect ( answers [ 'address crm' ] ) . toEqual ( [ 'slot' , CRM ] ) ;
591+ expect ( answers [ 'address hr' ] ) . toEqual ( [ 'slot' , HR ] ) ;
592+ expect ( answers [ 'address ops' ] ) . toEqual ( [ 409 , [ ...order ] ] ) ;
593+ expect ( answers [ 'address _env' ] ) . toEqual ( [ 409 , [ ...order ] ] ) ;
594+ } ) ;
595+
596+ it . each ( [ [ CRM , HR ] , [ HR , CRM ] ] ) ( '%s disabled: every door answers the one served holder\'s slot, or no flow, or a refusal naming it' , async ( off , on ) => {
597+ expect ( await answersOf ( registryOf ( order , [ off ] ) ) ) . toEqual ( oneServed ( off , on , order ) ) ;
598+ } ) ;
599+
600+ it ( 'both disabled: no door reaches a flow; the durable coordinates still name both' , async ( ) => {
601+ const answers = await answersOf ( registryOf ( order , [ CRM , HR ] ) ) ;
602+ for ( const caller of CALLERS ) {
603+ expect ( answers [ `action ${ caller } ` ] , `action ${ caller } ` ) . toEqual ( [ 'no flow' ] ) ;
604+ expect ( answers [ `holder ${ caller } ` ] , `holder ${ caller } ` ) . toBeUndefined ( ) ;
605+ expect ( answers [ `callee ${ caller } ` ] , `callee ${ caller } ` ) . toEqual ( [ 'no flow' ] ) ;
606+ }
607+ expect ( answers . root ) . toBeNull ( ) ;
608+ expect ( answers . durable ) . toEqual ( [ ...order ] ) ;
609+ expect ( answers . bare ) . toBe ( 'bare path' ) ;
610+ for ( const namespace of NAMESPACES ) expect ( answers [ `address ${ namespace } ` ] , namespace ) . toEqual ( [ 404 , undefined ] ) ;
611+ expect ( answers [ 'address _env' ] ) . toBe ( 'bare path' ) ;
612+ } ) ;
613+
614+ it ( 'CONTROL — one holder, disabled: judged as `main` judges it (not a name two packages hold)' , async ( ) => {
615+ const registry = registryOf ( [ CRM ] , [ CRM ] ) ;
616+ const engine = engineWithBothSlots ( registry ) ;
617+ expect ( flowServiceForCaller ( engine , registry , FLOW , CRM ) ) . toBe ( engine ) ;
618+ expect ( bareNameAdmission ( registry , 'flow' , FLOW ) ) . toBeUndefined ( ) ;
619+ expect ( addressOrNone ( admitAutomationAddress ( registry , { kind : 'namespace' , namespace : 'crm' } , { type : 'flow' , name : FLOW } ) ) ) . toBe ( 404 ) ;
620+ } ) ;
621+
622+ it ( 'CONTROL — no holder: no admission, no flow' , async ( ) => {
623+ const registry = new SchemaRegistry ( ) ;
624+ registry . logLevel = 'silent' ;
625+ expect ( bareNameAdmission ( registry , 'flow' , FLOW ) ) . toBeUndefined ( ) ;
626+ expect ( flowHolderForCaller ( registry , FLOW , undefined ) ) . toBeUndefined ( ) ;
627+ } ) ;
544628 } ) ;
545629} ) ;
630+
631+ const addressOrNone = ( admitted : ReturnType < typeof admitAutomationAddress > ) => ( admitted && 'status' in admitted ? admitted . status : admitted ) ;
0 commit comments