@@ -82,8 +82,14 @@ function harness(opts: {
8282 bundles ?: Record < string , Record < string , unknown > > ;
8383 /** The grants read fails (the resolver throws). */
8484 grantsFail ?: boolean ;
85+ /** The grants resolver answers nothing (`null`). */
86+ grantsNone ?: boolean ;
87+ /** No grants resolver is wired at all. */
88+ noGrantsResolver ?: boolean ;
89+ /** The live `deal` rows, when not the one default row. */
90+ rows ?: Record < string , Record < string , unknown > > ;
8591} = { } ) : Harness {
86- const { data, calls } = liveData ( ) ;
92+ const { data, calls } = liveData ( opts . rows ) ;
8793 const writeChecks : Harness [ 'writeChecks' ] = [ ] ;
8894 const security = opts . canWrite
8995 ? {
@@ -123,7 +129,7 @@ function harness(opts: {
123129 } as any ) ,
124130 async execute ( ) { h . approvalCalls ++ ; return { success : true , suspend : true } ; } ,
125131 } ) ;
126- engine . setUserGrantsResolver ( async ( ) => opts . grantsFail ? Promise . reject ( new Error ( 'grants store unreachable' ) ) : ( {
132+ if ( ! opts . noGrantsResolver ) engine . setUserGrantsResolver ( async ( ) => opts . grantsFail ? Promise . reject ( new Error ( 'grants store unreachable' ) ) : opts . grantsNone ? null as never : ( {
127133 positions : [ ] ,
128134 permissions : [ ] ,
129135 accessible_org_ids : [ 'org_1' ] ,
@@ -320,8 +326,12 @@ describe('dryRun — admission (the by-name start rules, ruling B for runAs syst
320326 expect ( result . steps ) . toEqual ( [ ] ) ;
321327 } ) ;
322328
323- it ( 'refuses a runAs system definition when the named user\'s grants cannot be read (the account rule fails closed)' , async ( ) => {
324- const h = harness ( { grantsFail : true } ) ;
329+ it . each ( [
330+ [ 'the read fails (the resolver throws)' , { grantsFail : true } ] ,
331+ [ 'the resolver answers nothing' , { grantsNone : true } ] ,
332+ [ 'no resolver is wired' , { noGrantsResolver : true } ] ,
333+ ] as const ) ( 'refuses a runAs system definition when the named user\'s grants cannot be read: %s (the account rule fails closed)' , async ( _arm , unread ) => {
334+ const h = harness ( unread ) ;
325335 const result = await h . engine . dryRun ( gated ( { type : 'schedule' , runAs : 'system' } ) , { userId : 'usr_maker' } ) ;
326336 expect ( result . status ) . toBe ( 'refused' ) ;
327337 expect ( result . steps ) . toEqual ( [ ] ) ;
@@ -546,3 +556,41 @@ describe('dryRun — a predicate write the engine refuses without multi', () =>
546556 expect ( result . steps . find ( ( s ) => s . nodeId === 'up' ) ) . toMatchObject ( { kind : 'write' , operation : 'update' , recordIds : [ 'd1' ] } ) ;
547557 } ) ;
548558} ) ;
559+
560+ describe ( 'dryRun — a write targets exactly the rows the engine dispatch names' , ( ) => {
561+ const rows = ( ) => ( { d1 : { id : 'd1' , stage : 'open' , amount : 10 } , d2 : { id : 'd2' , stage : 'open' , amount : 20 } } ) ;
562+ const readBoth = [
563+ { id : 'r1' , type : 'get_record' , label : 'Read d1' , config : { objectName : 'deal' , filter : { id : 'd1' } , outputVariable : 'one' } } ,
564+ { id : 'r2' , type : 'get_record' , label : 'Read d2' , config : { objectName : 'deal' , filter : { id : 'd2' } , outputVariable : 'two' } } ,
565+ { id : 'as' , type : 'assignment' , label : 'Keep' , config : { assignments : { seen : { dialect : 'cel' , source : 'one.stage + "/" + two.stage' } } } } ,
566+ ] ;
567+
568+ it ( 'an update whose fields name the id, with no filter, targets that one row and lays its values over it alone' , async ( ) => {
569+ const h = harness ( { canWrite : ( ) => true , rows : rows ( ) } ) ;
570+ const result = await h . engine . dryRun ( flow ( [
571+ { id : 'start' , type : 'start' , label : 'Start' } ,
572+ { id : 'up' , type : 'update_record' , label : 'Update' , config : { objectName : 'deal' , fields : { id : 'd2' , stage : 'won' } } } ,
573+ ...readBoth ,
574+ { id : 'end' , type : 'end' , label : 'End' } ,
575+ ] , chain ( 'start' , 'up' , 'r1' , 'r2' , 'as' , 'end' ) ) , { userId : 'usr_maker' } ) ;
576+
577+ expect ( result . status ) . toBe ( 'completed' ) ;
578+ expect ( writes ( h ) ) . toEqual ( [ ] ) ;
579+ expect ( result . steps . find ( ( s ) => s . nodeId === 'up' ) ) . toMatchObject ( { kind : 'write' , operation : 'update' , recordIds : [ 'd2' ] } ) ;
580+ expect ( result . steps . find ( ( s ) => s . nodeId === 'as' ) ) . toMatchObject ( { kind : 'assignment' , values : { seen : 'open/won' } } ) ;
581+ } ) ;
582+
583+ it ( 'CONTROL — the same update declaring multi with no filter targets every row the named user can read' , async ( ) => {
584+ const h = harness ( { canWrite : ( ) => true , rows : rows ( ) } ) ;
585+ const result = await h . engine . dryRun ( flow ( [
586+ { id : 'start' , type : 'start' , label : 'Start' } ,
587+ { id : 'up' , type : 'update_record' , label : 'Update' , config : { objectName : 'deal' , fields : { stage : 'won' } , multi : true } } ,
588+ ...readBoth ,
589+ { id : 'end' , type : 'end' , label : 'End' } ,
590+ ] , chain ( 'start' , 'up' , 'r1' , 'r2' , 'as' , 'end' ) ) , { userId : 'usr_maker' } ) ;
591+
592+ expect ( result . status ) . toBe ( 'completed' ) ;
593+ expect ( result . steps . find ( ( s ) => s . nodeId === 'up' ) ) . toMatchObject ( { kind : 'write' , operation : 'update' , recordIds : [ 'd1' , 'd2' ] } ) ;
594+ expect ( result . steps . find ( ( s ) => s . nodeId === 'as' ) ) . toMatchObject ( { kind : 'assignment' , values : { seen : 'won/won' } } ) ;
595+ } ) ;
596+ } ) ;
0 commit comments