Skip to content

Commit 35fe940

Browse files
committed
fix(source-control): validate check timestamp calendar dates
1 parent e5c3920 commit 35fe940

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎packages/source-control-core/src/server/pullRequestChecks.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ describe("dedupeChecks", () => {
2626
["2026-10-16T12:00:00.0001Z", "2026-10-16T12:00:00.0002Z"],
2727
["2026-10-16T12:00:00.0001z", "2026-10-16T12:00:00.0002z"],
2828
["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"],
2932
])("keeps the newer instant between %s and %s in either listing order", (older, newer) => {
3033
const oldRun = entry("build", "success", { at: older });
3134
const newRun = entry("build", "failure", { at: newer });
@@ -80,6 +83,23 @@ describe("dedupeChecks", () => {
8083
).toEqual(["failure"]);
8184
});
8285

86+
it.each([
87+
["2026-02-30T00:00:00Z", "2026-03-01T00:00:00Z"],
88+
["2026-02-29T00:00:00Z", "2026-03-01T00:00:00Z"],
89+
["1900-02-29T00:00:00Z", "1900-03-01T00:00:00Z"],
90+
["2026-04-31T00:00:00.0001-02:00", "2026-05-01T00:00:00Z"],
91+
])("uses text fallback for impossible date %s", (malformed, valid) => {
92+
const malformedRun = entry("build", "success", { at: malformed });
93+
const validRun = entry("build", "failure", { at: valid });
94+
95+
expect(
96+
[
97+
[malformedRun, validRun],
98+
[validRun, malformedRun],
99+
].map((runs) => dedupeChecks(runs)[0]?.status),
100+
).toEqual(["failure", "failure"]);
101+
});
102+
83103
it("holds a check at the place it first appeared, so a re-run does not reshuffle the list", () => {
84104
const checks = dedupeChecks([
85105
entry("lint", "success", { workflowName: "CI", at: "2026-08-11T16:00:00Z" }),

‎packages/source-control-core/src/server/pullRequestChecks.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
import type { PullRequestCheck } from "@t3tools/contracts";
2+
import * as DateTime from "effect/DateTime";
3+
import * as Option from "effect/Option";
24

35
// Parse whole seconds separately so sub-millisecond fractions keep their precision.
46
function timestampParts(value: string) {
57
const fraction = /\.(\d+)(?=Z$|[+-]\d{2}:\d{2}$)/i.exec(value);
8+
// Date can normalize impossible days. Check the calendar date before applying the offset.
9+
const datePart = value.split(/[Tt]/, 1)[0] ?? "";
10+
const date = DateTime.make(`${datePart}T00:00:00Z`);
11+
const parts = Option.isSome(date) ? DateTime.toPartsUtc(date.value) : null;
12+
const validDate =
13+
parts !== null &&
14+
parts.month === Number(datePart.slice(-5, -3)) &&
15+
parts.day === Number(datePart.slice(-2));
616
return {
7-
time: Date.parse(fraction ? value.replace(fraction[0], "") : value),
17+
time: validDate ? Date.parse(fraction ? value.replace(fraction[0], "") : value) : Number.NaN,
818
fraction: fraction?.[1] ?? "",
919
};
1020
}

0 commit comments

Comments
 (0)