GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): PR watches wake when checks finish after an early failur… · ryush00/t3code@450a8f3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/orchestration-v2
    • pullRequestWatch.test.ts
    • pullRequestWatch.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/pullRequestWatch.test.ts
+130Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,136 @@ describe("evaluatePullRequestWatch", () => {
649649
assert.deepEqual(evaluatePullRequestWatch(final.next, recovered, noRemarks).changes, []);
650650
});
651651

652+
it("wakes once when the other checks finish after one failed where none is required", () => {
653+
const sonar = check("sonar", "cancelled");
654+
const early = detail({ checks: [sonar, check("unit", "pending"), check("e2e", "pending")] });
655+
const first = evaluatePullRequestWatch(watch(), early, noRemarks);
656+
assert.deepEqual(first.changes, [{ kind: "checks-failed", failed: [sonar] }]);
657+
658+
const partway = detail({ checks: [sonar, check("unit", "success"), check("e2e", "pending")] });
659+
const waiting = evaluatePullRequestWatch(first.next, partway, noRemarks);
660+
assert.deepEqual(waiting.changes, []);
661+
662+
const done = detail({ checks: [sonar, check("unit", "success"), check("e2e", "success")] });
663+
const final = evaluatePullRequestWatch(waiting.next, done, noRemarks);
664+
assert.deepEqual(final.changes, [
665+
{ kind: "checks-finished", failing: [sonar], required: false },
666+
]);
667+
assert.deepEqual(evaluatePullRequestWatch(final.next, done, noRemarks).changes, []);
668+
669+
// An owed check stays owed while it runs, even when the failed one turns required.
670+
const gated = detail({
671+
checks: [{ ...sonar, required: true }, check("unit", "success"), check("e2e", "pending")],
672+
});
673+
const still = evaluatePullRequestWatch(waiting.next, gated, noRemarks);
674+
assert.deepEqual(still.changes, []);
675+
assert.deepEqual(still.next.owedChecks, ["e2e"]);
676+
677+
// Another gate failure owes the gate's running checks on top of those still owed.
678+
const lint = { ...check("lint", "failure"), required: true };
679+
const another = detail({ checks: [...gated.checks, lint] });
680+
const both = evaluatePullRequestWatch(still.next, another, noRemarks);
681+
assert.deepEqual(both.changes, [{ kind: "checks-failed", failed: [lint] }]);
682+
assert.deepEqual(both.next.owedChecks, ["e2e"]);
683+
684+
// The last owed check finishing still wakes when an unrelated check fails in the same read.
685+
const bot = check("bot", "failure");
686+
const finishedWithBot = detail({
687+
checks: [sonar, check("unit", "success"), check("e2e", "success"), bot],
688+
});
689+
assert.deepEqual(evaluatePullRequestWatch(waiting.next, finishedWithBot, noRemarks).changes, [
690+
{ kind: "checks-failed", failed: [bot] },
691+
{ kind: "checks-finished", failing: [sonar, bot], required: false },
692+
]);
693+
694+
// A later failure is its own wake and leaves nothing more owed.
695+
const broke = detail({ checks: [sonar, check("unit", "success"), check("e2e", "failure")] });
696+
const failure = evaluatePullRequestWatch(waiting.next, broke, noRemarks);
697+
assert.deepEqual(failure.changes, [
698+
{ kind: "checks-failed", failed: [check("e2e", "failure")] },
699+
]);
700+
assert.deepEqual(evaluatePullRequestWatch(failure.next, broke, noRemarks).changes, []);
701+
702+
// A failure while another owed check still runs keeps that one owed.
703+
const unitBroke = detail({
704+
checks: [sonar, check("unit", "failure"), check("e2e", "pending")],
705+
});
706+
const second = evaluatePullRequestWatch(first.next, unitBroke, noRemarks);
707+
assert.deepEqual(second.changes, [
708+
{ kind: "checks-failed", failed: [check("unit", "failure")] },
709+
]);
710+
const settled = detail({ checks: [sonar, check("unit", "failure"), check("e2e", "success")] });
711+
const last = evaluatePullRequestWatch(second.next, settled, noRemarks);
712+
assert.deepEqual(last.changes, [
713+
{ kind: "checks-finished", failing: [sonar, check("unit", "failure")], required: false },
714+
]);
715+
});
716+
717+
it("wakes once when the other required checks finish after a required one failed", () => {
718+
const required = (name: string, status: PullRequestCheck["status"]) => ({
719+
...check(name, status),
720+
required: true,
721+
});
722+
const early = detail({
723+
checks: [
724+
required("lint", "failure"),
725+
required("unit", "pending"),
726+
check("bot", "failure"),
727+
check("e2e", "pending"),
728+
],
729+
});
730+
const first = evaluatePullRequestWatch(watch(), early, noRemarks);
731+
assert.equal(first.changes.length, 1);
732+
assert.deepEqual(first.next.owedChecks, ["unit"]);
733+
734+
const done = detail({
735+
checks: [
736+
required("lint", "failure"),
737+
required("unit", "success"),
738+
check("bot", "failure"),
739+
check("e2e", "pending"),
740+
],
741+
});
742+
const final = evaluatePullRequestWatch(first.next, done, noRemarks);
743+
assert.deepEqual(final.changes, [
744+
{ kind: "checks-finished", failing: [required("lint", "failure")], required: true },
745+
]);
746+
assert.deepEqual(evaluatePullRequestWatch(final.next, done, noRemarks).changes, []);
747+
const message = pullRequestWatchMessage({
748+
number: 7,
749+
url: "https://github.com/o/r/pull/7",
750+
baseBranch: "main",
751+
headSha: "aaaaaaaaaa",
752+
report: final,
753+
});
754+
assert.equal(message.notification.outcome, "failed");
755+
756+
// A new advisory failure keeps what was owed rather than owing a required check started since.
757+
const advisory = detail({
758+
checks: [
759+
required("lint", "failure"),
760+
required("unit", "pending"),
761+
required("smoke", "pending"),
762+
check("bot", "failure"),
763+
check("e2e", "failure"),
764+
],
765+
});
766+
const later = evaluatePullRequestWatch(first.next, advisory, noRemarks);
767+
assert.deepEqual(later.changes, [{ kind: "checks-failed", failed: [check("e2e", "failure")] }]);
768+
assert.deepEqual(later.next.owedChecks, ["unit"]);
769+
770+
// A rerun of the failed required check is not the gate finishing, even with an advisory failure.
771+
const rerun = detail({
772+
checks: [
773+
required("lint", "pending"),
774+
required("unit", "success"),
775+
check("bot", "failure"),
776+
check("e2e", "pending"),
777+
],
778+
});
779+
assert.deepEqual(evaluatePullRequestWatch(first.next, rerun, noRemarks).changes, []);
780+
});
781+
652782
it("clears old-head owed checks when a new head is pushed", () => {
653783
const required = { ...check("test", "success"), required: true };
654784
const early = detail({ checks: [required, check("e2e", "pending")] });
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/pullRequestWatch.ts
+50-14Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ const SNIPPET_LENGTH = 200;
1717
export type PullRequestWatchChange =
1818
| { readonly kind: "checks-failed"; readonly failed: ReadonlyArray<PullRequestCheck> }
1919
| { readonly kind: "checks-passed"; readonly count: number; readonly required: boolean }
20+
| {
21+
readonly kind: "checks-finished";
22+
readonly failing: ReadonlyArray<PullRequestCheck>;
23+
readonly required: boolean;
24+
}
2025
| { readonly kind: "checks-awaiting-approval"; readonly checks: ReadonlyArray<PullRequestCheck> }
2126
| { readonly kind: "remarks"; readonly remarks: ReadonlyArray<PullRequestComment> }
2227
| { readonly kind: "no-checks"; readonly minutes: number }
@@ -65,6 +70,7 @@ export function evaluatePullRequestWatch(
6570
let passed = headMoved ? false : watch.passed;
6671
let passedChecks = headMoved ? [] : watch.passedChecks;
6772
let owedChecks = headMoved ? [] : (watch.owedChecks ?? []);
73+
const owedBefore = owedChecks;
6874
let awaitingApproval = headMoved ? [] : (watch.awaitingApproval ?? []);
6975
let approvalAnnounced = headMoved ? false : (watch.approvalAnnounced ?? false);
7076
// A watch with no answer (saved before the field, or since a push) waits only while the clock
@@ -75,23 +81,23 @@ export function evaluatePullRequestWatch(
7581
const checks = detail.checks.filter((check) => check.placeholder !== true);
7682
const failed = checks.filter(isFailedCheck);
7783
const awaiting = checks.filter((check) => check.status === "action-required");
84+
// A new run under a failing name is a rerun that failed again between reads. A run is its
85+
// URL, or the host's run ID where the URL stays the same across reruns.
86+
const toldRuns = failedRuns;
87+
const runOf = (check: PullRequestCheck) => {
88+
const run = check.runId ?? check.url;
89+
return run === null ? null : JSON.stringify([check.name, run]);
90+
};
91+
const newlyFailed = failed.filter((check) => {
92+
const run = runOf(check);
93+
return (
94+
!failedChecks.includes(check.name) ||
95+
(toldRuns !== undefined && run !== null && !toldRuns.includes(run))
96+
);
97+
});
7898
if (checks.length > 0) {
7999
// A run awaiting approval waits on a person, like a review, so only running checks count.
80100
checksPending = checks.some((check) => check.status === "pending");
81-
// A new run under a failing name is a rerun that failed again between reads. A run is its
82-
// URL, or the host's run ID where the URL stays the same across reruns.
83-
const toldRuns = failedRuns;
84-
const runOf = (check: PullRequestCheck) => {
85-
const run = check.runId ?? check.url;
86-
return run === null ? null : JSON.stringify([check.name, run]);
87-
};
88-
const newlyFailed = failed.filter((check) => {
89-
const run = runOf(check);
90-
return (
91-
!failedChecks.includes(check.name) ||
92-
(toldRuns !== undefined && run !== null && !toldRuns.includes(run))
93-
);
94-
});
95101
if (!checksBaseline && newlyFailed.length > 0) {
96102
changes.push({ kind: "checks-failed", failed: newlyFailed });
97103
}
@@ -172,6 +178,26 @@ export function evaluatePullRequestWatch(
172178
} else if (settled && owed.length > 0) {
173179
changes.push({ kind: "checks-passed", count: checks.length, required: false });
174180
owedChecks = [];
181+
} else if (gate.some(isFailedCheck)) {
182+
// Gate checks still running when one failed are owed one wake when they finish, since
183+
// the gate can no longer pass and so never sends the checks-passed wake.
184+
const running = checks
185+
.filter((check) => check.status === "pending" || check.status === "action-required")
186+
.map((check) => check.name);
187+
const stillOwed = owedBefore.filter((name) => running.includes(name));
188+
const gateNewlyFailed =
189+
!checksBaseline && newlyFailed.some((check) => gateNames.includes(check.name));
190+
owedChecks = gateNewlyFailed
191+
? [...new Set([...stillOwed, ...running.filter((name) => gateNames.includes(name))])]
192+
: stillOwed;
193+
const owedFailed = newlyFailed.some((check) => owedBefore.includes(check.name));
194+
if (!owedFailed && owedBefore.length > 0 && owedChecks.length === 0) {
195+
changes.push({
196+
kind: "checks-finished",
197+
failing: gate.filter(isFailedCheck),
198+
required: owedBefore.every((name) => required.some((check) => check.name === name)),
199+
});
200+
}
175201
}
176202
passed = passedNow;
177203
passedChecks = passedNow ? gateNames : [];
@@ -403,6 +429,14 @@ function changeLines(
403429
return ` - ${remark.author?.login ?? "someone"}${where}: ${said}${remark.url ? ` ${remark.url}` : ""}`;
404430
}),
405431
];
432+
case "checks-finished":
433+
return [
434+
`- The ${change.required ? "required " : ""}checks still running when one failed have finished${context.commit}. Still failing:`,
435+
...listed(
436+
change.failing,
437+
(check) => ` - ${check.name}${check.url ? ` ${check.url}` : ""}`,
438+
),
439+
];
406440
case "no-checks":
407441
return [
408442
`- No checks have reported${context.commit} after ${change.minutes} minutes. None may be configured to run on this change.`,
@@ -421,6 +455,7 @@ function changeLines(
421455
const SUMMARY: Record<PullRequestWatchChange["kind"], string> = {
422456
"checks-failed": "checks failed",
423457
"checks-passed": "checks passed",
458+
"checks-finished": "checks finished",
424459
"checks-awaiting-approval": "checks await approval",
425460
remarks: "new comments",
426461
"no-checks": "no checks reported",
@@ -489,6 +524,7 @@ export function pullRequestWatchMessage(input: {
489524
const failed = changes.some(
490525
(change) =>
491526
change.kind === "checks-failed" ||
527+
change.kind === "checks-finished" ||
492528
change.kind === "conflicting" ||
493529
change.kind === "needs-rebase" ||
494530
change.kind === "merge-queue-removed",

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.