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
9 changes: 7 additions & 2 deletions src/review/fix-handoff-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ export function buildFixHandoffBlock(finding: InlineFinding): FixHandoffBlock {
const location = hasLine ? `${safePath}:${line}` : `${safePath} (no specific line)`;
const label = finding.severity === "blocker" ? "Blocker" : "Nit";
const suggestedChange = finding.suggestion?.trim() || undefined;
const suggestionBlock = suggestedChange ? `\n\nSuggested change:\n\`\`\`\n${suggestedChange}\n\`\`\`` : "";
// Skip the fenced block when the suggestion itself contains a ``` sequence, which would close the outer fence
// early and break the rendered markdown -- matching inline-suggestion-anchor.ts's safeSuggestionBlock guard.
const suggestionBlock =
suggestedChange && !suggestedChange.includes("```") ? `\n\nSuggested change:\n\`\`\`\n${suggestedChange}\n\`\`\`` : "";
const body = [
FIX_HANDOFF_MARKER,
`**Fix handoff — ${label} at \`${location}\`**`,
Expand Down Expand Up @@ -106,7 +109,9 @@ function fixHandoffAggregateItem(finding: InlineFinding, index: number): string
const location = hasLine ? `${safePath}:${finding.line}` : `${safePath} (no specific line)`;
const label = finding.severity === "blocker" ? "Blocker" : "Nit";
const suggestion = finding.suggestion?.trim();
const suggestionBlock = suggestion ? `\n \`\`\`\n ${suggestion.replace(/\n/g, "\n ")}\n \`\`\`` : "";
// Same fence-safety guard as buildFixHandoffBlock / safeSuggestionBlock: an embedded ``` would break the block.
const suggestionBlock =
suggestion && !suggestion.includes("```") ? `\n \`\`\`\n ${suggestion.replace(/\n/g, "\n ")}\n \`\`\`` : "";
return `${index + 1}. **${label} at \`${location}\`** — ${finding.body}${suggestionBlock}`;
}

Expand Down
13 changes: 13 additions & 0 deletions test/unit/fix-handoff-render.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ describe("buildFixHandoffBlock (#2175)", () => {
expect(block.body).not.toContain("Suggested change:");
});

it("skips the fenced block when the suggestion itself contains a ``` sequence (#6632)", () => {
const block = buildFixHandoffBlock(finding({ suggestion: "Replace with:\n```\nconst x = 1;\n```" }));
// The embedded fence would close the outer block early, so the fenced rendering is skipped entirely
// (matching safeSuggestionBlock); no stray ``` leaks into the rendered markdown.
expect(block.body).not.toContain("Suggested change:");
expect(block.body).not.toContain("```");
});

it("yields a path-only block (line 0) when the finding has no commentable line (line <= 0)", () => {
const block = buildFixHandoffBlock(finding({ line: 0 }));
expect(block.line).toBe(0);
Expand Down Expand Up @@ -123,6 +131,11 @@ describe("buildFixHandoffAggregateBlock (#5102)", () => {
expect(buildFixHandoffAggregateBlock([finding({ suggestion: " " })])?.body).not.toContain("```");
});

it("skips the fenced suggestion block when the suggestion contains a ``` sequence (#6632)", () => {
const block = buildFixHandoffAggregateBlock([finding({ suggestion: "```\nconst x = 1;\n```" })]);
expect(block?.body).not.toContain("```"); // embedded fence would break the item's block; skipped entirely
});

it("always includes the exact LOCAL_WRITE_BOUNDARY text (boundary-safe)", () => {
const block = buildFixHandoffAggregateBlock([finding()]);
expect(block?.boundary).toBe(LOCAL_WRITE_BOUNDARY);
Expand Down