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.

76 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import type { Overlap } from "@g1t/contracts";
5
6import { MAX_ATTEMPTS, attemptOutcome, attemptReview, otherAttempts, sharedPaths, splitOverlaps } from "./attempts.ts";
7
8const overlap = (number: number, item: number | null): Overlap => ({ number, title: `#${number}`, item, paths: ["src/lib.rs"] });
9
10test("overlaps for the same work item are alternatives; the rest are collisions", () => {
11 const { collisions, alternatives } = splitOverlaps([overlap(3, 2), overlap(4, 7), overlap(5, null)], 2);
12 assert.deepEqual(
13 alternatives.map((o) => o.number),
14 [3],
15 );
16 assert.deepEqual(
17 collisions.map((o) => o.number),
18 [4, 5],
19 );
20 // A pull request for no work item has no alternatives.
21 assert.deepEqual(splitOverlaps([overlap(5, null)], null).alternatives, []);
22});
23
24test("the other attempts are the work item's other pull requests, newest first, a few at most", () => {
25 const pulls = [3, 9, 4, 12, 7, 8].map((number) => ({ number }));
26 const others = otherAttempts(pulls, 9);
27 assert.deepEqual(others, [12, 8, 7, 4]);
28 assert.equal(others.length, MAX_ATTEMPTS);
29 assert.deepEqual(otherAttempts([{ number: 9 }], 9), []);
30});
31
32test("shared paths are the files both change", () => {
33 assert.deepEqual(sharedPaths([{ path: "README.md" }, { path: "src/lib.rs" }, { path: "src/main.rs" }], [{ path: "src/main.rs" }, { path: "README.md" }]), [
34 "README.md",
35 "src/main.rs",
36 ]);
37});
38
39const said = (username: string, verdict: "approve" | "request_changes" | null) => ({
40 author: { id: `usr_${username}`, username },
41 verdict,
42});
43
44test("a review stands at each reviewer's latest verdict, changes asked for first", () => {
45 assert.deepEqual(attemptReview([said("g1t", "approve")], []), { state: "approved", text: "Approved by g1t" });
46 assert.deepEqual(attemptReview([said("g1t", "request_changes"), said("g1t", "approve"), said("ada", "approve")], []), {
47 state: "approved",
48 text: "Approved by g1t, ada",
49 });
50 assert.deepEqual(attemptReview([said("g1t", "approve"), said("ada", "request_changes")], ["sam"]), {
51 state: "changes_requested",
52 text: "Changes requested by ada",
53 });
54 assert.deepEqual(attemptReview([said("ada", null)], ["g1t"]), { state: "requested", text: "Review requested from g1t" });
55 assert.deepEqual(attemptReview([], []), { state: "none", text: "No review yet" });
56});
57
58test("an attempt's outcome says which was merged instead", () => {
59 assert.equal(attemptOutcome({ status: "merged", supersededBy: null }), "Merged");
60 assert.equal(attemptOutcome({ status: "closed", supersededBy: 5 }), "Closed · #5 was merged instead");
61 assert.equal(attemptOutcome({ status: "closed", supersededBy: null }), "Closed without merging");
62 assert.equal(attemptOutcome({ status: "draft", supersededBy: null }), "Draft · in progress");
63 assert.equal(attemptOutcome({ status: "open", supersededBy: null }), "Open");
64});
65
66test("an agent's review is advisory: it neither approves nor asks for changes", () => {
67 const margo = { id: "agt_1", handle: "margo", displayName: "Margo", avatarSeed: "margo" };
68 const advisory = (verdict: "approve" | "request_changes") => ({
69 author: { id: "agt_1", username: "margo" },
70 verdict,
71 agent: margo,
72 advisory: true,
73 });
74 assert.deepEqual(attemptReview([advisory("approve")], []), { state: "none", text: "No review yet" });
75 assert.deepEqual(attemptReview([advisory("request_changes")], ["ada"]), { state: "requested", text: "Review requested from ada" });
76});