Skip to content

Commit dc795e9

Browse files
committed
fix(server): preserve wide review guide excerpt coverage
1 parent 47b0af8 commit dc795e9

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

‎apps/server/src/pullRequest/pullRequestReviewGuideNormalize.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,31 @@ describe("normalizeReviewGuide", () => {
139139
expect(result.stops[0]?.excerpts).toEqual([
140140
{ ...excerpt("src/a.ts", 40, 51), caption: "Second" },
141141
]);
142+
143+
const tailNote = { path: "src/a.ts", line: 40, title: "Tail", body: "Keep this note." };
144+
const wide = normalizeReviewGuide(
145+
guide({
146+
stops: [
147+
stop({
148+
excerpts: [
149+
excerpt("src/a.ts", 1, 25),
150+
{ ...excerpt("src/a.ts", 30, 45), caption: "Second" },
151+
excerpt("src/a.ts", 24, 32),
152+
],
153+
notes: [tailNote],
154+
}),
155+
],
156+
}),
157+
parseReviewGuideChange(
158+
"src/a.ts\0",
159+
"diff --git a/src/a.ts b/src/a.ts\n--- a/src/a.ts\n+++ b/src/a.ts\n@@ -0,0 +1,60 @@\n+added",
160+
),
161+
);
162+
expect(wide.stops[0]?.excerpts).toEqual([
163+
{ ...excerpt("src/a.ts", 1, 25), caption: "Second" },
164+
{ ...excerpt("src/a.ts", 26, 45), caption: "Second" },
165+
]);
166+
expect(wide.stops[0]?.notes).toEqual([tailNote]);
142167
});
143168

144169
it("drops notes outside the stop's remaining excerpts", () => {

‎apps/server/src/pullRequest/pullRequestReviewGuideNormalize.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,17 @@ function mergeExcerpts(
9898
other === first ? [combined] : touches(other) ? [] : [other],
9999
);
100100
}
101-
return merged.map((excerpt) => ({
102-
...excerpt,
103-
end: Math.min(excerpt.end, excerpt.start + MAX_EXCERPT_LINES - 1),
104-
}));
101+
return merged.flatMap((excerpt) => {
102+
const chunks: Array<PullRequestReviewGuideExcerpt> = [];
103+
for (let start = excerpt.start; start <= excerpt.end; start += MAX_EXCERPT_LINES) {
104+
chunks.push({
105+
...excerpt,
106+
start,
107+
end: Math.min(excerpt.end, start + MAX_EXCERPT_LINES - 1),
108+
});
109+
}
110+
return chunks;
111+
});
105112
}
106113

107114
const nonEmpty = (value: string) => value.trim() !== "";

0 commit comments

Comments
 (0)