@@ -624,6 +624,13 @@ describe('[#30383] the field-path rules read the objects as served', () => {
624624 mappings : [ { name : 'm' , targetObject : 'xs_deal' , fieldMapping : [ { source : 'R' , target : f } ] } ] ,
625625 } ) ] ,
626626 ] ;
627+ // The per-package leg of `os build` (`packageBodyAsStack` in the cli): the
628+ // app body is the stack, its own collections at the top level and under
629+ // `manifest`, and the artifact's `packages[]` beside them.
630+ const perPackage = ( extra : Rec , objectExtensions : unknown [ ] = extensions ) : Rec => {
631+ const body = { id : 'app' , objects : [ deal , account , note ] , ...extra } ;
632+ return { ...body , manifest : body , packages : [ { manifest : body } , { manifest : { id : 'mod' , objectExtensions } } ] } ;
633+ } ;
627634 it . each ( existence ) ( '%s: an extension-added field passes; a field nothing adds is still %s' , ( _rule , id , run , naming ) => {
628635 // `ref_no` (an autonumber) is the one name every member admits, the
629636 // thank-you panel included.
@@ -632,6 +639,21 @@ describe('[#30383] the field-path rules read the objects as served', () => {
632639 expect ( ids ( run , artifact ( naming ( 'nowhere' ) ) ) ) . toContain ( id ) ;
633640 } ) ;
634641
642+ it . each ( existence ) ( '%s, on the per-package leg: the same verdicts' , ( _rule , id , run , naming ) => {
643+ expect ( ids ( run , perPackage ( naming ( 'ref_no' ) ) ) ) . not . toContain ( id ) ;
644+ expect ( ids ( run , perPackage ( naming ( 'ref_no' ) , [ ] ) ) ) . toContain ( id ) ;
645+ expect ( ids ( run , perPackage ( naming ( 'nowhere' ) ) ) ) . toContain ( id ) ;
646+ } ) ;
647+
648+ it . each ( existence ) ( '%s: a field nothing adds is refused byte-for-byte as on the declared objects alone' , ( _rule , id , run , naming ) => {
649+ const refusal = ( stack : Rec ) => run ( stack )
650+ . filter ( ( f ) => f . rule === id )
651+ . map ( ( f ) => { const { severity, where, path, message } = f as Rec ; return { severity, where, path, message } ; } ) ;
652+ const served = refusal ( artifact ( naming ( 'zq_absent' ) ) ) ;
653+ expect ( served ) . toHaveLength ( 1 ) ;
654+ expect ( served ) . toEqual ( refusal ( artifact ( naming ( 'zq_absent' ) , [ ] ) ) ) ;
655+ } ) ;
656+
635657 it ( 'validate-dataset-references: a path through an extension-added relationship resolves' , ( ) => {
636658 expect ( ids ( validateDatasetReferences , artifact ( { datasets : [ dataset ( 'partner.tier' ) ] } ) ) ) . toEqual ( [ ] ) ;
637659 expect ( ids ( validateDatasetReferences , artifact ( { datasets : [ dataset ( 'partner.nowhere' ) ] } ) ) ) . toEqual ( [ DATASET_FIELD_UNKNOWN ] ) ;
@@ -667,6 +689,17 @@ describe('[#30383] the field-path rules read the objects as served', () => {
667689 expect ( validateFieldConsumers ( artifact ( { datasets : [ dataset ( 'name' ) ] } ) ) . filter ( ( f ) => f . field in added ) ) . toEqual ( [ ] ) ;
668690 } ) ;
669691
692+ it ( 'validate-related-list-refs, on the per-package leg: a child another body owns stays unjudged' , ( ) => {
693+ // `lib` owns `xs_note` and its FK; `mod` extends `xs_note` with something
694+ // else. The app body's leg holds neither declaration, so it must not read
695+ // `mod`'s extension as `xs_note`'s whole field set.
696+ const body = { id : 'app' , objects : [ { ...deal , relatedLists : [ 'xs_note' , 'xs_note.deal_id' ] } , account ] } ;
697+ const lib = { id : 'lib' , objects : [ { name : 'xs_note' , fields : { deal_id : { type : 'lookup' , reference : 'xs_deal' } } } ] } ;
698+ const mod = { id : 'mod' , objectExtensions : [ { extend : 'xs_note' , fields : { mood : { type : 'text' } } } ] } ;
699+ const stack = { ...body , manifest : body , packages : [ { manifest : body } , { manifest : lib } , { manifest : mod } ] } ;
700+ expect ( ids ( validateRelatedListRefs , stack ) ) . toEqual ( [ ] ) ;
701+ } ) ;
702+
670703 it ( 'validate-related-list-refs: an FK a sibling package adds is an inbound relationship' , ( ) => {
671704 const lists = ( relatedLists : string [ ] ) => ( { objects : [ { ...deal , relatedLists } , account , note ] } ) ;
672705 expect ( ids ( validateRelatedListRefs , artifact ( lists ( [ 'xs_note' , 'xs_note.deal_id' ] ) ) ) ) . toEqual ( [ ] ) ;
@@ -690,4 +723,55 @@ describe('[#30383] the field-path rules read the objects as served', () => {
690723 expect ( ids ( validateMappingTargetFields , artifact ( mapping ( 'score' ) , replaced ) ) ) . toEqual ( [ ] ) ;
691724 expect ( ids ( validateMappingTargetFields , artifact ( mapping ( 'region' ) , replaced ) ) ) . toEqual ( [ MAPPING_TARGET_FIELD_UNKNOWN ] ) ;
692725 } ) ;
726+
727+ // Two packages writing one field at the deciding priority: the name is
728+ // served, but which definition wins is registration order, which the stack
729+ // does not state. The type arms leave it unjudged; the thank-you panel,
730+ // shown to anonymous visitors, fails closed.
731+ describe ( 'a field two packages tie on' , ( ) => {
732+ const tie = ( a : Rec , b : Rec ) : Rec => ( {
733+ objects : [ deal , account , note ] ,
734+ packages : [
735+ { manifest : { id : 'app' , objects : [ deal , account , note ] } } ,
736+ { manifest : { id : 'mod' , objectExtensions : [ { extend : 'xs_deal' , fields : a } ] } } ,
737+ { manifest : { id : 'mod2' , objectExtensions : [ { extend : 'xs_deal' , fields : b } ] } } ,
738+ ] ,
739+ } ) ;
740+ const numberOrText = ( extra : Rec ) => ( { ...tie ( { score : { type : 'number' } } , { score : { type : 'text' } } ) , ...extra } ) ;
741+ const dateOrText = ( extra : Rec ) => ( { ...tie ( { closed_on : { type : 'date' } } , { closed_on : { type : 'text' } } ) , ...extra } ) ;
742+
743+ it ( 'is still a served name for the existence rules' , ( ) => {
744+ expect ( ids ( validateDatasetReferences , numberOrText ( { datasets : [ { ...dataset ( 'score' ) , include : [ ] } ] } ) ) ) . toEqual ( [ ] ) ;
745+ expect ( ids ( validateDatasetReferences , numberOrText ( { datasets : [ { ...dataset ( 'zq_absent' ) , include : [ ] } ] } ) ) ) . toEqual ( [ DATASET_FIELD_UNKNOWN ] ) ;
746+ } ) ;
747+
748+ it ( 'is not judged on its type by the type arms' , ( ) => {
749+ const sum = { datasets : [ { name : 'deals' , object : 'xs_deal' , measures : [ { name : 's' , aggregate : 'sum' , field : 'score' } ] } ] } ;
750+ expect ( ids ( validateDatasetMeasureAggregates , numberOrText ( sum ) ) ) . toEqual ( [ ] ) ;
751+ expect ( ids ( validateDatasetMeasureAggregates , { ...tie ( { score : { type : 'text' } } , { } ) , ...sum } ) )
752+ . toEqual ( [ MEASURE_AGGREGATE_FIELD_TYPE_REFUSED ] ) ;
753+ expect ( ids ( validatePresetComparands , dateOrText ( widget ( { closed_on : 'last_30_days' } ) ) ) ) . toEqual ( [ ] ) ;
754+ const rule = { sharingRules : [ { name : 'sr' , object : 'xs_deal' , condition : 'record.closed_on == record.name' , sharedWith : { type : 'role' , value : 'r' } , accessLevel : 'read' } ] } ;
755+ expect ( ids ( validateSharingRuleEnforceability , dateOrText ( rule ) ) ) . toEqual ( [ ] ) ;
756+ } ) ;
757+
758+ it ( 'is admitted on a thank-you panel only when every tied definition is engine-generated' , ( ) => {
759+ const panel = ( stack : Rec ) => ( {
760+ ...stack ,
761+ views : [ {
762+ name : 'vv' ,
763+ form : {
764+ type : 'simple' , data : { provider : 'object' , object : 'xs_deal' } , sections : [ { name : 'a' , fields : [ 'name' ] } ] ,
765+ submitBehavior : { kind : 'thank-you' , title : 'T' , message : 'Ref {{record.ref_no}}' } ,
766+ } ,
767+ } ] ,
768+ } ) ;
769+ expect ( ids ( validateThankYouRecordFields , panel ( tie ( { ref_no : { type : 'autonumber' } } , { ref_no : { type : 'autonumber' } } ) ) ) ) . toEqual ( [ ] ) ;
770+ for ( const [ a , b ] of [ [ 'autonumber' , 'text' ] , [ 'text' , 'autonumber' ] ] ) {
771+ const findings = validateThankYouRecordFields ( panel ( tie ( { ref_no : { type : a } } , { ref_no : { type : b } } ) ) ) ;
772+ expect ( findings . map ( ( f ) => f . rule ) ) . toEqual ( [ THANK_YOU_RECORD_FIELD ] ) ;
773+ expect ( findings [ 0 ] . message ) . toContain ( 'is a text field' ) ;
774+ }
775+ } ) ;
776+ } ) ;
693777} ) ;
0 commit comments