GeezerVison is showing github.com — fix(server): baseline existing pull request checks when watching (#23… · incognitojam/styal@072254d
File treeExpand file treeCollapse file tree Open diff view settings apps/server/src/orchestration-v2
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Orchestrator.ts +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4709,6 +4709,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio | 4709 | 4709 | passedChecks: existing.endedWatch.passedChecks, | 4710 | 4710 | conflicting: existing.endedWatch.conflicting, | 4711 | 4711 | }), | | 4712 | + awaitingBaseline: existing.endedWatch | | 4713 | + ? existing.endedWatch.awaitingBaseline | | 4714 | + : "all", | 4712 | 4715 | ...(existing.endedWatch?.owedChecks !== undefined && { | 4713 | 4716 | owedChecks: existing.endedWatch.owedChecks, | 4714 | 4717 | }), | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/PullRequestWatchReactor.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -203,6 +203,7 @@ function watchesEqual(left: ThreadPullRequestWatch, right: ThreadPullRequestWatc | 203 | 203 | left.remarkIds.join("\n") === right.remarkIds.join("\n") && | 204 | 204 | left.conflicting === right.conflicting && | 205 | 205 | left.wakes === right.wakes && | | 206 | + left.awaitingBaseline === right.awaitingBaseline && | 206 | 207 | left.checksAwaitedSince === right.checksAwaitedSince | 207 | 208 | ); | 208 | 209 | } | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/pullRequestWatch.test.ts +207-2Lines changed: 207 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -81,6 +81,203 @@ const remark = ( | 81 | 81 | const noRemarks: ReadonlyArray<PullRequestComment> = []; | 82 | 82 |
| 83 | 83 | describe("evaluatePullRequestWatch", () => { | | 84 | + it.each([false, true])("baselines already-passed checks (required: %s)", (required) => { | | 85 | + const green = detail({ checks: [{ ...check("test", "success"), required }] }); | | 86 | + const baseline = evaluatePullRequestWatch(watch({ awaitingBaseline: "all" }), green, noRemarks); | | 87 | + assert.deepEqual(baseline.changes, []); | | 88 | + assert.equal(baseline.next.headSha, green.headSha); | | 89 | + assert.isTrue(baseline.next.passed); | | 90 | + assert.deepEqual(baseline.next.passedChecks, ["test"]); | | 91 | + assert.isFalse(baseline.exhausted); | | 92 | + assert.deepEqual(evaluatePullRequestWatch(baseline.next, green, noRemarks).changes, []); | | 93 | + | | 94 | + const pending = evaluatePullRequestWatch( | | 95 | + baseline.next, | | 96 | + detail({ checks: [{ ...check("test", "pending"), required }] }), | | 97 | + noRemarks, | | 98 | + ); | | 99 | + assert.deepEqual(pending.changes, []); | | 100 | + const failed = evaluatePullRequestWatch( | | 101 | + pending.next, | | 102 | + detail({ checks: [{ ...check("test", "failure"), required }] }), | | 103 | + noRemarks, | | 104 | + ); | | 105 | + assert.equal(failed.changes[0]?.kind, "checks-failed"); | | 106 | + const passed = evaluatePullRequestWatch(failed.next, green, noRemarks); | | 107 | + assert.deepEqual(passed.changes, [{ kind: "checks-passed", count: 1, required }]); | | 108 | + assert.deepEqual( | | 109 | + evaluatePullRequestWatch(passed.next, { ...green, headSha: "bbbbbbbbbb" }, noRemarks).changes, | | 110 | + [{ kind: "checks-passed", count: 1, required }], | | 111 | + ); | | 112 | + }); | | 113 | + | | 114 | + it("baselines existing failures and conflicts, then reports new ones", () => { | | 115 | + const broken = detail({ | | 116 | + checks: [check("lint", "failure"), check("test", "pending")], | | 117 | + mergeability: "conflicting", | | 118 | + }); | | 119 | + const baseline = evaluatePullRequestWatch( | | 120 | + watch({ awaitingBaseline: "all" }), | | 121 | + broken, | | 122 | + noRemarks, | | 123 | + ); | | 124 | + assert.deepEqual(baseline.changes, []); | | 125 | + assert.deepEqual(baseline.next.failedChecks, ["lint"]); | | 126 | + assert.isFalse(baseline.next.passed); | | 127 | + assert.isTrue(baseline.next.conflicting); | | 128 | + assert.deepEqual(evaluatePullRequestWatch(baseline.next, broken, noRemarks).changes, []); | | 129 | + | | 130 | + const failed = evaluatePullRequestWatch( | | 131 | + baseline.next, | | 132 | + { ...broken, checks: [check("lint", "failure"), check("test", "failure")] }, | | 133 | + noRemarks, | | 134 | + ); | | 135 | + assert.deepEqual(failed.changes, [ | | 136 | + { kind: "checks-failed", failed: [check("test", "failure")] }, | | 137 | + ]); | | 138 | + const clean = evaluatePullRequestWatch(failed.next, detail(), noRemarks); | | 139 | + assert.deepEqual(clean.changes, []); | | 140 | + assert.deepEqual(evaluatePullRequestWatch(clean.next, broken, noRemarks).changes, [ | | 141 | + { kind: "checks-failed", failed: [check("lint", "failure")] }, | | 142 | + { kind: "conflicting" }, | | 143 | + ]); | | 144 | + }); | | 145 | + | | 146 | + it("baselines checks already awaiting approval", () => { | | 147 | + const gated = detail({ checks: [{ ...check("CI", "action-required"), url: run(1) }] }); | | 148 | + const baseline = evaluatePullRequestWatch(watch({ awaitingBaseline: "all" }), gated, noRemarks); | | 149 | + assert.deepEqual(baseline.changes, []); | | 150 | + assert.deepEqual(evaluatePullRequestWatch(baseline.next, gated, noRemarks).changes, []); | | 151 | + }); | | 152 | + | | 153 | + it("reports remarks after the watch started while baselining checks and conflicts", () => { | | 154 | + const green = detail({ | | 155 | + checks: [check("test", "success")], | | 156 | + mergeability: "conflicting", | | 157 | + }); | | 158 | + const comments = [ | | 159 | + remark("reviewer", "2026-10-02T11:00:00Z"), | | 160 | + remark("reviewer", "2026-10-02T12:06:00Z"), | | 161 | + ]; | | 162 | + const baseline = evaluatePullRequestWatch(watch({ awaitingBaseline: "all" }), green, comments); | | 163 | + assert.deepEqual(baseline.changes, [{ kind: "remarks", remarks: [comments[1]!] }]); | | 164 | + assert.isTrue(baseline.next.passed); | | 165 | + assert.isTrue(baseline.next.conflicting); | | 166 | + assert.equal(baseline.next.wakes, 1); | | 167 | + assert.deepEqual(evaluatePullRequestWatch(baseline.next, green, comments).changes, []); | | 168 | + }); | | 169 | + | | 170 | + it("reports a failure once the head SHA appears after a baseline without one", () => { | | 171 | + const waiting = evaluatePullRequestWatch( | | 172 | + watch({ awaitingBaseline: "all" }), | | 173 | + detail({ headSha: undefined, checks: [check("test", "pending")] }), | | 174 | + noRemarks, | | 175 | + ); | | 176 | + assert.deepEqual(waiting.changes, []); | | 177 | + const failed = evaluatePullRequestWatch( | | 178 | + waiting.next, | | 179 | + detail({ checks: [check("test", "failure")] }), | | 180 | + noRemarks, | | 181 | + ); | | 182 | + assert.deepEqual(failed.changes, [ | | 183 | + { kind: "checks-failed", failed: [check("test", "failure")] }, | | 184 | + ]); | | 185 | + }); | | 186 | + | | 187 | + it("keeps a baseline taken without a head SHA once the SHA appears", () => { | | 188 | + const green = detail({ checks: [check("test", "success")] }); | | 189 | + const baseline = evaluatePullRequestWatch( | | 190 | + watch({ awaitingBaseline: "all" }), | | 191 | + { ...green, headSha: undefined }, | | 192 | + noRemarks, | | 193 | + ); | | 194 | + const known = evaluatePullRequestWatch(baseline.next, green, noRemarks); | | 195 | + assert.deepEqual(known.changes, []); | | 196 | + assert.equal(known.next.headSha, green.headSha); | | 197 | + const unknown = evaluatePullRequestWatch( | | 198 | + known.next, | | 199 | + { ...green, headSha: undefined }, | | 200 | + noRemarks, | | 201 | + ); | | 202 | + assert.equal(unknown.next.headSha, green.headSha); | | 203 | + assert.deepEqual( | | 204 | + evaluatePullRequestWatch(unknown.next, { ...green, headSha: "bbbbbbbbbb" }, noRemarks) | | 205 | + .changes, | | 206 | + [{ kind: "checks-passed", count: 1, required: false }], | | 207 | + ); | | 208 | + }); | | 209 | + | | 210 | + it.each(["success", "failure"] as const)( | | 211 | + "reports %s on checks that appear after a first read without any", | | 212 | + (status) => { | | 213 | + const empty = evaluatePullRequestWatch( | | 214 | + watch({ awaitingBaseline: "all" }), | | 215 | + detail({ checks: [] }), | | 216 | + noRemarks, | | 217 | + ); | | 218 | + assert.deepEqual(empty.changes, []); | | 219 | + assert.isUndefined(empty.next.awaitingBaseline); | | 220 | + assert.deepEqual( | | 221 | + evaluatePullRequestWatch(empty.next, detail({ checks: [check("test", status)] }), noRemarks) | | 222 | + .changes, | | 223 | + status === "success" | | 224 | + ? [{ kind: "checks-passed", count: 1, required: false }] | | 225 | + : [{ kind: "checks-failed", failed: [check("test", "failure")] }], | | 226 | + ); | | 227 | + }, | | 228 | + ); | | 229 | + | | 230 | + it("keeps the check baseline through a read whose approval lookup failed", () => { | | 231 | + const bot = check("bot", "success"); | | 232 | + const unavailable = { ...check("Workflow approval status", "pending"), placeholder: true }; | | 233 | + const partial = evaluatePullRequestWatch( | | 234 | + watch({ awaitingBaseline: "all" }), | | 235 | + detail({ checks: [bot, unavailable] }), | | 236 | + noRemarks, | | 237 | + ); | | 238 | + assert.deepEqual(partial.changes, []); | | 239 | + assert.equal(partial.next.awaitingBaseline, "checks"); | | 240 | + const approval = { ...check("CI", "action-required"), url: run(1) }; | | 241 | + for (const checks of [[bot], [bot, approval]]) { | | 242 | + assert.deepEqual( | | 243 | + evaluatePullRequestWatch(partial.next, detail({ checks }), noRemarks).changes, | | 244 | + [], | | 245 | + ); | | 246 | + } | | 247 | + }); | | 248 | + | | 249 | + it("reports pending advisory checks finishing after a required-check baseline", () => { | | 250 | + const initial = detail({ | | 251 | + checks: [{ ...check("test", "success"), required: true }, check("bot", "pending")], | | 252 | + }); | | 253 | + const baseline = evaluatePullRequestWatch( | | 254 | + watch({ awaitingBaseline: "all" }), | | 255 | + initial, | | 256 | + noRemarks, | | 257 | + ); | | 258 | + assert.deepEqual(baseline.changes, []); | | 259 | + const settled = evaluatePullRequestWatch( | | 260 | + baseline.next, | | 261 | + { | | 262 | + ...initial, | | 263 | + checks: [initial.checks[0]!, check("bot", "success")], | | 264 | + }, | | 265 | + noRemarks, | | 266 | + ); | | 267 | + assert.deepEqual(settled.changes, [{ kind: "checks-passed", count: 2, required: false }]); | | 268 | + assert.deepEqual( | | 269 | + evaluatePullRequestWatch( | | 270 | + settled.next, | | 271 | + { | | 272 | + ...initial, | | 273 | + checks: [initial.checks[0]!, check("bot", "success")], | | 274 | + }, | | 275 | + noRemarks, | | 276 | + ).changes, | | 277 | + [], | | 278 | + ); | | 279 | + }); | | 280 | + | 84 | 281 | it("waits for workflow approval once, through reads that miss it, until the run finishes", () => { | 85 | 282 | const bot = check("bot", "success"); | 86 | 283 | const approval = { ...check("CI", "action-required"), url: run(1) }; | @@ -571,14 +768,22 @@ describe("evaluatePullRequestWatch", () => { | 571 | 768 | const unknown = detail({ | 572 | 769 | checks: [{ ...check("Workflow approval status", "action-required"), placeholder: true }], | 573 | 770 | }); | 574 | | - assert.deepEqual(anHourLater(watch(), unknown).flat(), []); | 575 | | - const unread = evaluate(watch(), unknown, noRemarks, 0); | | 771 | + const fresh = watch({ awaitingBaseline: "all" }); | | 772 | + assert.deepEqual(anHourLater(fresh, unknown).flat(), []); | | 773 | + const unread = evaluate(fresh, unknown, noRemarks, 0); | 576 | 774 | assert.deepEqual( | 577 | 775 | evaluate(unread.next, detail({ checks: [] }), noRemarks, 60 * 60_000).changes, | 578 | 776 | [{ kind: "no-checks", minutes: 60 }], | 579 | 777 | ); | 580 | 778 | }); | 581 | 779 |
| | 780 | + it("starts the no-checks clock while a fresh watch awaits its baseline", () => { | | 781 | + assert.deepEqual( | | 782 | + anHourLater(watch({ awaitingBaseline: "all" }), detail({ checks: [] })).flat(), | | 783 | + ["no-checks"], | | 784 | + ); | | 785 | + }); | | 786 | + | 582 | 787 | it("never reports missing checks on a host where an empty list says nothing", () => { | 583 | 788 | const silent = detail({ capabilities: capabilities(false), checks: [] }); | 584 | 789 | assert.isTrue(anHourLater(watch(), silent).every((kinds) => kinds.length === 0)); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/pullRequestWatch.ts +20-9Lines changed: 20 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -45,9 +45,10 @@ export function evaluatePullRequestWatch( | 45 | 45 | now: number, | 46 | 46 | ): PullRequestWatchReport { | 47 | 47 | const changes: Array<PullRequestWatchChange> = []; | 48 | | - // Azure DevOps omits the head when its iteration read fails; that is not a push. | | 48 | + // A read without a head says nothing about pushes, so it keeps the last known one. | 49 | 49 | const headSha = detail.headSha ?? watch.headSha; | 50 | | - const headMoved = headSha !== watch.headSha; | | 50 | + const headMoved = watch.headSha !== null && headSha !== watch.headSha; | | 51 | + const checksBaseline = watch.awaitingBaseline !== undefined && !headMoved; | 51 | 52 |
| 52 | 53 | // Hosts can return no checks on read failure; preserve prior state. | 53 | 54 | let failedChecks = headMoved ? [] : watch.failedChecks; | @@ -63,9 +64,11 @@ export function evaluatePullRequestWatch( | 63 | 64 | const awaiting = checks.filter((check) => check.status === "action-required"); | 64 | 65 | if (checks.length > 0) { | 65 | 66 | const newlyFailed = failed.filter((check) => !failedChecks.includes(check.name)); | 66 | | - if (newlyFailed.length > 0) changes.push({ kind: "checks-failed", failed: newlyFailed }); | | 67 | + if (!checksBaseline && newlyFailed.length > 0) { | | 68 | + changes.push({ kind: "checks-failed", failed: newlyFailed }); | | 69 | + } | 67 | 70 | if (!approvalAnnounced && awaiting.length > 0) { | 68 | | - changes.push({ kind: "checks-awaiting-approval", checks: awaiting }); | | 71 | + if (!checksBaseline) changes.push({ kind: "checks-awaiting-approval", checks: awaiting }); | 69 | 72 | approvalAnnounced = true; | 70 | 73 | } | 71 | 74 | failedChecks = failed.map((check) => check.name); | @@ -125,7 +128,9 @@ export function evaluatePullRequestWatch( | 125 | 128 | checks.every((check) => check.status !== "pending"); | 126 | 129 | owedChecks = owed; | 127 | 130 | if (passedNow && (!passed || gateGrew)) { | 128 | | - changes.push({ kind: "checks-passed", count: gate.length, required: required.length > 0 }); | | 131 | + if (!checksBaseline) { | | 132 | + changes.push({ kind: "checks-passed", count: gate.length, required: required.length > 0 }); | | 133 | + } | 129 | 134 | owedChecks = | 130 | 135 | required.length > 0 | 131 | 136 | ? checks | @@ -146,9 +151,10 @@ export function evaluatePullRequestWatch( | 146 | 151 | // repository runs no checks at all, nothing waits. | 147 | 152 | let checksAwaitedSince = watch.checksAwaitedSince; | 148 | 153 | if (detail.capabilities.checksAlwaysReport === true) { | 149 | | - const awaitedBefore = headMoved | 150 | | - ? DateTime.formatIso(DateTime.makeUnsafe(now)) | 151 | | - : (watch.checksAwaitedSince ?? null); | | 154 | + const awaitedBefore = | | 155 | + headMoved || watch.awaitingBaseline === "all" | | 156 | + ? DateTime.formatIso(DateTime.makeUnsafe(now)) | | 157 | + : (watch.checksAwaitedSince ?? null); | 152 | 158 | checksAwaitedSince = checks.length > 0 ? null : awaitedBefore; | 153 | 159 | const awaitedMs = checksAwaitedSince === null ? 0 : now - Date.parse(checksAwaitedSince); | 154 | 160 | if (!unread && awaitedMs >= PULL_REQUEST_WATCH_NO_CHECKS_MS) { | @@ -179,7 +185,7 @@ export function evaluatePullRequestWatch( | 179 | 185 |
| 180 | 186 | // Like a failed check, a conflict a push did not resolve is news for the new head. | 181 | 187 | const toldConflict = !headMoved && watch.conflicting; | 182 | | - if (detail.mergeability === "conflicting" && !toldConflict) { | | 188 | + if (watch.awaitingBaseline !== "all" && detail.mergeability === "conflicting" && !toldConflict) { | 183 | 189 | changes.push({ kind: "conflicting" }); | 184 | 190 | } | 185 | 191 | // "unknown" is a host still computing after a push; only a clean answer clears a conflict. | @@ -204,6 +210,11 @@ export function evaluatePullRequestWatch( | 204 | 210 | remarkIds, | 205 | 211 | conflicting, | 206 | 212 | wakes, | | 213 | + // Only a read that cannot be trusted to show the checks leaves the baseline to the next one. | | 214 | + ...(checksBaseline && | | 215 | + (unread || (detail.headSha === undefined && checks.length === 0)) && { | | 216 | + awaitingBaseline: "checks" as const, | | 217 | + }), | 207 | 218 | checksAwaitedSince, | 208 | 219 | }, | 209 | 220 | exhausted: commentsOnly && wakes >= PULL_REQUEST_WATCH_WAKE_LIMIT, | |
|