Open History to see the last commit
1import type { PullRequestCheck, PullRequestCheckStatus } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3
4import { dedupeChecks } from "./pullRequestChecks.ts";
5
6function entry(
7 name: string,
8 status: PullRequestCheckStatus,
9 extra: { readonly workflowName?: string | null; readonly at?: string | null } = {},
10): {
11 readonly check: PullRequestCheck;
12 readonly workflowName: string | null;
13 readonly at: string | null;
14} {
15 return {
16 check: { name, status, description: null, url: null },
17 workflowName: extra.workflowName ?? null,
18 at: extra.at ?? null,
19 };
20}
21
22describe("dedupeChecks", () => {
23 it("keeps the newest run of a check the host listed twice", () => {
24 const checks = dedupeChecks([
25 entry("Prepare PR size config", "success", {
26 workflowName: "PR Size",
27 at: "2026-08-11T16:06:25Z",
28 }),
29 entry("Prepare PR size config", "pending", {
30 workflowName: "PR Size",
31 at: "2026-08-11T17:01:04Z",
32 }),
33 ]);
34
35 expect(checks.map((check) => [check.name, check.status])).toEqual([
36 ["Prepare PR size config", "pending"],
37 ]);
38 });
39
40 it("holds a check at the place it first appeared, so a re-run does not reshuffle the list", () => {
41 const checks = dedupeChecks([
42 entry("lint", "success", { workflowName: "CI", at: "2026-08-11T16:00:00Z" }),
43 entry("test", "success", { workflowName: "CI", at: "2026-08-11T16:00:00Z" }),
44 entry("lint", "failure", { workflowName: "CI", at: "2026-08-11T18:00:00Z" }),
45 ]);
46
47 expect(checks.map((check) => [check.name, check.status])).toEqual([
48 ["lint", "failure"],
49 ["test", "success"],
50 ]);
51 });
52
53 it("loses a run that never said when it happened to one that did, whichever came first", () => {
54 const undated = dedupeChecks([
55 entry("build", "success", { at: "2026-08-11T16:00:00Z" }),
56 entry("build", "pending"),
57 ]);
58 const dated = dedupeChecks([
59 entry("build", "pending"),
60 entry("build", "success", { at: "2026-08-11T16:00:00Z" }),
61 ]);
62
63 expect([undated[0]?.status, dated[0]?.status]).toEqual(["success", "success"]);
64 });
65
66 it("takes the last copy when neither run is dated, which is how an update is listed", () => {
67 const checks = dedupeChecks([entry("build", "pending"), entry("build", "failure")]);
68
69 expect(checks.map((check) => check.status)).toEqual(["failure"]);
70 });
71
72 it("keeps two workflows that name a job the same thing, and says which is which", () => {
73 const checks = dedupeChecks([
74 entry("build", "success", { workflowName: "CI", at: "2026-08-11T16:00:00Z" }),
75 entry("build", "failure", { workflowName: "Release", at: "2026-08-11T16:00:00Z" }),
76 ]);
77
78 expect(checks.map((check) => [check.name, check.status])).toEqual([
79 ["CI / build", "success"],
80 ["Release / build", "failure"],
81 ]);
82 });
83
84 it("leaves a colliding check with no workflow of its own unqualified", () => {
85 // An app-provided check run belongs to no workflow, which GitHub reports as an empty name.
86 const checks = dedupeChecks([
87 entry("build", "success", { workflowName: "", at: "2026-08-11T16:00:00Z" }),
88 entry("build", "failure", { workflowName: "CI", at: "2026-08-11T16:00:00Z" }),
89 ]);
90
91 expect(checks.map((check) => check.name)).toEqual(["build", "CI / build"]);
92 });
93});