@@ -20,6 +20,40 @@ 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+ ] ) ( "keeps the newer instant between %s and %s in either listing order" , ( older , newer ) => {
30+ const oldRun = entry ( "build" , "success" , { at : older } ) ;
31+ const newRun = entry ( "build" , "failure" , { at : newer } ) ;
32+
33+ expect (
34+ [
35+ [ oldRun , newRun ] ,
36+ [ newRun , oldRun ] ,
37+ ] . map ( ( runs ) => dedupeChecks ( runs ) [ 0 ] ?. status ) ,
38+ ) . toEqual ( [ "failure" , "failure" ] ) ;
39+ } ) ;
40+
41+ it . each ( [
42+ [ "2026-10-16T12:00:00Z" , "2026-10-16T12:00:00.000Z" ] ,
43+ [ "2026-10-16T12:00:00Z" , "2026-10-16T14:00:00+02:00" ] ,
44+ ] ) ( "takes the last copy for equal instants %s and %s" , ( first , second ) => {
45+ const forward = dedupeChecks ( [
46+ entry ( "build" , "success" , { at : first } ) ,
47+ entry ( "build" , "failure" , { at : second } ) ,
48+ ] ) ;
49+ const reversed = dedupeChecks ( [
50+ entry ( "build" , "success" , { at : second } ) ,
51+ entry ( "build" , "failure" , { at : first } ) ,
52+ ] ) ;
53+
54+ expect ( [ forward [ 0 ] ?. status , reversed [ 0 ] ?. status ] ) . toEqual ( [ "failure" , "failure" ] ) ;
55+ } ) ;
56+
2357 it ( "keeps the newest run of a check the host listed twice" , ( ) => {
2458 const checks = dedupeChecks ( [
2559 entry ( "Prepare PR size config" , "success" , {
@@ -37,6 +71,15 @@ describe("dedupeChecks", () => {
3771 ] ) ;
3872 } ) ;
3973
74+ it ( "preserves text ordering when a host supplies an unparseable timestamp" , ( ) => {
75+ expect (
76+ dedupeChecks ( [
77+ entry ( "build" , "success" , { at : "invalid-a" } ) ,
78+ entry ( "build" , "failure" , { at : "invalid-b" } ) ,
79+ ] ) . map ( ( check ) => check . status ) ,
80+ ) . toEqual ( [ "failure" ] ) ;
81+ } ) ;
82+
4083 it ( "holds a check at the place it first appeared, so a re-run does not reshuffle the list" , ( ) => {
4184 const checks = dedupeChecks ( [
4285 entry ( "lint" , "success" , { workflowName : "CI" , at : "2026-08-11T16:00:00Z" } ) ,
0 commit comments