|
| 1 | +// Requires PostgreSQL at localhost:5432 (docs/DEV.md). |
| 2 | +import { afterAll, expect, mock, test } from "bun:test"; |
| 3 | +import { emptyPack, VERDICT_LABELS } from "@corbits/triage-contracts"; |
| 4 | +import { comments, labelled, OWNER, pullOf, sha } from "../chain/github.ts"; |
| 5 | +import { modelStack } from "./stack.ts"; |
| 6 | + |
| 7 | +const MANAGER_RELEASE = { workflow: { assetId: "ast_triage-manager-github", commitSha: "c0ffee", packageName: "@corbits/triage-manager", entry: "./triage-manager-github.mjs" }, offerings: { ids: ["off_model"], defaultId: "off_model" } }; |
| 8 | +mock.module(new URL("../../packages/triage-manager/src/release.json", import.meta.url).pathname, () => ({ default: { github: { manager: MANAGER_RELEASE } } })); |
| 9 | + |
| 10 | +const REPO = `${OWNER}/one`; |
| 11 | +// Under `ask`, the pr-triage role holds only posting: its labels and its comment. |
| 12 | +const stack = await modelStack(REPO, { pack: { ...emptyPack(REPO), checks: { "max-files-changed": { enabled: true } } }, automatic: ["labels", "comment"] }); |
| 13 | +afterAll(() => stack.stop()); |
| 14 | + |
| 15 | +test("one pull request opened runs its listener and manager to one verdict, its label, and no run left live", async () => { |
| 16 | + const head = sha("one-1"); |
| 17 | + await stack.opened(pullOf(1, head)); |
| 18 | + const ran = await stack.drain(); |
| 19 | + |
| 20 | + const writes = stack.github.writesTo(REPO, 1); |
| 21 | + expect(stack.github.misses).toEqual([]); |
| 22 | + expect(ran.map((run) => run.status)).toEqual(["completed", "completed"]); |
| 23 | + expect(comments(writes)).toEqual([expect.stringContaining("**Triage: Pass**")]); |
| 24 | + expect(labelled(writes)).toEqual([VERDICT_LABELS.pass]); |
| 25 | + expect(await stack.claimOf(1)).toMatchObject({ status: "ended", history: [{ head }] }); |
| 26 | + expect(await stack.liveManagers()).toEqual([]); |
| 27 | + expect(stack.queue).toEqual([]); |
| 28 | + expect(await stack.verdicts(1)).toEqual([expect.objectContaining({ head_sha: head, run_status: "completed" })]); |
| 29 | +}); |
0 commit comments