Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions test/unit/review-thread-findings.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { describe, expect, it } from "vitest";
import {
REVIEW_THREAD_BLOCKER_CODE,
buildReviewThreadBlocker,
reviewThreadBlockerFinding,
} from "../../src/review/review-thread-findings";

describe("review thread blocker parsing", () => {
it("returns null when every comment body is empty", () => {
expect(
buildReviewThreadBlocker({
path: "src/a.ts",
line: 4,
comments: [{ body: " " }, { body: null }],
}),
).toBeNull();
});

it("prefers scanner-marked comments and parses markdown priority titles", () => {
const blocker = buildReviewThreadBlocker({
path: "src/a.ts",
line: 12,
comments: [
{ body: "Please fix this naming.", authorLogin: "human" },
{
body: "<!-- brin-pr-finding -->\n**P1:** Leaked secret in config",
authorLogin: "brin",
url: "https://github.com/o/r/pull/1#discussion_r1",
},
],
});
expect(blocker).toMatchObject({
title: "Leaked secret in config",
priority: "P1",
path: "src/a.ts",
line: 12,
authorLogin: "brin",
scannerFinding: true,
});
});

it("parses XML priority/title markers and formats advisory findings with locations", () => {
const blocker = buildReviewThreadBlocker({
path: "pkg/main.go",
line: 0,
comments: [
{
body: "<priority>P2</priority><title>Race in shutdown hook</title>",
authorLogin: "reviewer",
},
],
});
expect(blocker).toMatchObject({
title: "Race in shutdown hook",
priority: "P2",
scannerFinding: false,
});

const finding = reviewThreadBlockerFinding(blocker!);
expect(finding.code).toBe(REVIEW_THREAD_BLOCKER_CODE);
expect(finding.title).toMatch(/reviewer review thread unresolved: P2 Race in shutdown hook/);
expect(finding.detail).toMatch(/pkg\/main\.go/);
expect(finding.detail).not.toMatch(/pkg\/main\.go:/);
});
});