Skip to content

Commit 2d8e16d

Browse files
ScottN-PVclaude
andcommitted
fix(server): GitLab merge requests can expand unchanged lines
The GitLab provider never wired the diff file contents read, so the pull request service refused every expand with "This host cannot expand unchanged pull request lines." The CLI read already existed; the provider now exposes it the way the GitHub provider exposes its own. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ec80933 commit 2d8e16d

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,69 @@ describe("rewriting what has already been said", () => {
212212
}),
213213
);
214214
});
215+
216+
describe("expanding unchanged lines", () => {
217+
const change = {
218+
cwd: "/w",
219+
repository: "acme/web",
220+
host: "gitlab.com",
221+
number: 7,
222+
changeType: "change" as const,
223+
oldPath: "src/page.ts",
224+
newPath: "src/page.ts",
225+
};
226+
227+
it.effect("reads both sides of a file through the merge request or one of its commits", () =>
228+
Effect.gen(function* () {
229+
const getMergeRequestDiffFileContents = vi.fn(() =>
230+
Effect.succeed({ oldContents: "before\n", newContents: "after\n" }),
231+
);
232+
const provider = yield* make.pipe(
233+
Effect.provide(
234+
Layer.mock(GitLabPullRequestCli.GitLabPullRequestCli)({
235+
getMergeRequestDiffFileContents,
236+
}),
237+
),
238+
);
239+
assert.isDefined(provider.getDiffFileContents);
240+
const oneCommit = { ...change, commit: "a1b2c3d" };
241+
242+
expect(yield* provider.getDiffFileContents(change)).toEqual({
243+
oldContents: "before\n",
244+
newContents: "after\n",
245+
});
246+
yield* provider.getDiffFileContents(oneCommit);
247+
expect(getMergeRequestDiffFileContents).toHaveBeenNthCalledWith(1, change);
248+
expect(getMergeRequestDiffFileContents).toHaveBeenNthCalledWith(2, oneCommit);
249+
}),
250+
);
251+
252+
it.effect("reports a file GitLab cannot expand as a failed read", () =>
253+
Effect.gen(function* () {
254+
const provider = yield* make.pipe(
255+
Effect.provide(
256+
Layer.mock(GitLabPullRequestCli.GitLabPullRequestCli)({
257+
getMergeRequestDiffFileContents: () =>
258+
Effect.fail(
259+
new GitLabPullRequestCli.GitLabDiffFileContentsUnavailableError({
260+
command: "glab",
261+
cwd: "/w",
262+
path: "assets/logo.png",
263+
reason: "binary",
264+
}),
265+
),
266+
}),
267+
),
268+
);
269+
assert.isDefined(provider.getDiffFileContents);
270+
271+
expect(yield* Effect.flip(provider.getDiffFileContents(change))).toMatchObject({
272+
_tag: "PullRequestProviderError",
273+
provider: "gitlab",
274+
operation: "getDiffFileContents",
275+
reason: "failed",
276+
detail: "The diff file 'assets/logo.png' is binary.",
277+
});
278+
}),
279+
);
280+
});

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ export const make = Effect.gen(function* () {
230230

231231
getDiff: (input) => cli.getMergeRequestDiff(input).pipe(Effect.mapError(fail("getDiff"))),
232232

233+
getDiffFileContents: (input) =>
234+
cli.getMergeRequestDiffFileContents(input).pipe(Effect.mapError(fail("getDiffFileContents"))),
235+
233236
// What each marked file is at the head, which is what tells a mark that still stands from one
234237
// the branch has moved past. GitLab's own local-storage marks are keyed on the blob id too,
235238
// so this stales at the same moment its web UI would.

0 commit comments

Comments
 (0)