Skip to content
Merged
Show file tree
Hide file tree
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
119 changes: 102 additions & 17 deletions test/pr-review-advisor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1035,29 +1035,33 @@ diff --git a/test/example.test.ts b/test/example.test.ts
expect(detailed).toContain("## Source-of-truth review");
expect(detailed).toContain("trusted-code boundary");
expect(comment).toContain("<details>");
expect(comment).toContain(
"<summary>Review findings by urgency: 1 required fix, 0 items to resolve/justify, 0 in-scope improvements</summary>",
);
expect(comment).toContain("### Action checklist");
expect(comment).toContain("### Findings index");
expect(comment).toContain("| `PRA-1` | Required | workflow |");
expect(comment).toContain("<summary>Test follow-ups to resolve or justify</summary>");
expect(comment).toContain("- **Mocked behavioral coverage** — comment builder test.");
expect(comment).toContain("- `PRA-T1` **Mocked behavioral coverage** — comment builder test.");
expect(comment).not.toContain("\\*\\*Mocked behavioral coverage\\*\\*");
expect(comment).toContain("comment builder test");
expect(comment).toContain("<!-- head_sha: abc123def456; recommendation: merge_after_fixes -->");
expect(comment).toContain("**Review posture:** Resolve findings before merge");
expect(comment).toContain("## PR Review Advisor — Changes requested");
expect(comment).toContain("**Merge posture:** Do not merge yet");
expect(comment).toContain("**Primary next action:** Fix `PRA-1`: trusted-code boundary");
expect(comment).toContain("### 🚨 Required before merge");
expect(comment).toContain("### ⚠️ Resolve or justify before merge");
expect(comment).toContain("### 💡 In-scope improvements");
expect(comment).toContain("#### `PRA-1` Required — trusted-code boundary");
expect(comment).toContain(
"Impact: A PR-controlled workflow could run advisor code with repository secrets.",
"- **Impact:** A PR-controlled workflow could run advisor code with repository secrets.",
);
expect(comment).toContain(
"Verification hint: Inspect the workflow checkout and advisor script path.",
"- **Verification:** Inspect the workflow checkout and advisor script path.",
);
expect(comment).toContain(
"Missing regression test: Keep the workflow trusted-code boundary test.",
"- **Missing regression test:** Keep the workflow trusted-code boundary test.",
);
expect(comment).toContain(
"Expected follow-up: Fix before merge or get explicit maintainer override.",
"- **Expected follow-up:** Fix before merge or get explicit maintainer override.",
);
expect(comment).toContain(
"- **Done when:** The required change is committed and verification passes: Inspect the workflow checkout and advisor script path.",
);
expect(comment).toContain(
"Treat suggestions as current-PR improvements when they touch changed code",
Expand All @@ -1074,7 +1078,7 @@ diff --git a/test/example.test.ts b/test/example.test.ts
expect(summary).not.toContain("## Review completeness");
expect(summary).not.toContain("Human maintainer review required");
expect(comment).toContain(
"1 required fix, 0 items to resolve/justify, 0 in-scope improvements",
"**Open items:** 1 required · 0 warnings · 0 suggestions · 1 test follow-up",
);
expect(comment).toContain("**Top item:** trusted-code boundary");
expect(summary).not.toContain("Base: `origin/main`");
Expand All @@ -1100,9 +1104,9 @@ diff --git a/test/example.test.ts b/test/example.test.ts
result: followUpResult,
});
expect(followUp).toContain(
"**Since last review:** 1 prior item resolved, 1 still applies, 1 new item found",
"**Since last review:** 1 prior item resolved · 1 still applies · 1 new item found",
);
expect(followUp).toContain("<summary>Review findings by urgency:");
expect(followUp).toContain("### Action checklist");
expect(followUp).toContain("<summary>Since last review details</summary>");
});

Expand Down Expand Up @@ -1146,6 +1150,37 @@ diff --git a/test/example.test.ts b/test/example.test.ts
expect(comment).toContain("Safety boundary: Keep input validation and timezone test coverage.");
});

it("prioritizes warning findings ahead of test follow-ups", () => {
const result = normalizeReviewResult(
validResult({
findings: [
{
severity: "warning",
category: "correctness",
file: "src/lib/example.ts",
line: 12,
title: "Resolve the warning first",
description: "Warnings should remain ahead of test follow-ups in scan-first sections.",
recommendation:
"Resolve or justify this warning before working through test follow-ups.",
},
],
}),
metadata(),
);

const comment = buildComment({ summary: renderSummary(result), result });
const warningChecklist = "- [ ] `PRA-1` Resolve or justify: Resolve the warning first";
const testChecklist = "- [ ] `PRA-T1` Add or justify test follow-up";

expect(comment).toContain(
"**Primary next action:** Resolve or justify `PRA-1`: Resolve the warning first.",
);
expect(comment).toContain(warningChecklist);
expect(comment).toContain(testChecklist);
expect(comment.indexOf(warningChecklist)).toBeLessThan(comment.indexOf(testChecklist));
});

it("renders suggestion findings as in-scope current-review work", () => {
const result = normalizeReviewResult(
validResult({
Expand Down Expand Up @@ -1176,8 +1211,12 @@ diff --git a/test/example.test.ts b/test/example.test.ts
);
expect(comment).toContain("### 💡 In-scope improvements");
expect(comment).toContain(
"Expected follow-up: Prefer a current-PR fix when local to changed code; defer only with rationale or linked follow-up.",
"- [ ] `PRA-1` In-scope improvement: Simplify changed branch in <code>src/lib/example.ts:12</code>",
);
expect(comment).toContain(
"- **Expected follow-up:** Prefer a current-PR fix when local to changed code; defer only with rationale or linked follow-up.",
);
expect(comment).not.toContain("Optional: Simplify changed branch");
expect(comment).not.toContain("nice ideas");
});

Expand All @@ -1194,13 +1233,59 @@ diff --git a/test/example.test.ts b/test/example.test.ts
);
const comment = buildComment({ summary: renderSummary(result), result });

expect(comment).toContain("- **Mocked behavioral coverage** — probe");
expect(comment).toContain("- `PRA-T1` **Mocked behavioral coverage** — probe");
expect(comment).toContain("probe \\*\\*bold\\*\\* \\[link\\]\\(https://bad.invalid\\).");
expect(comment).toContain("&lt;/details&gt; and &#64;team");
expect(comment).not.toContain("- \\*\\*Mocked behavioral coverage\\*\\*");
expect(comment).not.toContain("check </details>");
});

it("keeps hostile file locations inside checklist and table fields", () => {
const result = normalizeReviewResult(
validResult({
findings: [
{
severity: "blocker",
category: "correctness",
file: "src/a|b.ts",
line: 7,
title: "Pipe in path",
description: "Location should not add a table cell.",
},
{
severity: "warning",
category: "correctness",
file: "src/a\nb.ts",
line: 8,
title: "Newline in path",
description: "Location should stay on one rendered line.",
},
{
severity: "suggestion",
category: "correctness",
file: "src/a`b.ts",
line: 9,
title: "Backtick in path",
description: "Location should not break a Markdown code span.",
},
],
}),
metadata(),
);
const comment = buildComment({ summary: renderSummary(result), result });
const indexRows = comment.split("\n").filter((line) => /^\| `PRA-/.test(line));

expect(indexRows).toHaveLength(3);
expect(indexRows[0]).toContain("<code>src/a&#124;b.ts:7</code>");
expect(indexRows[1]).toContain("<code>src/a b.ts:8</code>");
expect(indexRows[2]).toContain("<code>src/a`b.ts:9</code>");
for (const row of indexRows) expect(row.match(/\|/g)).toHaveLength(6);
expect(comment).toContain("- [ ] `PRA-1` Fix: Pipe in path in <code>src/a&#124;b.ts:7</code>");
expect(comment).toContain("- **Location:** <code>src/a b.ts:8</code>");
expect(comment).not.toContain("src/a\nb.ts");
expect(comment).not.toContain("`src/a`b.ts:9`");
});

it("escapes advisor finding text before rendering sticky comments", () => {
const result = normalizeReviewResult(
validResult({
Expand Down Expand Up @@ -1231,7 +1316,7 @@ diff --git a/test/example.test.ts b/test/example.test.ts
expect(comment).toContain(
"&lt;/details&gt; &#64;team \\*\\*boom\\*\\* \\[x\\]\\(https://bad.invalid\\)",
);
expect(comment).toContain("src/&lt;bad&gt;\\(1\\).ts:7");
expect(comment).toContain("src/&lt;bad&gt;(1).ts:7");
expect(comment).toContain("first ### injected &lt;script&gt;");
expect(comment).toContain("ping &#64;here &amp; fix \\_now\\_");
expect(comment).toContain("\\`code\\` &lt;tag&gt;");
Expand Down
Loading