From 1c3d6938a672b1170258ef73b02e0efe39c89996 Mon Sep 17 00:00:00 2001 From: wdawdwa <2864460459@qq.com> Date: Sat, 22 Aug 2026 17:43:17 +0800 Subject: [PATCH] test: cover review processor plan, commands, and format bodies (M1) --- test/review-format.test.ts | 75 +++++++++++++++++++++++++++++++++++ test/review-processor.test.ts | 65 ++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 test/review-format.test.ts create mode 100644 test/review-processor.test.ts diff --git a/test/review-format.test.ts b/test/review-format.test.ts new file mode 100644 index 0000000..705283a --- /dev/null +++ b/test/review-format.test.ts @@ -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 { + 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, /"; + const body = formatSupersededReviewBody({ + originalMarker: marker, + oldCommitId: "a".repeat(40), + currentCommitId: "b".repeat(40) + }); + assert.ok(body.startsWith(marker)); + assert.match(body, /Superseded automated review/); +});