| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { madeByG1t, openedBy } from "./opened-by.ts"; |
| 5 | |
| 6 | const author = { id: "usr_1", username: "syntaqx" }; |
| 7 | |
| 8 | test("a pull request g1t's agent made in a fork shows g1t, requested by its author", () => { |
| 9 | const pull = { agent: "g1t", branch: null, author }; |
| 10 | assert.equal(madeByG1t(pull), true); |
| 11 | assert.deepEqual(openedBy(pull), { name: "g1t", requestedBy: "syntaqx" }); |
| 12 | }); |
| 13 | |
| 14 | test("anything else shows its author", () => { |
| 15 | // Someone's own agent. |
| 16 | assert.deepEqual(openedBy({ agent: "claude-code", branch: null, author }), { name: "syntaqx", requestedBy: null }); |
| 17 | // A branch pushed to the repository, even with g1t named on it. |
| 18 | assert.equal(madeByG1t({ agent: "g1t", branch: "fix-login" }), false); |
| 19 | assert.deepEqual(openedBy({ agent: "g1t", branch: "fix-login", author }), { name: "syntaqx", requestedBy: null }); |
| 20 | }); |
| 21 | |
| 22 | test("work g1t started itself names nobody as asking", () => { |
| 23 | const pull = { agent: "g1t", branch: null, author: { id: "g1t", username: "g1t" } }; |
| 24 | assert.deepEqual(openedBy(pull), { name: "g1t", requestedBy: null }); |
| 25 | }); |