iara-pwa/tests/unit/github-pr-flow.test.ts
Francisco Solla 8d4a944127 feat(ci): CI/PR no GitHub Actions — tracker de Issues permanece no Forgejo (Closes #17)
- .github/workflows: ci.yml (job único checks hosted), deploy.yml (verify
  hosted full → deploy self-hosted no homeserver), flips pós-merge via API
  (FORGEJO_API_TOKEN/PR_BODY, fail-loud), auto-merge nativo (GraphQL)
- scripts: github-api/pr-flow/branch-protection (plain Node zero-dep),
  pr.mjs reescrito (GitHub + auto-merge), configure-branch-protection,
  deploy-iara.sh (local, sem SSH, idempotente), forgejo-issue-transition
  com PR_BODY + fail-loud (I10 absorvida)
- AGENTS.md/runbook: seção CI GitHub, branch protection REAL em main,
  passos manuais do cutover
2026-08-19 23:06:23 -03:00

54 lines
1.4 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import { decideAutomergeAction } from "../../scripts/lib/github-pr-flow.mjs";
const pr = (overrides: Record<string, unknown> = {}) => ({
number: 7,
title: "t",
body: "",
state: "OPEN",
merged: false,
draft: false,
mergeable: true,
nodeId: "PR_1",
head: { ref: "OPS1-x", sha: "abc" },
base: { ref: "main" },
...overrides,
});
describe("github-pr-flow", () => {
test("skip: PR inexistente", () => {
expect(decideAutomergeAction(null)).toEqual({ action: "skip", reason: "pr-inexistente" });
});
test("skip: já mergeada", () => {
expect(decideAutomergeAction(pr({ merged: true }))).toEqual({
action: "skip",
reason: "ja-mergeada",
});
});
test("skip: PR fechada", () => {
expect(decideAutomergeAction(pr({ state: "CLOSED" }))).toEqual({
action: "skip",
reason: "pr-nao-aberta",
});
});
test("skip: base não é main", () => {
expect(decideAutomergeAction(pr({ base: { ref: "release" } }))).toEqual({
action: "skip",
reason: "base-nao-main",
});
});
test("skip: draft é veto do ator (qualquer branch)", () => {
expect(decideAutomergeAction(pr({ draft: true }))).toEqual({
action: "skip",
reason: "draft-veto",
});
});
test("enable-auto-merge: PR open, não-draft, base main", () => {
expect(decideAutomergeAction(pr())).toEqual({ action: "enable-auto-merge", reason: "ready" });
});
});