1919 * - a create, or a rename, into a name the metadata door refuses answers the
2020 * door's own refusal and keeps nothing (seat re-rule Q1 = A); an edit of a
2121 * row that already carries such a name still lands as a row write;
22- * - a name a package or a built-in holds stands the write-through down: the
23- * write is passed on and nothing reaches metadata (Q2 = A), pinned at the
24- * write-through's own level rather than at the data door's answer;
22+ * - an edit that keeps a name a package or a built-in holds, and a delete of
23+ * such a row, stand the write-through down: the write is passed on and
24+ * nothing reaches metadata (Q2 = A), pinned at the write-through's own level
25+ * rather than at the data door's answer;
26+ * - a create, or a rename into, a name a package or a built-in holds answers
27+ * the metadata door's own locked-base refusal and keeps nothing (C2 stage
28+ * S10, ADR-0048 addendum N.2/N.3); the engine's own refusals keep theirs;
2529 * - a package registering a name a Setup position holds in the environment
2630 * ledger is refused `NAMESPACE_CONFLICT` (Q3 = A, within Q4 = A);
2731 * - controls: a walled posture, a system write and a kernel without a metadata
@@ -393,17 +397,21 @@ describe('[ADR-0131 D3] Q1 = A — a name the metadata door refuses is refused w
393397 } ) ;
394398} ) ;
395399
396- describe ( '[ADR-0131 D3] Q2 = A — a name a package or a built-in holds stands the write-through down' , ( ) => {
400+ describe ( '[ADR-0131 D3] Q2 = A — an edit that keeps, or a delete of, a name a package or a built-in holds stands the write-through down' , ( ) => {
397401 // Pinned at the write-through's own level, never at the data door's answer:
398402 // whether the data door admits an edit of a package-declared row is the
399403 // system-row gate's call, decided on the row's provenance stamp, and that
400404 // stamp is another change's. The write-through must stand down whatever the
401405 // stamp says, because it reads the name's holder from the engine registry.
402- it ( 'the write-through passes a write on a package-held or built-in name to the next step, and writes nothing to metadata' , async ( ) => {
406+ // A CREATE under such a name is no stand-down since stage S10 (below).
407+ it ( 'the write-through passes an edit or a delete on a package-held name to the next step, and writes nothing to metadata' , async ( ) => {
403408 const b = await boot ( ) ;
404409 const door = {
405410 saveMetaItem : vi . fn ( async ( _request : Record < string , unknown > ) => undefined ) ,
406411 deleteMetaItem : vi . fn ( async ( _request : Record < string , unknown > ) => undefined ) ,
412+ // The real door's verdict, so the S10 refusal is in force for this double too.
413+ packagedBaseRefusal : vi . fn ( ( request : { type : string ; name : string ; operation : 'save' | 'delete' } ) =>
414+ b . protocol . packagedBaseRefusal ( request ) as Error | null ) ,
407415 } ;
408416 const writeThrough = createPositionWriteThrough ( {
409417 ql : b . engine , getProtocol : ( ) => door , getPosture : ( ) => 'single' , logger : b . logger ,
@@ -418,9 +426,6 @@ describe('[ADR-0131 D3] Q2 = A — a name a package or a built-in holds stands t
418426 const edit = { object : 'sys_position' , operation : 'update' , data : { id : 'pos_pkg' , label : 'Edited' , delegatable : true } , context : b . admin } ;
419427 expect ( await passOn ( edit , ( ) => b . engine . update ( 'sys_position' , { id : 'pos_pkg' , label : 'Edited' , delegatable : true } , { context : SYS } as any ) ) )
420428 . toBe ( 1 ) ;
421- // A create under a built-in name (the plugin registers the six under its own package).
422- const builtIn = { object : 'sys_position' , operation : 'insert' , data : { name : 'everyone' , label : 'Everyone' } , context : b . admin } ;
423- expect ( await passOn ( builtIn , async ( ) => ( { id : 'pos_builtin' , name : 'everyone' } ) ) ) . toBe ( 1 ) ;
424429 // A delete of the package-declared row.
425430 const del = { object : 'sys_position' , operation : 'delete' , options : { where : { id : 'pos_pkg' } } , context : b . admin } ;
426431 expect ( await passOn ( del , ( ) => b . engine . delete ( 'sys_position' , { where : { id : 'pos_pkg' } , context : SYS } as any ) ) ) . toBe ( 1 ) ;
@@ -446,6 +451,97 @@ describe('[ADR-0131 D3] Q2 = A — a name a package or a built-in holds stands t
446451 } ) ;
447452} ) ;
448453
454+ describe ( '[C2 stage S10, ADR-0048 addendum N.2/N.3] one namespace — a create or a rename into a held name answers the door\'s refusal' , ( ) => {
455+ /** The metadata door's own envelope for an environment save over a name a package or a built-in holds. */
456+ const DOOR_REFUSAL = { code : 'NOT_OVERRIDABLE' , status : 403 } ;
457+
458+ it . each ( [
459+ [ 'a package declares' , PKG_POSITION ] ,
460+ [ 'the platform declares as an audience anchor' , 'everyone' ] ,
461+ [ 'the platform declares as an audience anchor (guest)' , 'guest' ] ,
462+ ] ) ( 'a create under a name %s is refused with the door\'s envelope, and keeps no row and no definition' , async ( _holder , name ) => {
463+ const b = await boot ( ) ;
464+ const before = ( await b . rows ( name ) ) . map ( ( r ) => r . id ) ;
465+ const refusal = await refusalOf ( create ( b , { name, label : 'Mine' } ) ) ;
466+ expect ( envelope ( refusal ) ) . toEqual ( DOOR_REFUSAL ) ;
467+ expect ( ( await b . rows ( name ) ) . map ( ( r ) => r . id ) , 'the created row was undone' ) . toEqual ( before ) ;
468+ expect ( await b . envRows ( name ) ) . toEqual ( [ ] ) ;
469+ } ) ;
470+
471+ it ( 'the refusal is the door\'s own, relayed as the door built it — the same verdict a metadata save gets' , async ( ) => {
472+ const b = await boot ( ) ;
473+ const refusal : any = await refusalOf ( create ( b , { name : PKG_POSITION , label : 'Mine' } ) ) ;
474+ const door : any = await refusalOf (
475+ b . protocol . saveMetaItem ( { type : 'position' , name : PKG_POSITION , item : { name : PKG_POSITION , label : 'Mine' } } ) ,
476+ ) ;
477+ expect ( { code : refusal ?. code , status : refusal ?. status , message : refusal ?. message } )
478+ . toEqual ( { code : door ?. code , status : door ?. status , message : door ?. message } ) ;
479+ } ) ;
480+
481+ it ( 'a bulk create carrying one held name is refused whole: no row of the write is kept' , async ( ) => {
482+ const b = await boot ( ) ;
483+ const refusal = await refusalOf ( b . engine . insert ( 'sys_position' , [
484+ { name : 'bulk_lead' , label : 'Bulk lead' } ,
485+ { name : PKG_POSITION , label : 'Mine' } ,
486+ ] , { context : b . admin } as any ) ) ;
487+ expect ( envelope ( refusal ) ) . toEqual ( DOOR_REFUSAL ) ;
488+ expect ( await b . rows ( 'bulk_lead' ) ) . toEqual ( [ ] ) ;
489+ expect ( await b . envRows ( 'bulk_lead' ) ) . toEqual ( [ ] ) ;
490+ expect ( ( await b . rows ( PKG_POSITION ) ) . map ( ( r ) => r . id ) ) . toEqual ( [ 'pos_pkg' ] ) ;
491+ } ) ;
492+
493+ it . each ( [
494+ [ 'a package declares' , PKG_POSITION ] ,
495+ [ 'the platform declares' , 'guest' ] ,
496+ ] ) ( 'a rename into a name %s is refused; the row and its definition keep the old name' , async ( _holder , held ) => {
497+ const b = await boot ( ) ;
498+ const created : any = await create ( b , { name : 'route_lead' , label : 'Route lead' } ) ;
499+ const refusal = await refusalOf ( patch ( b , created . id , { name : held , label : 'Renamed' } ) ) ;
500+ expect ( envelope ( refusal ) ) . toEqual ( DOOR_REFUSAL ) ;
501+ const [ row ] = await b . rows ( 'route_lead' ) ;
502+ expect ( { id : row ?. id , label : row ?. label } ) . toEqual ( { id : created . id , label : 'Route lead' } ) ;
503+ expect ( ( await b . rows ( held ) ) . map ( ( r ) => r . id ) ) . not . toContain ( created . id ) ;
504+ // Before S10 the rename stood down for the new name and then deleted the old name's definition.
505+ expect ( ( await b . envRows ( 'route_lead' ) ) . map ( ( r ) => r . body ) ) . toEqual ( [
506+ { name : 'route_lead' , label : 'Route lead' , delegatable : false } ,
507+ ] ) ;
508+ expect ( await b . envRows ( held ) ) . toEqual ( [ ] ) ;
509+ } ) ;
510+
511+ it ( 'control: the engine\'s own refusals keep their answer — a reserved identity name stays 400 VALIDATION_FAILED' , async ( ) => {
512+ const b = await boot ( ) ;
513+ const refusal = await refusalOf ( create ( b , { name : 'org_admin' , label : 'Mine' } ) ) ;
514+ expect ( envelope ( refusal ) ) . toEqual ( { code : 'VALIDATION_FAILED' , status : 400 } ) ;
515+ } ) ;
516+
517+ it ( 'control: an edit that keeps a held name stays a row write, with no definition and no refusal' , async ( ) => {
518+ const b = await boot ( ) ;
519+ // A row that predates this stage: an organization's own row under the package's name.
520+ await b . engine . insert ( 'sys_position' , {
521+ id : 'pos_twin' , name : PKG_POSITION , label : 'Twin' , organization_id : ORG ,
522+ } , { context : SYS } as any ) ;
523+ await patch ( b , 'pos_twin' , { label : 'Twin (relabelled)' } ) ;
524+ expect ( ( await b . rows ( PKG_POSITION ) ) . find ( ( r ) => r . id === 'pos_twin' ) ?. label ) . toBe ( 'Twin (relabelled)' ) ;
525+ expect ( await b . envRows ( PKG_POSITION ) ) . toEqual ( [ ] ) ;
526+ } ) ;
527+
528+ it ( 'control: a door that brings no locked-base verdict keeps the stand-down' , async ( ) => {
529+ const b = await boot ( ) ;
530+ const door = {
531+ saveMetaItem : vi . fn ( async ( _request : Record < string , unknown > ) => undefined ) ,
532+ deleteMetaItem : vi . fn ( async ( _request : Record < string , unknown > ) => undefined ) ,
533+ } ;
534+ const writeThrough = createPositionWriteThrough ( {
535+ ql : b . engine , getProtocol : ( ) => door , getPosture : ( ) => 'single' , logger : b . logger ,
536+ } ) ;
537+ const opCtx : any = { object : 'sys_position' , operation : 'insert' , data : { name : 'everyone' , label : 'Everyone' } , context : b . admin } ;
538+ const next = vi . fn ( async ( ) => { opCtx . result = { id : 'pos_builtin' , name : 'everyone' } ; } ) ;
539+ await writeThrough ( opCtx , next ) ;
540+ expect ( next ) . toHaveBeenCalledTimes ( 1 ) ;
541+ expect ( door . saveMetaItem ) . not . toHaveBeenCalled ( ) ;
542+ } ) ;
543+ } ) ;
544+
449545describe ( '[ADR-0131 D3] Q3 = A — a package cannot register a name a Setup position holds in the environment ledger' , ( ) => {
450546 it ( 'the registry item seam refuses it 422 NAMESPACE_CONFLICT, naming both holders' , async ( ) => {
451547 const b = await boot ( ) ;
0 commit comments