@@ -20,6 +20,47 @@ function entry(
2020}
2121
2222describe ( "dedupeChecks" , ( ) => {
23+ it . each ( [
24+ [ "2026-10-16T12:00:00Z" , "2026-10-16T12:00:00.500Z" ] ,
25+ [ "2026-10-16T12:00:00+02:00" , "2026-10-16T10:30:00Z" ] ,
26+ [ "2026-10-16T12:00:00.0001Z" , "2026-10-16T12:00:00.0002Z" ] ,
27+ [ "2026-10-16T12:00:00.0001z" , "2026-10-16T12:00:00.0002z" ] ,
28+ [ "2026-10-16T12:00:00.00009Z" , "2026-10-16T12:00:00.0001Z" ] ,
29+ [ "2024-02-28T23:59:59Z" , "2024-02-29T00:00:00.0001Z" ] ,
30+ [ "2000-02-28T23:59:59Z" , "2000-02-29T00:00:00Z" ] ,
31+ [ "2024-03-01T01:00:00Z" , "2024-02-29T23:30:00-02:00" ] ,
32+ [ "2026-10-16t12:00:00z" , "2026-10-16t12:00:00.0001z" ] ,
33+ [ "+010000-01-01T00:00:00Z" , "+010000-01-01T00:00:00.0001Z" ] ,
34+ ] ) ( "keeps the newer instant between %s and %s in either listing order" , ( older , newer ) => {
35+ const oldRun = entry ( "build" , "success" , { at : older } ) ;
36+ const newRun = entry ( "build" , "failure" , { at : newer } ) ;
37+
38+ expect (
39+ [
40+ [ oldRun , newRun ] ,
41+ [ newRun , oldRun ] ,
42+ ] . map ( ( runs ) => dedupeChecks ( runs ) [ 0 ] ?. status ) ,
43+ ) . toEqual ( [ "failure" , "failure" ] ) ;
44+ } ) ;
45+
46+ it . each ( [
47+ [ "2026-10-16T12:00:00Z" , "2026-10-16T12:00:00.000Z" ] ,
48+ [ "2026-10-16T12:00:00Z" , "2026-10-16T14:00:00+02:00" ] ,
49+ [ "2026-10-16T24:00:00.000Z" , "2026-10-17T00:00:00Z" ] ,
50+ [ "2026-10-16T12:00Z" , "2026-10-16T12:00:00Z" ] ,
51+ ] ) ( "takes the last copy for equal instants %s and %s" , ( first , second ) => {
52+ const forward = dedupeChecks ( [
53+ entry ( "build" , "success" , { at : first } ) ,
54+ entry ( "build" , "failure" , { at : second } ) ,
55+ ] ) ;
56+ const reversed = dedupeChecks ( [
57+ entry ( "build" , "success" , { at : second } ) ,
58+ entry ( "build" , "failure" , { at : first } ) ,
59+ ] ) ;
60+
61+ expect ( [ forward [ 0 ] ?. status , reversed [ 0 ] ?. status ] ) . toEqual ( [ "failure" , "failure" ] ) ;
62+ } ) ;
63+
2364 it ( "keeps the newest run of a check the host listed twice" , ( ) => {
2465 const checks = dedupeChecks ( [
2566 entry ( "Prepare PR size config" , "success" , {
@@ -37,6 +78,48 @@ describe("dedupeChecks", () => {
3778 ] ) ;
3879 } ) ;
3980
81+ it ( "preserves text ordering when a host supplies an unparseable timestamp" , ( ) => {
82+ expect (
83+ dedupeChecks ( [
84+ entry ( "build" , "success" , { at : "invalid-a" } ) ,
85+ entry ( "build" , "failure" , { at : "invalid-b" } ) ,
86+ ] ) . map ( ( check ) => check . status ) ,
87+ ) . toEqual ( [ "failure" ] ) ;
88+ } ) ;
89+
90+ it . each ( [
91+ [ "2026-10-16" , "2026-10-15T23:00:00-02:00" , "success" ] ,
92+ [ "2026-10-16T00:00:00" , "2026-10-15T23:00:00-02:00" , "success" ] ,
93+ [ "2026-10-16T24:00:00.0001Z" , "2026-10-17T00:00:00Z" , "failure" ] ,
94+ ] ) ( "uses text fallback for incomplete or invalid timestamp %s" , ( malformed , valid , expected ) => {
95+ const malformedRun = entry ( "build" , "success" , { at : malformed } ) ;
96+ const validRun = entry ( "build" , "failure" , { at : valid } ) ;
97+
98+ expect (
99+ [
100+ [ malformedRun , validRun ] ,
101+ [ validRun , malformedRun ] ,
102+ ] . map ( ( runs ) => dedupeChecks ( runs ) [ 0 ] ?. status ) ,
103+ ) . toEqual ( [ expected , expected ] ) ;
104+ } ) ;
105+
106+ it . each ( [
107+ [ "2026-02-30T00:00:00Z" , "2026-03-01T00:00:00Z" ] ,
108+ [ "2026-02-29T00:00:00Z" , "2026-03-01T00:00:00Z" ] ,
109+ [ "1900-02-29T00:00:00Z" , "1900-03-01T00:00:00Z" ] ,
110+ [ "2026-04-31T00:00:00.0001-02:00" , "2026-05-01T00:00:00Z" ] ,
111+ ] ) ( "uses text fallback for impossible date %s" , ( malformed , valid ) => {
112+ const malformedRun = entry ( "build" , "success" , { at : malformed } ) ;
113+ const validRun = entry ( "build" , "failure" , { at : valid } ) ;
114+
115+ expect (
116+ [
117+ [ malformedRun , validRun ] ,
118+ [ validRun , malformedRun ] ,
119+ ] . map ( ( runs ) => dedupeChecks ( runs ) [ 0 ] ?. status ) ,
120+ ) . toEqual ( [ "failure" , "failure" ] ) ;
121+ } ) ;
122+
40123 it ( "holds a check at the place it first appeared, so a re-run does not reshuffle the list" , ( ) => {
41124 const checks = dedupeChecks ( [
42125 entry ( "lint" , "success" , { workflowName : "CI" , at : "2026-08-11T16:00:00Z" } ) ,
0 commit comments