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.

g1t.sh
34 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import test from "node:test";
3import { deliveryDays, deliveryTotals, duration, projectCosts, usageKey } from "./workspace-insights.ts";
4import type { DeliveryMetrics, UsageReport } from "@g1t/contracts";
5
6test("workspace averages weight samples rather than averaging project averages", () => {
7 const empty: DeliveryMetrics = { repoId: "a", opened: 0, merged: 0, active: 0, unreviewed: 0, checking: 0, failed: 0, queued: 0, leadSeconds: 0, reviewSeconds: 0, reviewed: 0 };
8 const total = deliveryTotals([{ ...empty, merged: 1, leadSeconds: 100 }, { ...empty, repoId: "b", merged: 9, leadSeconds: 9000 }]);
9 assert.equal(total.leadSeconds / total.merged, 910);
10 assert.equal(deliveryTotals([]).merged, 0);
11});
12
13test("costs combine meters and products without conflating project keys", () => {
14 const report = { products: [{ meters: [{ byProject: [{ project: "a/one", micros: 3 }, { project: "a/two", micros: 7 }] }] }, { meters: [{ byProject: [{ project: "a/one", micros: 11 }] }] }] } as UsageReport;
15 assert.deepEqual([...projectCosts(report)], [["a/one", 14], ["a/two", 7]]);
16 assert.equal(projectCosts(null).size, 0);
17});
18
19test("a project's usage is its repository's, not its slug's", () => {
20 assert.equal(usageKey({ namespace: "Acme", name: "Web-App" }), "acme/web-app");
21});
22
23test("missing duration is distinct from a fast change", () => {
24 assert.equal(duration(null), "—");
25 assert.equal(duration(0), "<1m");
26 assert.equal(duration(7200), "2.0h");
27 assert.equal(duration(172800), "2.0d");
28});
29
30test("daily series combines batches and retains quiet days across month boundaries", () => {
31 assert.deepEqual(deliveryDays("2026-09-30", "2026-10-02", [{ day: "2026-10-01", merged: 2 }, { day: "2026-10-01", merged: 3 }]), [
32 { day: "2026-09-30", merged: 0 }, { day: "2026-10-01", merged: 5 }, { day: "2026-10-02", merged: 0 },
33 ]);
34});