Skip to content

Commit 042e3c6

Browse files
committed
fix(server): a viewed mark on a wide review stops reporting changes
A whole-change answer wider than one entry's path cap trimmed away the reader's own files, which stored the mark without a baseline and left it reading viewed however far the head moved. Signed-off-by: Yordis Prieto <[email protected]>
1 parent 0d64740 commit 042e3c6

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5594,6 +5594,58 @@ it.effect("bounds the paths one change request's held revisions carry", () =>
55945594
}),
55955595
);
55965596

5597+
it.effect("keeps the marked paths when a whole-change answer is wider than the cap", () =>
5598+
Effect.gen(function* () {
5599+
// A host with no per-file version answers with the whole change, which on a wide review
5600+
// carries more paths than one entry holds. What the trim reaches has to be the paths the
5601+
// answer threw in rather than the ones the reader ticked: a mark stored with no baseline
5602+
// reports viewed however far the head moves off it.
5603+
const head = new Map<string, string>(
5604+
Array.from(
5605+
{ length: MAX_FILE_REVISION_PATHS + 178 },
5606+
(_, index) =>
5607+
[`src/f${String(index).padStart(4, "0")}.ts`, `blob-${String(index)}`] as const,
5608+
),
5609+
);
5610+
const service = yield* makeService({
5611+
projects: [
5612+
project({
5613+
id: "p1",
5614+
title: "on gitlab",
5615+
workspaceRoot: "/a",
5616+
repository: "group/project",
5617+
provider: "gitlab",
5618+
}),
5619+
],
5620+
providers: [
5621+
{
5622+
...environmentViewedProvider(head, []),
5623+
getFileRevisions: () => Effect.succeed({ revisions: head, complete: true }),
5624+
},
5625+
],
5626+
});
5627+
const ticked = ["src/f0000.ts", "src/f0500.ts"];
5628+
5629+
yield* service.setFilesViewed({
5630+
...GITLAB_REFERENCE,
5631+
files: ticked.map((path) => ({ path, viewed: true })),
5632+
});
5633+
for (const path of ticked) head.set(path, "blob-moved");
5634+
// Past the stale window, so the read is answered by the host rather than from what the press
5635+
// heard.
5636+
yield* TestClock.adjust("11 minutes");
5637+
const marked = yield* service.filesViewed(GITLAB_REFERENCE);
5638+
5639+
assert.deepStrictEqual(
5640+
[...marked.files].toSorted((left, right) => left.path.localeCompare(right.path)),
5641+
[
5642+
{ path: "src/f0000.ts", state: "dismissed" },
5643+
{ path: "src/f0500.ts", state: "dismissed" },
5644+
],
5645+
);
5646+
}),
5647+
);
5648+
55975649
it.effect("keeps the change request being ticked through, not the one pressed first", () =>
55985650
Effect.gen(function* () {
55995651
// Ordered by insertion alone a hit does not renew its entry, so the review a reader is

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ const makeFileRevisions = (dependencies: FileRevisionsDependencies) => {
9595
: null;
9696
const revisions = new Map(carried?.revisions ?? []);
9797
const asked = new Set(carried?.asked ?? []);
98-
const learned = answer.complete === true ? [...paths, ...answer.revisions.keys()] : paths;
98+
// The paths asked for go last, so a whole-change answer wider than the cap is trimmed down
99+
// to the reader's own files rather than over them.
100+
const learned = answer.complete === true ? [...answer.revisions.keys(), ...paths] : paths;
99101
for (const path of learned) {
100102
// Reinserted rather than added, so what a full entry drops below is the path nobody has
101103
// asked about in the longest rather than one just asked for.

0 commit comments

Comments
 (0)