@@ -40,8 +40,9 @@ import { ACTION_BODY_WRITE_UNKNOWN_FIELD, validateActionBodyWrites } from './val
4040import { HOOK_BODY_WRITE_UNKNOWN_FIELD , validateHookBodyWrites } from './validate-hook-body-writes.js' ;
4141import { validateReactPageProps } from './validate-react-page-props.js' ;
4242import { TRANSLATION_TARGET_UNKNOWN , validateTranslationReferences } from './validate-translation-references.js' ;
43- import { FLOW_UPDATE_READONLY_FIELD , validateReadonlyFlowWrites } from './validate-readonly-flow-writes.js' ;
44- import { HOOK_API_UPDATE_READONLY_FIELD , validateReadonlyHookWrites } from './validate-readonly-hook-writes.js' ;
43+ import { FLOW_UPDATE_READONLY_FIELD , FLOW_UPDATE_READONLY_WHEN_FIELD , validateReadonlyFlowWrites } from './validate-readonly-flow-writes.js' ;
44+ import { HOOK_API_UPDATE_READONLY_FIELD , HOOK_API_UPDATE_READONLY_WHEN_FIELD , validateReadonlyHookWrites } from './validate-readonly-hook-writes.js' ;
45+ import { SORT_FIELD_UNKNOWN , SORT_FIELD_UNSORTABLE , validateSortableFields } from './validate-sortable-fields.js' ;
4546import { ACTION_API_UPDATE_READONLY_WHEN_FIELD , validateReadonlyActionWrites } from './validate-readonly-action-writes.js' ;
4647import { SEARCHABLE_FIELD_UNKNOWN } from './validate-searchable-fields.js' ;
4748// [#16340] Read back the registry's OWN definition table to assert the graph
@@ -853,6 +854,12 @@ describe('[#30471] the field-name indexes read the objects as served', () => {
853854 const validationOn = ( condition : string ) : Rec => ( {
854855 objects : [ { ...deal , validations : [ { name : 'v' , type : 'script' , condition, message : 'M' } ] } , account ] ,
855856 } ) ;
857+ const pageSort = ( field : string ) : Rec => ( {
858+ pages : [ { name : 'p' , type : 'list' , object : 'xs_deal' , interfaceConfig : { source : 'xs_deal' , sort : [ { field, order : 'asc' } ] } } ] ,
859+ } ) ;
860+ const viewSort = ( field : string ) : Rec => ( {
861+ views : [ { name : 'v' , objectName : 'xs_deal' , list : { type : 'grid' , columns : [ 'name' ] , sort : [ { field, order : 'asc' } ] } } ] ,
862+ } ) ;
856863
857864 // rule · its unknown-field id · the stack naming FIELD
858865 const existence : Array < [ string , string , Run , ( field : string ) => Rec ] > = [
@@ -878,6 +885,8 @@ describe('[#30471] the field-name indexes read the objects as served', () => {
878885 [ 'validate-translation-references' , TRANSLATION_TARGET_UNKNOWN , validateTranslationReferences , ( f ) => ( {
879886 translations : [ { 'zh-CN' : { objects : { xs_deal : { fields : { [ f ] : { label : 'L' } } } } } } ] ,
880887 } ) ] ,
888+ [ 'validate-sortable-fields (a page sort)' , PAGE_FIELD_UNKNOWN , validateSortableFields , ( f ) => pageSort ( f ) ] ,
889+ [ 'validate-sortable-fields (a list-view sort)' , SORT_FIELD_UNKNOWN , validateSortableFields , ( f ) => viewSort ( f ) ] ,
881890 ] ;
882891
883892 it . each ( existence ) ( '%s: an extension-added field passes; a field nothing adds is still refused' , ( _rule , id , run , naming ) => {
@@ -1031,4 +1040,89 @@ describe('[#30471] the field-name indexes read the objects as served', () => {
10311040 expect ( ids ( validateReactPageProps , artifact ( search ( 'region' ) ) ) ) . toEqual ( [ SEARCHABLE_FIELD_UNKNOWN ] ) ;
10321041 expect ( ids ( validateReactPageProps , artifact ( search ( 'name' ) ) ) ) . toEqual ( [ ] ) ;
10331042 } ) ;
1043+
1044+ // Every refusal this change adds, one row each: a write or a sort naming an
1045+ // extension field whose served definition the runtime refuses or drops. On
1046+ // the declared objects alone (what `main` read) the same stack was the
1047+ // existence rule's unknown name; now the existence rule passes it and the
1048+ // definition rule owns it, at that rule's own severity. The hook rows are
1049+ // the one severity move: `hook-body-write-unknown-field` was a warning.
1050+ describe ( 'each refusal this change adds is the definition rule\'s, at its own severity' , ( ) => {
1051+ const lock = { locked : { type : 'text' , readonly : true } } ;
1052+ const gate = { gated : { type : 'number' , readonlyWhen : "record.name == 'x'" } } ;
1053+ const calc = { calc : { type : 'formula' , expression : 'record.amount * 2' } } ;
1054+ const flowNode = ( type : string , field : string ) : Rec => ( {
1055+ flows : [ { name : 'fl' , nodes : [ { id : 'n' , type, config : { objectName : 'xs_deal' , fields : { [ field ] : 'x' } } } ] } ] ,
1056+ } ) ;
1057+ const hookApi = ( call : string ) : Rec => ( {
1058+ hooks : [ { name : 'h' , object : 'xs_account' , events : [ 'afterInsert' ] , body : { language : 'js' , source : `await ctx.api.object('xs_deal').${ call } ;` } } ] ,
1059+ } ) ;
1060+ const actionApi = ( field : string ) : Rec => ( {
1061+ actions : [ { name : 'act' , label : 'Act' , objectName : 'xs_deal' , body : { language : 'js' , source : `await ctx.api.object('xs_deal').update({ id: ctx.recordId, ${ field } : 1 });` } } ] ,
1062+ } ) ;
1063+ const hooks : Run = ( stack ) => validateReadonlyHookWrites ( stack ) ;
1064+ const hookExistence : Run = ( stack ) => validateHookBodyWrites ( stack ) ;
1065+ // the write · the rule judging it now · the extension fields · the stack ·
1066+ // its id and severity now · the existence rule and the id it raised before
1067+ const refusals : Array < [ string , Run , Rec , Rec , string , string , Run , string ] > = [
1068+ [ 'a flow update_record of a readonly field' , validateReadonlyFlowWrites , lock , flowNode ( 'update_record' , 'locked' ) ,
1069+ FLOW_UPDATE_READONLY_FIELD , 'error' , validateFlowNodeWrites , FLOW_NODE_WRITE_UNKNOWN_FIELD ] ,
1070+ [ 'a flow create_record of a readonly field' , validateReadonlyFlowWrites , lock , flowNode ( 'create_record' , 'locked' ) ,
1071+ FLOW_UPDATE_READONLY_FIELD , 'error' , validateFlowNodeWrites , FLOW_NODE_WRITE_UNKNOWN_FIELD ] ,
1072+ [ 'a flow update_record of a readonlyWhen field' , validateReadonlyFlowWrites , gate , flowNode ( 'update_record' , 'gated' ) ,
1073+ FLOW_UPDATE_READONLY_WHEN_FIELD , 'warning' , validateFlowNodeWrites , FLOW_NODE_WRITE_UNKNOWN_FIELD ] ,
1074+ [ 'a hook ctx.api update of a readonly field' , hooks , lock , hookApi ( "update({ id: dealId, locked: 'x' })" ) ,
1075+ HOOK_API_UPDATE_READONLY_FIELD , 'error' , hookExistence , HOOK_BODY_WRITE_UNKNOWN_FIELD ] ,
1076+ [ 'a hook ctx.api insert of a readonly field' , hooks , lock , hookApi ( "insert({ locked: 'x' })" ) ,
1077+ HOOK_API_UPDATE_READONLY_FIELD , 'error' , hookExistence , HOOK_BODY_WRITE_UNKNOWN_FIELD ] ,
1078+ [ 'a hook ctx.api update of a readonlyWhen field' , hooks , gate , hookApi ( 'update({ id: dealId, gated: 1 })' ) ,
1079+ HOOK_API_UPDATE_READONLY_WHEN_FIELD , 'warning' , hookExistence , HOOK_BODY_WRITE_UNKNOWN_FIELD ] ,
1080+ [ 'an action ctx.api update of a readonlyWhen field' , validateReadonlyActionWrites , gate , actionApi ( 'gated' ) ,
1081+ ACTION_API_UPDATE_READONLY_WHEN_FIELD , 'warning' , validateActionBodyWrites , ACTION_BODY_WRITE_UNKNOWN_FIELD ] ,
1082+ [ 'a page sort by a formula field' , validateSortableFields , calc , pageSort ( 'calc' ) ,
1083+ SORT_FIELD_UNSORTABLE , 'error' , validateSortableFields , PAGE_FIELD_UNKNOWN ] ,
1084+ [ 'a list-view sort by a formula field' , validateSortableFields , calc , viewSort ( 'calc' ) ,
1085+ SORT_FIELD_UNSORTABLE , 'error' , validateSortableFields , SORT_FIELD_UNKNOWN ] ,
1086+ ] ;
1087+ // The stack on both CLI legs (the union artifact, then the per-package
1088+ // body), each extension list its own package.
1089+ const onLegs = ( extra : Rec , packages : unknown [ ] [ ] , objects : unknown [ ] = [ deal , account ] ) : Rec [ ] => {
1090+ const mods = packages . map ( ( objectExtensions , i ) => ( { manifest : { id : `mod${ i } ` , objectExtensions } } ) ) ;
1091+ const body = { id : 'app' , objects, ...extra } ;
1092+ return [
1093+ { objects, packages : [ { manifest : { id : 'app' , objects } } , ...mods ] , ...extra } ,
1094+ { ...body , manifest : body , packages : [ { manifest : body } , ...mods ] } ,
1095+ ] ;
1096+ } ;
1097+ const ext = ( fields : Rec ) => [ { extend : 'xs_deal' , fields } ] ;
1098+
1099+ it . each ( refusals ) ( '%s' , ( _write , run , fields , stack , id , severity , existence , unknownId ) => {
1100+ for ( const served of onLegs ( stack , [ ext ( fields ) ] ) ) {
1101+ expect ( run ( served ) . map ( ( f ) => [ f . rule , f . severity ] ) ) . toEqual ( [ [ id , severity ] ] ) ;
1102+ expect ( ids ( existence , served ) ) . not . toContain ( unknownId ) ;
1103+ }
1104+ for ( const declared of onLegs ( stack , [ [ ] ] ) ) {
1105+ expect ( ids ( existence , declared ) ) . toContain ( unknownId ) ;
1106+ expect ( ids ( run , declared ) ) . not . toContain ( id ) ;
1107+ }
1108+ } ) ;
1109+
1110+ it . each ( refusals ) ( '%s, on a field two packages tie on: unjudged' , ( _write , run , fields , stack , id ) => {
1111+ const plain = Object . fromEntries ( Object . keys ( fields ) . map ( ( name ) => [ name , { type : 'text' } ] ) ) ;
1112+ for ( const [ a , b ] of [ [ plain , fields ] , [ fields , plain ] ] ) {
1113+ for ( const tied of onLegs ( stack , [ ext ( a ) , ext ( b ) ] ) ) expect ( ids ( run , tied ) ) . not . toContain ( id ) ;
1114+ }
1115+ for ( const single of onLegs ( stack , [ ext ( fields ) , ext ( { } ) ] ) ) expect ( ids ( run , single ) ) . toContain ( id ) ;
1116+ } ) ;
1117+
1118+ // An object that declares no field (an introspected schema) is left
1119+ // unjudged by the write rules and skip 2 of the sort rule; an extension
1120+ // adding to it does not make it judgeable by the definition rules either.
1121+ it . each ( refusals ) ( '%s, on an object that declares no field: unjudged, extended or not' , ( _write , run , fields , stack ) => {
1122+ const bare = { name : 'xs_deal' , label : 'Deal' , fields : { } } ;
1123+ for ( const packages of [ [ ext ( fields ) ] , [ [ ] ] ] ) {
1124+ for ( const s of onLegs ( stack , packages , [ bare , account ] ) ) expect ( ids ( run , s ) ) . toEqual ( [ ] ) ;
1125+ }
1126+ } ) ;
1127+ } ) ;
10341128} ) ;
0 commit comments