Skip to content

Commit 439b255

Browse files
committed
fix(azure-devops): 为审查指南保留最新迭代提交
将已读取的最新源提交提供给审查指南,文件统计失败时仍保留该提交。 避免回退到可能过期的试合并提交,新增真实解码链路及失败边界验证。 105 项定向测试、包类型检查及静态检查通过。
1 parent 13aa882 commit 439b255

3 files changed

Lines changed: 122 additions & 9 deletions

File tree

‎packages/source-control-azure-devops/src/server/AzureDevOpsPullRequestCli.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,47 @@ afterEach(() => {
173173
});
174174

175175
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+
176217
it.effect("asks for one row more than the page, to probe for a next page", () =>
177218
Effect.gen(function* () {
178219
mockedExecute.mockReturnValueOnce(Effect.succeed(output(pullRequests(3, 1))));

‎packages/source-control-azure-devops/src/server/AzureDevOpsPullRequestProvider.test.ts‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,74 @@ describe("getChangeRequest", () => {
177177
});
178178

179179
expect(detail.changedFiles).toBe(2);
180+
expect(detail.headSha).toBe(ITERATION.headCommit);
180181
}),
181182
);
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+
);
182248
});
183249

184250
describe("getDiff reads", () => {

‎packages/source-control-azure-devops/src/server/AzureDevOpsPullRequestProvider.ts‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -309,24 +309,30 @@ export const make = Effect.gen(function* () {
309309
Effect.gen(function* () {
310310
const pullRequest = yield* cli.getPullRequest({ cwd: input.cwd, number: input.number });
311311
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;
312320
const changedFiles =
313321
location === null
314322
? 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(
324329
Effect.map((listed) => listed.changes.length),
325330
Effect.orElseSucceed(() => 0),
326331
);
327332
const detail: ProviderChangeRequestDetail = {
328333
...toChangeRequest(pullRequest),
329334
body: pullRequest.body,
335+
...(headSha === undefined ? {} : { headSha }),
330336
changedFiles,
331337
mergedAt: pullRequest.state === "merged" ? pullRequest.closedAt : null,
332338
closedAt: pullRequest.state === "closed" ? pullRequest.closedAt : null,

0 commit comments

Comments
 (0)