@@ -62,6 +62,8 @@ const loan = {
6262 fields : {
6363 title : { name : 'title' , label : 'Title' , type : 'text' } ,
6464 borrow_date : { name : 'borrow_date' , label : 'Borrowed' , type : 'date' } ,
65+ // [#34946] Required, so the null-guard gate draws no second finding on a comparison of it.
66+ due_date : { name : 'due_date' , label : 'Due' , type : 'date' , required : true } ,
6567 picked_up_at : { name : 'picked_up_at' , label : 'Picked up' , type : 'datetime' } ,
6668 } ,
6769} ;
@@ -150,3 +152,56 @@ describe('[#34662] the flow publish door refuses timestamp() over a date field r
150152 }
151153 } , 60_000 ) ;
152154} ) ;
155+
156+ /** [#34946] The door's date-arithmetic findings on a refused publish. */
157+ const dateArithmeticIssues = ( err : any ) =>
158+ ( err ?. issues ?? [ ] ) . filter ( ( i : any ) => i . rule === 'expression-invalid' && / ^ d a t e a r i t h m e t i c / . test ( i . message ) ) ;
159+
160+ /**
161+ * [#34946] The flow publish door refuses date arithmetic on a date field read
162+ * through `record.` / `previous.` in a flow condition, as it refuses the bare
163+ * name. The business case: an administrator publishes a record-triggered flow
164+ * on a loan that runs once the loan is a day past due (`record.due_date + 1 > 5`
165+ * written as if the date were a number). The run holds the field as its
166+ * `YYYY-MM-DD` text, the evaluator cannot add a number to it, and the flow
167+ * failed on every run while the door published it; the bare spelling was
168+ * refused. A `datetime` field takes exactly the bare name's verdict too, and an
169+ * ordering against `today()` still publishes.
170+ */
171+ describe ( '[#34946] the flow publish door refuses date arithmetic on a date field read through record. / previous.' , ( ) => {
172+ it ( '⭐ LIT — refuses the bare name, `record.` and `previous.` alike, with INVALID_METADATA / 422, leaving the draft' , async ( ) => {
173+ const rig = await boot ( ) ;
174+ for ( const [ name , read ] of [
175+ [ 'loan_due_bare' , 'due_date' ] ,
176+ [ 'loan_due_record' , 'record.due_date' ] ,
177+ [ 'loan_due_previous' , 'previous.due_date' ] ,
178+ ] as const ) {
179+ const err : any = await rig . publish ( flowOn ( name , `${ read } + 1 > 5` ) ) ;
180+ expect ( err , `${ read } : the publish was admitted` ) . toBeInstanceOf ( Error ) ;
181+ expect ( { code : err . code , status : err . status } , read ) . toEqual ( { code : 'INVALID_METADATA' , status : 422 } ) ;
182+ const issues = dateArithmeticIssues ( err ) ;
183+ expect ( issues , `${ read } : ${ JSON . stringify ( err . issues ) } ` ) . toHaveLength ( 1 ) ;
184+ expect ( issues [ 0 ] . message ) . toContain ( `date arithmetic \`google.protobuf.Timestamp + int\` — \`${ read } \` is a date` ) ;
185+ expect ( await rig . state ( name ) , read ) . toEqual ( [ 'draft' ] ) ;
186+ }
187+ } , 60_000 ) ;
188+
189+ it ( '⭐ CONTROL — a datetime field\'s root reads take the bare name\'s refusal, and an ordering against today() publishes' , async ( ) => {
190+ const rig = await boot ( ) ;
191+ for ( const [ name , read ] of [
192+ [ 'loan_picked_bare' , 'picked_up_at' ] ,
193+ [ 'loan_picked_record' , 'record.picked_up_at' ] ,
194+ [ 'loan_picked_previous' , 'previous.picked_up_at' ] ,
195+ ] as const ) {
196+ const err : any = await rig . publish ( flowOn ( name , `${ read } + 1 > 5` ) ) ;
197+ expect ( { code : err ?. code , status : err ?. status } , read ) . toEqual ( { code : 'INVALID_METADATA' , status : 422 } ) ;
198+ const issues = dateArithmeticIssues ( err ) ;
199+ expect ( issues , `${ read } : ${ JSON . stringify ( err ?. issues ) } ` ) . toHaveLength ( 1 ) ;
200+ expect ( issues [ 0 ] . message ) . toContain ( `date arithmetic \`google.protobuf.Timestamp + int\` — \`${ read } \` is a date` ) ;
201+ expect ( await rig . state ( name ) , read ) . toEqual ( [ 'draft' ] ) ;
202+ }
203+ const err = await rig . publish ( flowOn ( 'loan_due_ordering' , 'record.due_date < today()' ) ) ;
204+ expect ( err ?. issues ?? err , 'record.due_date < today(): the door refused' ) . toBeUndefined ( ) ;
205+ expect ( await rig . state ( 'loan_due_ordering' ) ) . toEqual ( [ 'active' ] ) ;
206+ } , 60_000 ) ;
207+ } ) ;
0 commit comments