1010 * The catalog translates the PACKAGED rule, so under `zh-CN`:
1111 *
1212 * - the rewritten rule must answer the tenant's own sentence, as written;
13- * - the rule the tenant left alone must still answer its translation.
13+ * - the rule the tenant left alone must still answer its translation;
14+ * - a rule a second package folds on through `objectExtensions` — absent
15+ * from the owner's declaration by construction — must still answer its own
16+ * package's translation: it has no packaged message to diverge from.
1417 *
1518 * Both readers are driven off ONE real registry: the refusal of a real write
1619 * (the engine's validator), and the served object as `/meta` translates it —
@@ -26,14 +29,29 @@ import { ObjectQL } from './index.js';
2629
2730const OBJ = 'tr_duty' ;
2831const PKG = 'com.objectstack.test.tenant-rewrite' ;
32+ const EXT_PKG = 'com.objectstack.test.tenant-rewrite-extension' ;
2933
3034const PACKAGED = {
3135 returned_needs_note : 'Say why the duty is being returned.' ,
3236 done_needs_owner : 'A finished duty needs an owner.' ,
37+ ext_blocked_needs_reason : 'Say what is blocking the duty.' ,
3338} ;
3439const ZH = {
3540 returned_needs_note : '请写明打回的原因。' ,
3641 done_needs_owner : '已完成的职责需要负责人。' ,
42+ ext_blocked_needs_reason : '请写明阻塞原因。' ,
43+ } ;
44+
45+ /** The extension package's own rule, folded onto the object. */
46+ const EXTENSION = {
47+ name : OBJ ,
48+ validations : [ {
49+ type : 'script' ,
50+ name : 'ext_blocked_needs_reason' ,
51+ message : PACKAGED . ext_blocked_needs_reason ,
52+ condition : "record.status == 'blocked' && record.return_note == null" ,
53+ fields : [ 'return_note' ] ,
54+ } ] ,
3755} ;
3856const REWRITE = 'Tell the owner what to change before you send it back.' ;
3957
@@ -72,6 +90,7 @@ const BUNDLE: Record<string, any> = {
7290 _validations : {
7391 returned_needs_note : { message : PACKAGED . returned_needs_note } ,
7492 done_needs_owner : { message : PACKAGED . done_needs_owner } ,
93+ ext_blocked_needs_reason : { message : PACKAGED . ext_blocked_needs_reason } ,
7594 } ,
7695 } ,
7796 } ,
@@ -82,6 +101,7 @@ const BUNDLE: Record<string, any> = {
82101 _validations : {
83102 returned_needs_note : { message : ZH . returned_needs_note } ,
84103 done_needs_owner : { message : ZH . done_needs_owner } ,
104+ ext_blocked_needs_reason : { message : ZH . ext_blocked_needs_reason } ,
85105 } ,
86106 } ,
87107 } ,
@@ -134,6 +154,7 @@ describe('ADR-0029 D9.2a a tenant-rewritten rule message, on the refusal and on
134154 await engine . init ( ) ;
135155 engine . setI18nService ( servedI18n ( BUNDLE ) as any ) ;
136156 engine . registry . registerObject ( body ( PACKAGED . returned_needs_note ) as any , PKG ) ;
157+ engine . registry . registerObject ( EXTENSION as any , EXT_PKG , undefined , 'extend' ) ;
137158 if ( overlay ) {
138159 engine . registry . registerObject ( { ...body ( REWRITE ) , _provenance : 'org' } as any , PKG , undefined , 'overlay' ) ;
139160 }
@@ -170,6 +191,7 @@ describe('ADR-0029 D9.2a a tenant-rewritten rule message, on the refusal and on
170191 refusal : {
171192 returned_needs_note : await refusal ( header , { id : 'r1' , status : 'returned' } ) ,
172193 done_needs_owner : await refusal ( header , { id : 'r2' , status : 'done' } ) ,
194+ ext_blocked_needs_reason : await refusal ( header , { id : 'r3' , status : 'blocked' } ) ,
173195 } ,
174196 } ;
175197 }
@@ -180,24 +202,32 @@ describe('ADR-0029 D9.2a a tenant-rewritten rule message, on the refusal and on
180202 beforeEach ( async ( ) => { await boot ( true ) ; } ) ;
181203
182204 it ( 'the overlay is what both readers see, over a packaged owner that is still there' , ( ) => {
205+ const served = ( engine . registry . getObject ( OBJ ) as any ) . validations . map ( ( r : any ) => r . name ) ;
206+ expect ( served ) . toEqual ( [ 'returned_needs_note' , 'done_needs_owner' , 'ext_blocked_needs_reason' ] ) ;
183207 expect ( ( engine . registry . getObject ( OBJ ) as any ) . validations [ 0 ] . message ) . toBe ( REWRITE ) ;
184- expect ( ( protocol . getPackagedObjectBase ( OBJ ) as any ) . validations [ 0 ] . message ) . toBe ( PACKAGED . returned_needs_note ) ;
208+ const packaged = protocol . getPackagedObjectBase ( OBJ ) as any ;
209+ expect ( packaged . validations . map ( ( r : any ) => r . name ) ) . toEqual ( [ 'returned_needs_note' , 'done_needs_owner' ] ) ;
210+ expect ( packaged . validations [ 0 ] . message ) . toBe ( PACKAGED . returned_needs_note ) ;
185211 } ) ;
186212
187- it ( 'serves and refuses with the rewrite as written, and still translates the untouched rule' , async ( ) => {
188- const both = ( zh : string ) => ( { returned_needs_note : REWRITE , done_needs_owner : zh } ) ;
213+ it ( 'serves and refuses with the rewrite as written, and still translates the untouched and extension rules' , async ( ) => {
214+ const rows = ( t : typeof ZH ) => ( {
215+ returned_needs_note : REWRITE ,
216+ done_needs_owner : t . done_needs_owner ,
217+ ext_blocked_needs_reason : t . ext_blocked_needs_reason ,
218+ } ) ;
189219 expect ( await table ( ) ) . toEqual ( {
190- 'zh-CN' : { served : both ( ZH . done_needs_owner ) , refusal : both ( ZH . done_needs_owner ) } ,
191- zh : { served : both ( ZH . done_needs_owner ) , refusal : both ( ZH . done_needs_owner ) } ,
192- en : { served : both ( PACKAGED . done_needs_owner ) , refusal : both ( PACKAGED . done_needs_owner ) } ,
220+ 'zh-CN' : { served : rows ( ZH ) , refusal : rows ( ZH ) } ,
221+ zh : { served : rows ( ZH ) , refusal : rows ( ZH ) } ,
222+ en : { served : rows ( PACKAGED ) , refusal : rows ( PACKAGED ) } ,
193223 } ) ;
194224 } ) ;
195225 } ) ;
196226
197227 describe ( 'control: no overlay' , ( ) => {
198228 beforeEach ( async ( ) => { await boot ( false ) ; } ) ;
199229
200- it ( 'translates both packaged rules on both readers' , async ( ) => {
230+ it ( 'translates every rule on both readers' , async ( ) => {
201231 expect ( await table ( ) ) . toEqual ( {
202232 'zh-CN' : { served : ZH , refusal : ZH } ,
203233 zh : { served : ZH , refusal : ZH } ,
0 commit comments