| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | import { hasSeparateAttempt, projectCheckSections } from "./project-checks.ts"; |
| 4 | |
| 5 | test("a CLI-only fix keeps latest branch checks separate from the older production commit", () => { |
| 6 | assert.deepEqual(projectCheckSections("6049e67", "main", "a8f62b9"), [ |
| 7 | { kind: "branch", label: "Latest on main", sha: "6049e67" }, |
| 8 | { kind: "production", label: "Checks for deployed commit", sha: "a8f62b9" }, |
| 9 | ]); |
| 10 | }); |
| 11 | |
| 12 | test("the same commit is not reported twice, and a project without deployment still shows branch checks", () => { |
| 13 | const branch = [{ kind: "branch", label: "Latest on trunk", sha: "head" }]; |
| 14 | assert.deepEqual(projectCheckSections("head", "trunk", "head"), branch); |
| 15 | assert.deepEqual(projectCheckSections("head", "trunk", null), branch); |
| 16 | }); |
| 17 | |
| 18 | test("an unavailable branch head never mislabels deployed checks as latest branch checks", () => { |
| 19 | assert.deepEqual(projectCheckSections(null, "main", "old"), [{ kind: "production", label: "Checks for deployed commit", sha: "old" }]); |
| 20 | assert.deepEqual(projectCheckSections(null, null, null), []); |
| 21 | }); |
| 22 | |
| 23 | test("a failed same-commit retry does not replace the serving deployment", () => { |
| 24 | assert.equal(hasSeparateAttempt("dep_live", "abc", { id: "dep_retry", sha: "abc", state: "failure" }), true); |
| 25 | assert.equal(hasSeparateAttempt(null, "abc", { id: "dep_retry", sha: "abc", state: "failure" }), true); |
| 26 | assert.equal(hasSeparateAttempt("dep_live", "abc", { id: "dep_live", sha: "abc", state: "success" }), false); |
| 27 | assert.equal(hasSeparateAttempt(null, null, { id: "dep_first", sha: "abc", state: "in_progress" }), false); |
| 28 | }); |