Skip to content

Commit afbfc53

Browse files
committed
fix(server): retain approval holds while overlapping jobs run
1 parent 209aed8 commit afbfc53

3 files changed

Lines changed: 39 additions & 11 deletions

File tree

‎apps/server/src/orchestration-v2/pullRequestWatch.test.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,31 @@ describe("evaluatePullRequestWatch", () => {
163163
assert.deepEqual(running.changes, []);
164164
assert.isFalse(running.next.passed);
165165
assert.deepEqual(running.next.awaitingApproval, [run(1)]);
166+
const overlap = evaluatePullRequestWatch(
167+
running.next,
168+
detail({ checks: [required, job, { ...pending, url: `${run(2)}/job/9` }] }),
169+
noRemarks,
170+
);
171+
assert.deepEqual(overlap.changes, []);
172+
assert.isFalse(overlap.next.passed);
173+
assert.deepEqual(overlap.next.awaitingApproval, [run(1)]);
174+
const unlinked = evaluatePullRequestWatch(
175+
overlap.next,
176+
detail({ checks: [required, job, { ...pending, url: null }] }),
177+
noRemarks,
178+
);
179+
assert.deepEqual(unlinked.changes, []);
180+
assert.isFalse(unlinked.next.passed);
181+
assert.deepEqual(unlinked.next.awaitingApproval, [run(1)]);
182+
const advisory = evaluatePullRequestWatch(
183+
unlinked.next,
184+
detail({ checks: [required, job, { ...pending, url: "https://ci.example/test" }] }),
185+
noRemarks,
186+
);
187+
assert.deepEqual(advisory.changes, [{ kind: "checks-passed", count: 1, required: true }]);
188+
assert.deepEqual(advisory.next.awaitingApproval, []);
166189
const completed = detail({ checks: [required, job, { ...pending, status: "success" }] });
167-
const finished = evaluatePullRequestWatch(running.next, completed, noRemarks);
190+
const finished = evaluatePullRequestWatch(unlinked.next, completed, noRemarks);
168191
assert.deepEqual(finished.changes, [{ kind: "checks-passed", count: 1, required: true }]);
169192
assert.deepEqual(finished.next.awaitingApproval, []);
170193
assert.deepEqual(evaluatePullRequestWatch(finished.next, completed, noRemarks).changes, []);

‎apps/server/src/orchestration-v2/pullRequestWatch.ts‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ export function evaluatePullRequestWatch(
7474
failedChecks = failed.map((check) => check.name);
7575

7676
// GitHub lists runs awaiting approval in a separate read that can come back empty, so a run
77-
// stays awaited through reads that miss it until all reported jobs finish. One known only by
78-
// name needs a completed check with that name before its hold can clear.
77+
// stays awaited through reads that miss it until reported GitHub jobs, and pending checks
78+
// without a URL, finish. One known only by name needs a completed check with that name before
79+
// its hold can clear.
7980
const awaitingNow = [...new Set(awaiting.map(approvalKey))];
8081
const nameUnfinished = (name: string) => {
8182
const matching = checks.filter((check) => check.name === name);
@@ -84,14 +85,18 @@ export function evaluatePullRequestWatch(
8485
matching.some((check) => check.status === "pending" || check.status === "action-required")
8586
);
8687
};
87-
const pending = new Set(
88-
checks.filter((check) => check.status === "pending").map((check) => workflowRunOf(check.url)),
88+
// GitHub deduplicates jobs across runs, so a visible pending job may hide one in an awaited run.
89+
// A pending check without a URL could be such a job; one with another host's URL cannot.
90+
const jobsPending = checks.some(
91+
(check) =>
92+
check.status === "pending" && (check.url === null || workflowRunOf(check.url) !== null),
8993
);
9094
const finished = new Set(
91-
checks
92-
.filter((check) => check.status !== "action-required" && check.status !== "pending")
93-
.map((check) => workflowRunOf(check.url))
94-
.filter((run) => !pending.has(run)),
95+
jobsPending
96+
? []
97+
: checks
98+
.filter((check) => check.status !== "action-required" && check.status !== "pending")
99+
.map((check) => workflowRunOf(check.url)),
95100
);
96101
awaitingApproval = [
97102
...awaitingNow,

‎packages/contracts/src/threadPullRequest.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ export const ThreadPullRequestWatch = Schema.Struct({
9191
owedChecks: Schema.optional(Schema.Array(TrimmedNonEmptyString)),
9292
/**
9393
* Checks waiting for someone to approve or act on them, which block a pass: a workflow run's
94-
* URL, kept through reads that miss it until all reported jobs finish, or else a check's name,
95-
* kept until reported checks with that name finish.
94+
* URL, kept through reads that miss it until reported GitHub jobs and pending checks without a
95+
* URL finish, or else a check's name, kept until reported checks with that name finish.
9696
*/
9797
awaitingApproval: Schema.optional(Schema.Array(TrimmedNonEmptyString)),
9898
/** The agent was told checks await approval on this head, so later ones stay quiet. */

0 commit comments

Comments
 (0)