test: cover review processor plan, commands, and format bodies (M1)
This commit is contained in:
1 parent
a02dea31d7
commit
1c3d6938a6
2 files changed
+140
No files matched your search
@@ -0,0 +1,75 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { formatReviewBody, formatFindingReviewBody } from "../src/review/format.js";
|
||||
import type { ReviewDecision, ReviewMode } from "../src/types.js";
|
||||
import type { ReviewDisposition } from "../src/review/policy.js";
|
||||
|
||||
const mode: ReviewMode = "normal";
|
||||
|
||||
const passDisposition: ReviewDisposition = {
|
||||
event: "APPROVE",
|
||||
blocksMerge: false,
|
||||
requiresAdminApproval: false,
|
||||
outcome: "pass"
|
||||
};
|
||||
|
||||
const blockDisposition: ReviewDisposition = {
|
||||
event: "REQUEST_CHANGES",
|
||||
blocksMerge: true,
|
||||
requiresAdminApproval: false,
|
||||
outcome: "block"
|
||||
};
|
||||
|
||||
const adminDisposition: ReviewDisposition = {
|
||||
event: "COMMENT",
|
||||
blocksMerge: false,
|
||||
requiresAdminApproval: true,
|
||||
outcome: "pass"
|
||||
};
|
||||
|
||||
function decision(overrides: Partial<ReviewDecision> = {}): ReviewDecision {
|
||||
return {
|
||||
review: [],
|
||||
change: [],
|
||||
comment: "Overall this looks fine.",
|
||||
result: { canMerge: true, summary: "safe", shouldClosePullRequest: false, closeReason: "" },
|
||||
...overrides
|
||||
};
|
||||
}
|
||||
|
||||
test("clean pass body shows the approve summary and merge guidance", () => {
|
||||
const body = formatReviewBody(decision(), [], mode, passDisposition);
|
||||
assert.match(body, /Final status: safe to merge/);
|
||||
assert.match(body, /Model decision: safe to merge/);
|
||||
assert.match(body, /Applied review policy/);
|
||||
});
|
||||
|
||||
test("blocked body lists unposted findings and recheck hint", () => {
|
||||
const withChange = decision({
|
||||
change: [{ path: "a.ts", line: 1, title: "Fix it", body: "broken" }],
|
||||
result: { ...decision().result, canMerge: false }
|
||||
});
|
||||
const body = formatReviewBody(
|
||||
withChange,
|
||||
[{ ...withChange.change[0]!, category: "change" as const }],
|
||||
mode,
|
||||
blockDisposition
|
||||
);
|
||||
assert.match(body, /Final status: changes requested/);
|
||||
assert.match(body, /could not be attached inline/);
|
||||
assert.match(body, /\/recheck/);
|
||||
});
|
||||
|
||||
test("admin approval body states the waiting disposition", () => {
|
||||
const body = formatReviewBody(decision(), [], mode, adminDisposition);
|
||||
assert.match(body, /waiting for repository administrator approval/);
|
||||
});
|
||||
|
||||
test("finding bodies carry the state marker and finding count", () => {
|
||||
const withReview = decision({
|
||||
review: [{ path: "b.ts", line: 2, title: "note", body: "nb" }]
|
||||
});
|
||||
const body = formatFindingReviewBody(withReview, "review", [], mode, passDisposition);
|
||||
assert.match(body, /<!-- ghbot-review:v1/);
|
||||
assert.match(body, /Findings: 1/);
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import {
|
||||
buildReviewSubmissionPlan,
|
||||
isConflictComment,
|
||||
isRecheckComment,
|
||||
formatSupersededReviewBody
|
||||
} from "../src/review/processor.js";
|
||||
import type { ReviewDecision } from "../src/types.js";
|
||||
|
||||
const cleanDecision: ReviewDecision = {
|
||||
review: [],
|
||||
change: [],
|
||||
comment: "ok",
|
||||
result: { canMerge: true, summary: "s", shouldClosePullRequest: false, closeReason: "" }
|
||||
};
|
||||
|
||||
test("recheck and conflict commands match only exact bodies", () => {
|
||||
assert.equal(isRecheckComment("/recheck"), true);
|
||||
assert.equal(isRecheckComment(" /recheck "), true);
|
||||
assert.equal(isRecheckComment("please /recheck now"), false);
|
||||
assert.equal(isRecheckComment("/recheck extra"), false);
|
||||
assert.equal(isConflictComment("/conflict"), true);
|
||||
assert.equal(isConflictComment("/conflict?"), false);
|
||||
});
|
||||
|
||||
test("submission plan emits change phase first, then review, then final", () => {
|
||||
const decision: ReviewDecision = {
|
||||
review: [{ path: "a.ts", line: 1, title: "r", body: "b" }],
|
||||
change: [{ path: "b.ts", line: 2, title: "c", body: "b" }],
|
||||
comment: "c",
|
||||
result: { ...cleanDecision.result }
|
||||
};
|
||||
const approveDisposition = { event: "APPROVE" as const };
|
||||
const plan = buildReviewSubmissionPlan(decision, approveDisposition);
|
||||
assert.deepEqual(
|
||||
plan.map((phase) => [phase.phase, phase.event]),
|
||||
[
|
||||
["change", "REQUEST_CHANGES"],
|
||||
["review", "COMMENT"],
|
||||
["final", "COMMENT"]
|
||||
]
|
||||
);
|
||||
assert.equal(plan[0]?.findings.length, 1);
|
||||
assert.equal(plan[1]?.findings.length, 1);
|
||||
assert.equal(plan[2]?.findings.length, 0);
|
||||
});
|
||||
|
||||
test("a clean decision submits a single final APPROVE review", () => {
|
||||
const plan = buildReviewSubmissionPlan(cleanDecision, { event: "APPROVE" });
|
||||
assert.equal(plan.length, 1);
|
||||
assert.equal(plan[0]?.phase, "final");
|
||||
assert.equal(plan[0]?.event, "APPROVE");
|
||||
});
|
||||
|
||||
test("superseded review bodies keep the original state marker", () => {
|
||||
const marker = "<!-- ghbot-review:v1 mode=normal outcome=pass requires-admin=false review=0 change=0 -->";
|
||||
const body = formatSupersededReviewBody({
|
||||
originalMarker: marker,
|
||||
oldCommitId: "a".repeat(40),
|
||||
currentCommitId: "b".repeat(40)
|
||||
});
|
||||
assert.ok(body.startsWith(marker));
|
||||
assert.match(body, /Superseded automated review/);
|
||||
});
|
||||
Reference in new issue
Block a user