@devries-cameron20 / t3code-1 / commits / 264815cda7
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(azure-devops): expose the latest source revision for review guides (#20977)

Yukun Shan committed Oct 19, 2026 at 04:06 UTC 264815cda7b6011e2d0226df38256725f65d66fb
3 files changed +122 -9
packages/source-control-azure-devops/src/server/AzureDevOpsPullRequestCli.test.ts
+41
@@ -173,6 +173,47 @@ afterEach(() => {
173 });
174
175 layer("AzureDevOpsPullRequestCli.layer", (it) => {
176 + it.effect("reports the latest pushed source commit even while the trial merge is stale", () =>
177 + Effect.gen(function* () {
178 + const previousHead = "a".repeat(40);
179 + const latestHead = "c".repeat(40);
180 + mockedExecute
181 + .mockReturnValueOnce(
182 + Effect.succeed(
183 + output(json({ ...pullRequestRow, lastMergeSourceCommit: { commitId: previousHead } })),
184 + ),
185 + )
186 + .mockReturnValueOnce(
187 + Effect.succeed(
188 + output(
189 + json({
190 + value: [
191 + {
192 + id: 2,
193 + sourceRefCommit: { commitId: latestHead },
194 + commonRefCommit: { commitId: "b".repeat(40) },
195 + },
196 + ...oneIteration.value,
197 + ],
198 + }),
199 + ),
200 + ),
201 + )
202 + .mockReturnValueOnce(Effect.succeed(output(json({ changeEntries: [] }))));
203 + const provider = yield* AzureDevOpsPullRequestProvider.make;
204 + const detail = yield* provider.getChangeRequest({
205 + cwd: "/w",
206 + repository: "platform/web",
207 + host: "dev.azure.com",
208 + number: 42,
209 + });
210 +
211 + expect(detail.headSha).toBe(latestHead);
212 + expect(argsOfCall(2)).toContain("iterationId=2");
213 + expect(mockedExecute).toHaveBeenCalledTimes(3);
214 + }),
215 + );
216 +
217 it.effect("asks for one row more than the page, to probe for a next page", () =>
218 Effect.gen(function* () {
219 mockedExecute.mockReturnValueOnce(Effect.succeed(output(pullRequests(3, 1))));
packages/source-control-azure-devops/src/server/AzureDevOpsPullRequestProvider.test.ts
+66
@@ -177,8 +177,74 @@ describe("getChangeRequest", () => {
177 });
178
179 expect(detail.changedFiles).toBe(2);
180 + expect(detail.headSha).toBe(ITERATION.headCommit);
181 }),
182 );
183 +
184 + it.effect("preserves the newest head when file counting fails", () =>
185 + Effect.gen(function* () {
186 + const provider = yield* make.pipe(
187 + Effect.provide(
188 + Layer.mock(AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli)({
189 + getPullRequest: () => Effect.succeed(PULL_REQUEST),
190 + listIterations: () =>
191 + Effect.succeed([ITERATION, { ...ITERATION, id: 4, headCommit: "new-head" }]),
192 + listIterationChanges: () =>
193 + Effect.fail(
194 + new AzureDevOpsPullRequestCli.AzureDevOpsPullRequestReadError({
195 + command: "az",
196 + cwd: "/w",
197 + operation: "listIterationChanges",
198 + cause: "unavailable",
199 + }),
200 + ),
201 + }),
202 + ),
203 + );
204 +
205 + const detail = yield* provider.getChangeRequest({
206 + cwd: "/w",
207 + repository: "acme/web",
208 + host: "dev.azure.com",
209 + number: 7,
210 + });
211 + expect(detail.headSha).toBe("new-head");
212 + expect(detail.changedFiles).toBe(0);
213 + }),
214 + );
215 +
216 + it.effect.each(["missing", "failed"] as const)(
217 + "leaves the head unavailable when the iteration read is %s",
218 + (state) =>
219 + Effect.gen(function* () {
220 + const provider = yield* make.pipe(
221 + Effect.provide(
222 + Layer.mock(AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli)({
223 + getPullRequest: () => Effect.succeed(PULL_REQUEST),
224 + listIterations: () =>
225 + state === "missing"
226 + ? Effect.succeed([])
227 + : Effect.fail(
228 + new AzureDevOpsPullRequestCli.AzureDevOpsPullRequestReadError({
229 + command: "az",
230 + cwd: "/w",
231 + operation: "listIterations",
232 + cause: "unavailable",
233 + }),
234 + ),
235 + }),
236 + ),
237 + );
238 + const detail = yield* provider.getChangeRequest({
239 + cwd: "/w",
240 + repository: "acme/web",
241 + host: "dev.azure.com",
242 + number: 7,
243 + });
244 + expect(detail.headSha).toBeUndefined();
245 + expect(detail.changedFiles).toBe(0);
246 + }),
247 + );
248 });
249
250 describe("getDiff reads", () => {
packages/source-control-azure-devops/src/server/AzureDevOpsPullRequestProvider.ts
+15 -9
@@ -309,24 +309,30 @@ export const make = Effect.gen(function* () {
309 Effect.gen(function* () {
310 const pullRequest = yield* cli.getPullRequest({ cwd: input.cwd, number: input.number });
311 const location = pullRequest.location;
312 + const iterations =
313 + location === null
314 + ? []
315 + : yield* cli
316 + .listIterations({ cwd: input.cwd, location, number: input.number })
317 + .pipe(Effect.orElseSucceed(() => []));
318 + // The trial merge's lastMergeSourceCommit can lag behind a new source push.
319 + const headSha = iterations.at(-1)?.headCommit;
320 const changedFiles =
321 location === null
322 ? 0
315 - : yield* cli.listIterations({ cwd: input.cwd, location, number: input.number }).pipe(
316 - Effect.flatMap((iterations) =>
317 - listLatestChanges({
318 - cwd: input.cwd,
319 - location,
320 - number: input.number,
321 - iterations,
322 - }),
323 - ),
323 + : yield* listLatestChanges({
324 + cwd: input.cwd,
325 + location,
326 + number: input.number,
327 + iterations,
328 + }).pipe(
329 Effect.map((listed) => listed.changes.length),
330 Effect.orElseSucceed(() => 0),
331 );
332 const detail: ProviderChangeRequestDetail = {
333 ...toChangeRequest(pullRequest),
334 body: pullRequest.body,
335 + ...(headSha === undefined ? {} : { headSha }),
336 changedFiles,
337 mergedAt: pullRequest.state === "merged" ? pullRequest.closedAt : null,
338 closedAt: pullRequest.state === "closed" ? pullRequest.closedAt : null,