Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

62 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import type { CheckItem } from "@g1t/contracts";
5
6import { checkDetail, checksHeadline, checksTally, detailsLink, took } from "./commit-checks.ts";
7
8const item = (over: Partial<CheckItem>): CheckItem => ({
9 kind: "check_run",
10 id: "cr_1",
11 name: "lint",
12 state: "success",
13 description: null,
14 detailsUrl: null,
15 url: null,
16 app: null,
17 startedAt: null,
18 completedAt: null,
19 ...over,
20});
21
22test("the headline says the worst of a commit's checks", () => {
23 assert.equal(checksHeadline({ state: "success" }), "All checks have passed");
24 assert.equal(checksHeadline({ state: "failure" }), "Some checks were not successful");
25 assert.equal(checksHeadline({ state: "pending" }), "Some checks haven't completed yet");
26});
27
28test("the tally counts each kind, worst first", () => {
29 assert.equal(checksTally({ total: 2, successful: 2, failed: 0, pending: 0, skipped: 0 }), "2 successful checks");
30 assert.equal(checksTally({ total: 1, successful: 1, failed: 0, pending: 0, skipped: 0 }), "1 successful check");
31 assert.equal(checksTally({ total: 4, successful: 2, failed: 1, pending: 1, skipped: 0 }), "1 failing, 1 in progress and 2 successful checks");
32});
33
34test("a check run says how it went and how long it took", () => {
35 const started = "2026-10-07T14:00:00Z";
36 assert.equal(took(started, "2026-10-07T14:00:25Z"), "25s");
37 assert.equal(took(started, "2026-10-07T14:01:12Z"), "1m 12s");
38 assert.equal(took(started, null), "");
39 assert.equal(checkDetail(item({ startedAt: started, completedAt: "2026-10-07T14:00:25Z" })), "Successful in 25s");
40 assert.equal(
41 checkDetail(item({ state: "failure", startedAt: started, completedAt: "2026-10-07T14:00:12Z", description: "2 problems" })),
42 "Failing after 12s — 2 problems",
43 );
44 assert.equal(checkDetail(item({ state: "pending" })), "Queued");
45 assert.equal(checkDetail(item({ state: "pending", startedAt: started })), "In progress");
46 assert.equal(checkDetail(item({ kind: "status", description: "Deployment has completed" })), "Deployment has completed");
47 assert.equal(checkDetail(item({ kind: "status", state: "skipped" })), "Skipped");
48});
49
50test("details go to g1t's own page first, and elsewhere apart", () => {
51 assert.deepEqual(detailsLink(item({ url: "/acme/web/checks/cr_1", detailsUrl: "https://ci.example.com/1" })), {
52 href: "/acme/web/checks/cr_1",
53 external: false,
54 });
55 assert.deepEqual(detailsLink(item({ detailsUrl: "https://g1t.sh/acme/web/actions/runs/run_1" })), {
56 href: "/acme/web/actions/runs/run_1",
57 external: false,
58 });
59 assert.deepEqual(detailsLink(item({ detailsUrl: "https://vercel.com/acme/web/1" })), { href: "https://vercel.com/acme/web/1", external: true });
60 assert.equal(detailsLink(item({ detailsUrl: "javascript:alert(1)" })), null);
61 assert.equal(detailsLink(item({})), null);
62});