Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Merge demo dry run fixes: settled checks, other attempts, queue links, clone box, activity feed, DEMO.md | 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; | |
| 3 | ||
| 4 | import type { Overlap } from "@g1t/contracts"; | |
| 5 | ||
| 6 | import { MAX_ATTEMPTS, attemptOutcome, attemptReview, otherAttempts, sharedPaths, splitOverlaps } from "./attempts.ts"; | |
| 7 | ||
| 8 | const overlap = (number: number, issue: number | null): Overlap => ({ number, title: `#${number}`, issue, paths: ["src/lib.rs"] }); | |
| 9 | ||
| 10 | test("overlaps for the same issue are alternatives; the rest are collisions", () => { | |
| 11 | const { collisions, alternatives } = splitOverlaps([overlap(3, 2), overlap(4, 7), overlap(5, null)], 2); | |
| 12 | assert.deepEqual(alternatives.map((o) => o.number), [3]); | |
| 13 | assert.deepEqual(collisions.map((o) => o.number), [4, 5]); | |
| 14 | // A pull request for no issue has no alternatives. | |
| 15 | assert.deepEqual(splitOverlaps([overlap(5, null)], null).alternatives, []); | |
| 16 | }); | |
| 17 | ||
| 18 | test("the other attempts are the issue's other pull requests, newest first, a few at most", () => { | |
| 19 | const pulls = [3, 9, 4, 12, 7, 8].map((number) => ({ number })); | |
| 20 | const others = otherAttempts(pulls, 9); | |
| 21 | assert.deepEqual(others, [12, 8, 7, 4]); | |
| 22 | assert.equal(others.length, MAX_ATTEMPTS); | |
| 23 | assert.deepEqual(otherAttempts([{ number: 9 }], 9), []); | |
| 24 | }); | |
| 25 | ||
| 26 | test("shared paths are the files both change", () => { | |
| 27 | assert.deepEqual( | |
| 28 | sharedPaths([{ path: "README.md" }, { path: "src/lib.rs" }, { path: "src/main.rs" }], [{ path: "src/main.rs" }, { path: "README.md" }]), | |
| 29 | ["README.md", "src/main.rs"], | |
| 30 | ); | |
| 31 | }); | |
| 32 | ||
| 33 | const said = (username: string, verdict: "approve" | "request_changes" | null) => ({ | |
| 34 | author: { id: `usr_${username}`, username }, | |
| 35 | verdict, | |
| 36 | }); | |
| 37 | ||
| 38 | test("a review stands at each reviewer's latest verdict, changes asked for first", () => { | |
| 39 | assert.deepEqual(attemptReview([said("g1t", "approve")], []), { state: "approved", text: "Approved by g1t" }); | |
| 40 | assert.deepEqual(attemptReview([said("g1t", "request_changes"), said("g1t", "approve"), said("ada", "approve")], []), { | |
| 41 | state: "approved", | |
| 42 | text: "Approved by g1t, ada", | |
| 43 | }); | |
| 44 | assert.deepEqual(attemptReview([said("g1t", "approve"), said("ada", "request_changes")], ["sam"]), { | |
| 45 | state: "changes_requested", | |
| 46 | text: "Changes requested by ada", | |
| 47 | }); | |
| 48 | assert.deepEqual(attemptReview([said("ada", null)], ["g1t"]), { state: "requested", text: "Review requested from g1t" }); | |
| 49 | assert.deepEqual(attemptReview([], []), { state: "none", text: "No review yet" }); | |
| 50 | }); | |
| 51 | ||
| 52 | test("an attempt's outcome says which was merged instead", () => { | |
| 53 | assert.equal(attemptOutcome({ status: "merged", supersededBy: null }), "Merged"); | |
| 54 | assert.equal(attemptOutcome({ status: "closed", supersededBy: 5 }), "Closed · #5 was merged instead"); | |
| 55 | assert.equal(attemptOutcome({ status: "closed", supersededBy: null }), "Closed without merging"); | |
| 56 | assert.equal(attemptOutcome({ status: "draft", supersededBy: null }), "Draft · in progress"); | |
| 57 | assert.equal(attemptOutcome({ status: "open", supersededBy: null }), "Open"); | |
| 58 | }); |
This file's history is long; its oldest lines are credited to the oldest commit read.