@@ -404,3 +404,94 @@ describe('[ADR-0146 D10] a module\'s extension that re-declares the base\'s fiel
404404 expect ( rig . extenders ( ) ) . toEqual ( [ MODULE ] ) ;
405405 } , 60_000 ) ;
406406} ) ;
407+
408+ /**
409+ * [ruling record 6691022506, ADR-0146 D3 as amended] The HotCRM rehearsal, on
410+ * an in-repo fixture of HotCRM's shape (the HotCRM repository is not part of
411+ * this tree): the App `app.objectstack.hotcrm` and three modules that declare
412+ * it, all `namespace: 'crm'`, all held as code. The ensure door is asked for
413+ * each — one `app.objectstack.hotcrm.custom` — and a MODULE's object is then
414+ * extended in that pair and read back on every object read.
415+ */
416+ describe ( '[#29594] the App unit: HotCRM and three modules share one pair, and a module object is customized in it' , ( ) => {
417+ const APP = 'app.objectstack.hotcrm' ;
418+ const APP_PAIR = `${ APP } .custom` ;
419+ const MODULES = [ 'service' , 'revenue' , 'marketing' ] as const ;
420+ const CASE = 'crm_service_case' ;
421+ const ADMIN_CTX : any = {
422+ request : { } ,
423+ environmentId : 'hotcrm-app-unit' ,
424+ executionContext : { userId : 'u_admin' , systemPermissions : [ 'manage_metadata' , 'studio.access' , 'setup.access' ] } ,
425+ } ;
426+
427+ async function hotcrm ( ) {
428+ const engine = new ObjectQL ( ) ;
429+ liveEngines . push ( engine ) ;
430+ engine . registerDriver ( new SqlDriver ( {
431+ client : 'better-sqlite3' ,
432+ connection : { filename : ':memory:' } ,
433+ useNullAsDefault : true ,
434+ } ) , true ) ;
435+ await engine . init ( ) ;
436+ engine . registry . registerObject ( SysMetadata as any , TEST_PACKAGE_ID ) ;
437+ engine . registry . registerObject ( SysMetadataHistoryObject as any , TEST_PACKAGE_ID ) ;
438+ engine . registry . registerObject ( SysMetadataAuditObject as any , TEST_PACKAGE_ID ) ;
439+ ( engine . registry as unknown as { logLevel : string } ) . logLevel = 'silent' ;
440+ engine . registerApp ( {
441+ id : APP , name : 'hotcrm' , version : '6.1.0' , type : 'app' , namespace : 'crm' ,
442+ objects : [ { name : 'crm_account' , label : 'Account' , fields : { name : { name : 'name' , label : 'Name' , type : 'text' } } } ] ,
443+ } ) ;
444+ for ( const m of MODULES ) {
445+ engine . registerApp ( {
446+ id : `${ APP } .${ m } ` , name : `hotcrm-${ m } ` , version : '6.1.0' , type : 'module' , namespace : 'crm' ,
447+ dependencies : { [ APP ] : '^6.1.0' } ,
448+ objects : [ { name : `crm_${ m } _case` , label : `${ m } case` , fields : { subject : { name : 'subject' , label : 'Subject' , type : 'text' } } } ] ,
449+ } ) ;
450+ }
451+ await engine . syncSchemas ( ) ;
452+ const protocol : any = new ObjectStackProtocolImplementation ( engine as any , ( ) => new Map ( ) ) ;
453+ const named : Record < string , unknown > = { protocol, objectql : engine } ;
454+ const get = ( name : string ) => named [ name ] ?? null ;
455+ const kernel : any = { context : { getService : get } , getService : get , getServiceAsync : async ( name : string ) => get ( name ) } ;
456+ const dispatcher = new HttpDispatcher ( kernel ) ;
457+ const ensure = ( id : string ) =>
458+ dispatcher . handlePackages ( `/${ encodeURIComponent ( id ) } /ensure-customization` , 'POST' , undefined , { } , ADMIN_CTX ) as Promise < any > ;
459+ return { engine, protocol, ensure } ;
460+ }
461+
462+ it ( 'ensure on the App and each module answers one app.objectstack.hotcrm.custom; a module object extended there reads back' , async ( ) => {
463+ const { engine, protocol, ensure } = await hotcrm ( ) ;
464+ const answers : Array < [ string , number , string ] > = [ ] ;
465+ for ( const id of [ APP , ...MODULES . map ( ( m ) => `${ APP } .${ m } ` ) ] ) {
466+ const r = await ensure ( id ) ;
467+ answers . push ( [ id , r . response . status , r . response . body ?. data ?. packageId ] ) ;
468+ }
469+ expect ( answers ) . toEqual ( [
470+ [ APP , 201 , APP_PAIR ] ,
471+ [ `${ APP } .service` , 200 , APP_PAIR ] ,
472+ [ `${ APP } .revenue` , 200 , APP_PAIR ] ,
473+ [ `${ APP } .marketing` , 200 , APP_PAIR ] ,
474+ ] ) ;
475+ const pairs = engine . registry . getAllPackages ( ) . map ( ( p : any ) => p . manifest ?. id ) . filter ( ( id : string ) => id . endsWith ( '.custom' ) ) ;
476+ expect ( pairs ) . toEqual ( [ APP_PAIR ] ) ;
477+
478+ // Customize a MODULE's object in the App's pair: Studio's add-field body.
479+ await protocol . saveMetaItem ( {
480+ type : TYPE , name : CASE , mode : 'draft' , packageId : APP_PAIR ,
481+ item : { extend : CASE , fields : { sla_tier__c : { type : 'text' , label : 'SLA tier' } } } ,
482+ } ) ;
483+ await protocol . publishMetaItem ( { type : TYPE , name : CASE , packageId : APP_PAIR } ) ;
484+
485+ const byName = ( await protocol . getMetaItem ( { type : 'object' , name : CASE } ) ) ?. item ;
486+ const layered = await protocol . getMetaItemLayered ( { type : 'object' , name : CASE } ) ;
487+ expect ( Object . keys ( byName ?. fields ?? { } ) ) . toEqual ( expect . arrayContaining ( [ 'subject' , 'sla_tier__c' ] ) ) ;
488+ expect ( Object . keys ( layered ?. effective ?. fields ?? { } ) ) . toContain ( 'sla_tier__c' ) ;
489+ expect ( Object . keys ( ( engine . registry . getObject ( CASE ) as any ) ?. fields ?? { } ) ) . toContain ( 'sla_tier__c' ) ;
490+ expect ( engine . registry . getObjectContributors ( CASE ) . filter ( ( c : any ) => c . ownership === 'extend' ) . map ( ( c : any ) => c . packageId ) )
491+ . toEqual ( [ APP_PAIR ] ) ;
492+ // A record stores a value in the field.
493+ const created : any = await engine . insert ( CASE , { subject : 'Outage' , sla_tier__c : 'gold' } , { context : { isSystem : true } } ) ;
494+ const back : any = await engine . findOne ( CASE , { where : { id : created . id } , context : { isSystem : true } } ) ;
495+ expect ( back ?. sla_tier__c ) . toBe ( 'gold' ) ;
496+ } , 60_000 ) ;
497+ } ) ;
0 commit comments