@@ -806,6 +806,33 @@ describe('validateExpression (ADR-0032)', () => {
806806 }
807807 } ) ;
808808
809+ // [#30250] A time-relative sweep's run is `run-fails` too (it binds a row
810+ // of the typed object), but no write fires it: the sweep starts one run per
811+ // row it finds. Its sentence names no write, under its own code.
812+ it ( 'on a time-relative sweep says the run for that row fails and names no write (#30250)' , ( ) => {
813+ const sweep = { ...schema , scope : 'flattened' as const , faultOutcome : 'run-fails' as const , timeRelativeSweep : true } ;
814+ for ( const [ source , reference ] of [ [ 'name > 5' , 'name' ] , [ 'record.name > 5' , 'record.name' ] ] as const ) {
815+ const r = validateExpression ( 'predicate' , source , sweep ) ;
816+ expect ( r . warnings , source ) . toHaveLength ( 0 ) ;
817+ expect ( r . errors . map ( ( e ) => [ e . code , e . params ] ) , source ) . toEqual ( [
818+ [ 'type-mismatch-sweep-run-fails' , { operands : 'string > int' , operator : '>' , held : 'text' , reference } ] ,
819+ ] ) ;
820+ expect ( r . errors [ 0 ] . message , source ) . toContain (
821+ 'a flow condition that cannot be evaluated fails the run: the time-relative sweep starts one run per row it ' +
822+ 'finds, the run for this row stops at this condition and the work the flow exists to do is not done for that ' +
823+ 'row, and nothing else happens' ,
824+ ) ;
825+ expect ( r . errors [ 0 ] . message , source ) . not . toMatch ( / s t i l l l a n d s | w r i t e t h a t f i r e d | e v a l u a t e s t o n u l l | i s r e f u s e d / ) ;
826+ }
827+ // The key reads only with the `run-fails` outcome: with none declared the
828+ // warning is the same as without it.
829+ const w = validateExpression ( 'predicate' , 'name > 5' , { ...schema , scope : 'flattened' , timeRelativeSweep : true } ) ;
830+ expect ( w . warnings . map ( ( e ) => e . code ) ) . toEqual ( [ 'type-mismatch-run-may-fail' ] ) ;
831+ // The date verdict's run-fails sentence names no write already: unchanged.
832+ const d = validateExpression ( 'predicate' , 'due + 1 > 3' , sweep ) ;
833+ expect ( d . errors . map ( ( e ) => e . code ) ) . toEqual ( [ 'date-arithmetic-run-fails' ] ) ;
834+ } ) ;
835+
809836 // [#29959] A flow condition reads the field bare AND as `record.<field>`
810837 // (`seedRunVariables` binds both to the trigger record), so the record
811838 // read gets the bare name's verdict: here the run-fails error.
@@ -1086,10 +1113,43 @@ describe('validateExpression (ADR-0032)', () => {
10861113 }
10871114 // A bare name a flow variable holds is not the field: no verdict.
10881115 expect ( codeOf ( { faultOutcome : 'run-fails' , flowVariables : [ 'start_date' ] } ) ) . toEqual ( [ ] ) ;
1089- // Control: a record-scoped validation rule keeps its code and sentence.
1090- const rule = validateExpression ( 'predicate' , 'record.start_date + 1 > 3' , { ...schema , faultOutcome : 'fail-closed' } ) ;
1091- expect ( rule . errors . map ( ( e ) => e . code ) ) . toEqual ( [ 'date-arithmetic' ] ) ;
1092- expect ( rule . errors [ 0 ] . message ) . toMatch ( / t h i s f a u l t s a t r u n t i m e , s o t h e f i e l d s i l e n t l y e v a l u a t e s t o n u l l / ) ;
1116+ // Control: a record-scoped site with no declared outcome (a formula
1117+ // field) keeps its code and sentence; a fail-closed rule is #30250's.
1118+ const field = validateExpression ( 'value' , 'record.start_date + 1' , schema ) ;
1119+ expect ( field . errors . map ( ( e ) => e . code ) ) . toEqual ( [ 'date-arithmetic' ] ) ;
1120+ expect ( field . errors [ 0 ] . message ) . toMatch ( / t h i s f a u l t s a t r u n t i m e , s o t h e f i e l d s i l e n t l y e v a l u a t e s t o n u l l / ) ;
1121+ } ) ;
1122+
1123+ // [#30250] On a fail-closed site (an `error` validation rule, a field
1124+ // `requiredWhen` / `readonlyWhen`, an option `visibleWhen`, a hook
1125+ // `condition`) a fault refuses the write: nothing reads null. The date
1126+ // verdicts there take the fail-closed sentence under their own codes.
1127+ it ( 'on a fail-closed site says the write is refused, not that the field reads null (#30250)' , ( ) => {
1128+ const closed = { ...schema , faultOutcome : 'fail-closed' } as const ;
1129+ for ( const [ source , code ] of [
1130+ [ 'record.start_date + 1 > 3' , 'date-arithmetic-fail-closed' ] ,
1131+ [ 'record.end_date - record.start_date > duration("24h")' , 'date-text-arithmetic-fail-closed' ] ,
1132+ ] as const ) {
1133+ const r = validateExpression ( 'predicate' , source , closed ) ;
1134+ expect ( r . warnings , source ) . toHaveLength ( 0 ) ;
1135+ expect ( r . errors . map ( ( e ) => e . code ) , source ) . toEqual ( [ code ] ) ;
1136+ expect ( r . errors [ 0 ] . message , source ) . toContain (
1137+ 'this faults at runtime, and here an expression that cannot be evaluated fails closed: the write (or the ' +
1138+ 'operation a hook guards) is refused, not skipped (it does not read null).' ,
1139+ ) ;
1140+ expect ( r . errors [ 0 ] . message , source ) . not . toMatch ( / e v a l u a t e s t o n u l l / ) ;
1141+ }
1142+ // Controls: a formula field (no outcome) keeps the null sentence; so does
1143+ // an advisory rule (`fail-open`), which #30250 does not cover.
1144+ for ( const [ role , source , hint , code ] of [
1145+ [ 'value' , 'record.start_date + 1' , schema , 'date-arithmetic' ] ,
1146+ [ 'value' , 'record.end_date - record.start_date' , schema , 'date-text-arithmetic' ] ,
1147+ [ 'predicate' , 'record.start_date + 1 > 3' , { ...schema , faultOutcome : 'fail-open' } , 'date-arithmetic' ] ,
1148+ ] as const ) {
1149+ const r = validateExpression ( role , source , hint ) ;
1150+ expect ( r . errors . map ( ( e ) => e . code ) , source ) . toEqual ( [ code ] ) ;
1151+ expect ( r . errors [ 0 ] . message , source ) . toContain ( 'this faults at runtime, so the field silently evaluates to null' ) ;
1152+ }
10931153 } ) ;
10941154 } ) ;
10951155
0 commit comments