From e665888a45d933c229aefe73c2a05e125290b983 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 13 Mar 2026 21:51:01 +0000 Subject: [PATCH] test: tighten shared usage aggregate coverage --- src/shared/usage-aggregates.test.ts | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/shared/usage-aggregates.test.ts b/src/shared/usage-aggregates.test.ts index e5ba960ad95..dc6896b7490 100644 --- a/src/shared/usage-aggregates.test.ts +++ b/src/shared/usage-aggregates.test.ts @@ -16,6 +16,13 @@ describe("shared/usage-aggregates", () => { }; mergeUsageLatency(totals, undefined); + mergeUsageLatency(totals, { + count: 0, + avgMs: 999, + minMs: 1, + maxMs: 999, + p95Ms: 999, + }); mergeUsageLatency(totals, { count: 2, avgMs: 50, @@ -51,6 +58,7 @@ describe("shared/usage-aggregates", () => { { date: "2026-03-12", count: 1, avgMs: 120, minMs: 120, maxMs: 120, p95Ms: 120 }, { date: "2026-03-11", count: 1, avgMs: 30, minMs: 30, maxMs: 30, p95Ms: 30 }, ]); + mergeUsageDailyLatency(dailyLatencyMap, null); const tail = buildUsageAggregateTail({ byChannelMap: new Map([ @@ -114,4 +122,38 @@ describe("shared/usage-aggregates", () => { expect(tail.latency).toBeUndefined(); expect(tail.dailyLatency).toEqual([]); }); + + it("normalizes zero-count daily latency entries to zero averages and mins", () => { + const dailyLatencyMap = new Map([ + [ + "2026-03-12", + { + date: "2026-03-12", + count: 0, + sum: 0, + min: Number.POSITIVE_INFINITY, + max: 0, + p95Max: 0, + }, + ], + ]); + + const tail = buildUsageAggregateTail({ + byChannelMap: new Map(), + latencyTotals: { + count: 0, + sum: 0, + min: Number.POSITIVE_INFINITY, + max: 0, + p95Max: 0, + }, + dailyLatencyMap, + modelDailyMap: new Map(), + dailyMap: new Map(), + }); + + expect(tail.dailyLatency).toEqual([ + { date: "2026-03-12", count: 0, avgMs: 0, minMs: 0, maxMs: 0, p95Ms: 0 }, + ]); + }); });