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.

66 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { describe, it } from "node:test";
3
4import type { RepoChange } from "@g1t/contracts";
5
6import { arrivedOf, homeShows, type HomeRepo } from "./home-live.ts";
7
8const repos: HomeRepo[] = [{ id: "r1", path: "acme/web", defaultBranch: "main" }];
9const change = (kind: string, extra: Partial<RepoChange> = {}): RepoChange => ({ repo_id: "r1", kind, at: "2026-10-15T00:00:00Z", ...extra });
10
11describe("homeShows", () => {
12 it("takes a default branch's pushes and tags, not another branch's", () => {
13 assert.equal(homeShows(change("git.push", { ref: "refs/heads/main" }), repos), true);
14 assert.equal(homeShows(change("git.push", { ref: "refs/tags/v1.0.0" }), repos), true);
15 assert.equal(homeShows(change("git.push", { ref: "refs/heads/feature" }), repos), false);
16 });
17
18 it("takes any branch's push where the default branch is not known", () => {
19 assert.equal(homeShows({ ...change("git.push", { ref: "refs/heads/feature" }), repo_id: "other" }, repos), true);
20 });
21
22 it("takes what Home lists and leaves a commit's checks", () => {
23 for (const kind of [
24 "pull.merged",
25 "review.submitted",
26 "work_item.opened",
27 "comment.created",
28 "workflow.completed",
29 "run.updated",
30 "deployment_status.created",
31 "release.published",
32 "session.started",
33 "session.ended",
34 ]) {
35 assert.equal(homeShows(change(kind), repos), true, kind);
36 }
37 for (const kind of ["status.created", "check_run.completed", "check_suite.completed", "checks.completed", "session.progressed", "git.deleted"]) {
38 assert.equal(homeShows(change(kind), repos), false, kind);
39 }
40 });
41});
42
43describe("arrivedOf", () => {
44 it("finds nothing new on the first draw", () => {
45 const { arrived, seen } = arrivedOf(null, "last", ["a", "b"]);
46 assert.deepEqual([...arrived], []);
47 assert.deepEqual([...seen.keys], ["a", "b"]);
48 });
49
50 it("finds the rows that were not shown before", () => {
51 const first = arrivedOf(null, "last", ["a", "b"]).seen;
52 const { arrived } = arrivedOf(first, "last", ["c", "a", "b"]);
53 assert.deepEqual([...arrived], ["c"]);
54 });
55
56 it("does not count a row that went and came back as new", () => {
57 const first = arrivedOf(null, "last", ["a", "b"]).seen;
58 const second = arrivedOf(first, "last", ["b"]).seen;
59 assert.deepEqual([...arrivedOf(second, "last", ["a", "b"]).arrived], []);
60 });
61
62 it("starts over when the span switches", () => {
63 const first = arrivedOf(null, "last", ["a"]).seen;
64 assert.deepEqual([...arrivedOf(first, "7d", ["a", "b", "c"]).arrived], []);
65 });
66});