All files / src/lib decision-order.ts

100% Statements 4/4
100% Branches 6/6
100% Functions 1/1
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16                      5795x 5795x 1040x    
// The ONE tie-break comparator for decision-event ordering (spec §2.4, parent
// ARCH-6). createdAt (DB now(), transaction-start-fixed) first; then CODE-UNIT
// id comparison — deliberately not localeCompare (host-locale-dependent). On
// the real id corpus (prefixed lowercase ULIDs, `event_` and `evt_`) this is
// sign-identical to both comparators it replaces; the property test asserts it.
export interface Ordered {
  id: string;
  createdAt: Date;
}
 
export function compareByCreatedAtThenId(a: Ordered, b: Ordered): number {
  const byTime = a.createdAt.getTime() - b.createdAt.getTime();
  if (byTime !== 0) return byTime;
  return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
}