From c5f9fab13a960e0f920f177133b593c494f1f68c Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 6 Jun 2026 03:16:19 +0000 Subject: [PATCH 1/2] test: add tests for getMostActiveHour edge cases Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com> --- src/lib/__tests__/yearInReviewUtils.test.ts | 43 +++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/lib/__tests__/yearInReviewUtils.test.ts b/src/lib/__tests__/yearInReviewUtils.test.ts index c964d7bc..8f0256bc 100644 --- a/src/lib/__tests__/yearInReviewUtils.test.ts +++ b/src/lib/__tests__/yearInReviewUtils.test.ts @@ -78,6 +78,31 @@ describe("buildHourlyHeatmapFromCommitDates", () => { describe("getMostActiveHour", () => { + it("returns 0 if heatmap does not have 7 rows", () => { + const heatmap = Array.from({ length: 6 }, () => Array.from({ length: 24 }, () => 0)); + expect(getMostActiveHour(heatmap)).toBe(0); + }); + + it("returns 0 if a row does not have 24 hours", () => { + const heatmap = Array.from({ length: 7 }, () => Array.from({ length: 24 }, () => 0)); + heatmap[0] = Array.from({ length: 23 }, () => 0); + expect(getMostActiveHour(heatmap)).toBe(0); + }); + + it("returns 0 if a row is not an array", () => { + // @ts-expect-error Intentionally invalid input + const heatmap: number[][] = Array.from({ length: 7 }, () => Array.from({ length: 24 }, () => 0)); + // @ts-expect-error Intentionally invalid input + heatmap[0] = "not-an-array"; + expect(getMostActiveHour(heatmap)).toBe(0); + }); + + it("returns 0 if an element in a row is not finite", () => { + const heatmap = Array.from({ length: 7 }, () => Array.from({ length: 24 }, () => 0)); + heatmap[0][0] = NaN; + expect(getMostActiveHour(heatmap)).toBe(0); + }); + it("returns 0 if heatmap is malformed (not 7x24 matrix)", () => { expect(getMostActiveHour([])).toBe(0); expect(getMostActiveHour([[1,2,3]])).toBe(0); @@ -176,6 +201,18 @@ describe("getMostActiveDayFromCalendar", () => { }); describe("buildHourlyHeatmapFromCommitDates - edge cases", () => { + it("falls back to full date parsing when fast path check fails", () => { + const commitDates = ["2023-01-01T10:00:00+00:00"]; // Invalid timezone ending format for fast path, uses T but not Z + const heatmap = buildHourlyHeatmapFromCommitDates(commitDates); + expect(heatmap[0][10]).toBe(1); + }); + + it("falls back to full date parsing when new Date parsing fails", () => { + const commitDates = ["2023-13-45T10:00:00Z"]; // Invalid date part + const heatmap = buildHourlyHeatmapFromCommitDates(commitDates); + expect(heatmap.flat().reduce((sum, count) => sum + count, 0)).toBe(0); + }); + it("falls back to full string parsing for unparseable hour data", () => { const heatmap = buildHourlyHeatmapFromCommitDates(["2023-01-01TX0:00:00Z"]); const totalCommits = heatmap.flat().reduce((sum, count) => sum + count, 0); @@ -210,4 +247,10 @@ describe("buildHourlyHeatmapFromCommitDates - edge cases", () => { const heatmap = buildHourlyHeatmapFromCommitDates(commitDates); expect(heatmap[0][10]).toBe(0); }); + + it("falls back to full date parsing when timezone check fails parsing", () => { + const commitDates = ["2023-01-01T10:00:00+XX:XX"]; + const heatmap = buildHourlyHeatmapFromCommitDates(commitDates); + expect(heatmap.flat().reduce((sum, count) => sum + count, 0)).toBe(0); + }); }); From 4620094ba534e0abdd359282683735f930c7f351 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 6 Jun 2026 03:19:34 +0000 Subject: [PATCH 2/2] test: remove unused ts-expect-error directive Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com> --- src/lib/__tests__/yearInReviewUtils.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/__tests__/yearInReviewUtils.test.ts b/src/lib/__tests__/yearInReviewUtils.test.ts index 8f0256bc..3f99bf4d 100644 --- a/src/lib/__tests__/yearInReviewUtils.test.ts +++ b/src/lib/__tests__/yearInReviewUtils.test.ts @@ -90,7 +90,6 @@ describe("getMostActiveHour", () => { }); it("returns 0 if a row is not an array", () => { - // @ts-expect-error Intentionally invalid input const heatmap: number[][] = Array.from({ length: 7 }, () => Array.from({ length: 24 }, () => 0)); // @ts-expect-error Intentionally invalid input heatmap[0] = "not-an-array";