GeezerVison is showing github.com — fix(server): wake GitLab MR watches when a rebase is required (#30312) · pingdotgg/t3code@f5ca0f9
File treeExpand file treeCollapse file tree Open diff view settings source-control-core/src/server source-control-gitlab/src/server
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 +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5065,6 +5065,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio | 5065 | 5065 | passed: existing.endedWatch.passed, | 5066 | 5066 | passedChecks: existing.endedWatch.passedChecks, | 5067 | 5067 | conflicting: existing.endedWatch.conflicting, | | 5068 | + rebaseRequired: existing.endedWatch.rebaseRequired, | 5068 | 5069 | }), | 5069 | 5070 | awaitingBaseline: existing.endedWatch | 5070 | 5071 | ? existing.endedWatch.awaitingBaseline | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts +33Lines changed: 33 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -613,6 +613,39 @@ describe("PullRequestSyncReactor", () => { | 613 | 613 | }).pipe(Effect.provide(fixture.layer)); | 614 | 614 | }), | 615 | 615 | ); | | 616 | + it.effect("syncs a rebase blocker even when the PR timestamp is unchanged", () => | | 617 | + Effect.scoped( | | 618 | + Effect.gen(function* () { | | 619 | + yield* TestClock.setTime(Date.parse(NOW)); | | 620 | + const required = yield* Ref.make(false); | | 621 | + const fixture = yield* makeHarness({ | | 622 | + snapshot: makeSnapshot([makeThread("rebase", { pullRequests: [makeLink(7)] })]), | | 623 | + summary: (input) => | | 624 | + Ref.get(required).pipe( | | 625 | + Effect.map((rebaseRequired) => makeSummary(input, { rebaseRequired })), | | 626 | + ), | | 627 | + }); | | 628 | + yield* Effect.gen(function* () { | | 629 | + const reactor = yield* startAndSweep(fixture); | | 630 | + yield* applyRecordedSyncs(fixture); | | 631 | + yield* Ref.set(required, true); | | 632 | + yield* reactor.requestSync({ | | 633 | + host: "github.com", | | 634 | + repository: "owner/repository", | | 635 | + number: 7, | | 636 | + }); | | 637 | + yield* Queue.take(fixture.snapshotReads); | | 638 | + yield* reactor.drain; | | 639 | + const commands = yield* Ref.get(fixture.syncCommands); | | 640 | + assert.equal(commands.length, 2); | | 641 | + assert.equal(commands[0]?.snapshot?.rebaseRequired, false); | | 642 | + assert.equal(commands[1]?.snapshot?.rebaseRequired, true); | | 643 | + assert.equal(commands[0]?.snapshot?.updatedAt, commands[1]?.snapshot?.updatedAt); | | 644 | + }).pipe(Effect.provide(fixture.layer)); | | 645 | + }), | | 646 | + ), | | 647 | + ); | | 648 | + | 616 | 649 | it.effect("snapshots an unsynced link once and writes it to the thread", () => | 617 | 650 | Effect.gen(function* () { | 618 | 651 | yield* TestClock.setTime(Date.parse(NOW)); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/PullRequestSyncReactor.ts +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -234,6 +234,7 @@ function snapshotFieldsOf(summary: PullRequestSummary): SnapshotFields { | 234 | 234 | ...(summary.reviewDecision === undefined ? {} : { reviewDecision: summary.reviewDecision }), | 235 | 235 | ...(summary.checksState === undefined ? {} : { checksState: summary.checksState }), | 236 | 236 | ...(summary.mergeability === undefined ? {} : { mergeability: summary.mergeability }), | | 237 | + ...(summary.rebaseRequired === undefined ? {} : { rebaseRequired: summary.rebaseRequired }), | 237 | 238 | }; | 238 | 239 | } | 239 | 240 |
| @@ -282,7 +283,8 @@ function snapshotFieldsEqual(left: SnapshotFields, right: SnapshotFields): boole | 282 | 283 | left.changedFiles === right.changedFiles && | 283 | 284 | (left.reviewDecision ?? null) === (right.reviewDecision ?? null) && | 284 | 285 | (left.checksState ?? null) === (right.checksState ?? null) && | 285 | | - left.mergeability === right.mergeability | | 286 | + left.mergeability === right.mergeability && | | 287 | + left.rebaseRequired === right.rebaseRequired | 286 | 288 | ); | 287 | 289 | } | 288 | 290 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/PullRequestWatchReactor.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -151,6 +151,7 @@ const snapshotFingerprint = ({ link }: WatchTarget) => { | 151 | 151 | snapshot.updatedAt, | 152 | 152 | snapshot.checksState, | 153 | 153 | snapshot.mergeability, | | 154 | + snapshot.rebaseRequired, | 154 | 155 | snapshot.reviewDecision, | 155 | 156 | snapshot.isDraft, | 156 | 157 | ].join(" "); | @@ -212,6 +213,7 @@ function watchesEqual(left: ThreadPullRequestWatch, right: ThreadPullRequestWatc | 212 | 213 | left.remarksThrough === right.remarksThrough && | 213 | 214 | left.remarkIds.join("\n") === right.remarkIds.join("\n") && | 214 | 215 | left.conflicting === right.conflicting && | | 216 | + left.rebaseRequired === right.rebaseRequired && | 215 | 217 | left.mergeQueueRemovalId === right.mergeQueueRemovalId && | 216 | 218 | left.wakes === right.wakes && | 217 | 219 | left.awaitingBaseline === right.awaitingBaseline && | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/pullRequestWatch.test.ts +47-1Lines changed: 47 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -81,6 +81,45 @@ const remark = ( | 81 | 81 | const noRemarks: ReadonlyArray<PullRequestComment> = []; | 82 | 82 |
| 83 | 83 | describe("evaluatePullRequestWatch", () => { | | 84 | + it.each(["pending", "success"] as const)( | | 85 | + "reports a required rebase once with %s CI", | | 86 | + (status) => { | | 87 | + const blocked = detail({ | | 88 | + mergeability: "unknown", | | 89 | + rebaseRequired: true, | | 90 | + checks: [check("test", status)], | | 91 | + }); | | 92 | + const first = evaluatePullRequestWatch(watch(), blocked, noRemarks); | | 93 | + assert.include( | | 94 | + first.changes.map((change) => change.kind), | | 95 | + "needs-rebase", | | 96 | + ); | | 97 | + assert.deepEqual(evaluatePullRequestWatch(first.next, blocked, noRemarks).changes, []); | | 98 | + const unknown = evaluatePullRequestWatch( | | 99 | + first.next, | | 100 | + { ...blocked, rebaseRequired: undefined }, | | 101 | + noRemarks, | | 102 | + ); | | 103 | + assert.deepEqual(evaluatePullRequestWatch(unknown.next, blocked, noRemarks).changes, []); | | 104 | + const clean = evaluatePullRequestWatch( | | 105 | + first.next, | | 106 | + { ...blocked, rebaseRequired: false }, | | 107 | + noRemarks, | | 108 | + ); | | 109 | + assert.deepEqual(evaluatePullRequestWatch(clean.next, blocked, noRemarks).changes, [ | | 110 | + { kind: "needs-rebase" }, | | 111 | + ]); | | 112 | + assert.include( | | 113 | + evaluatePullRequestWatch( | | 114 | + first.next, | | 115 | + { ...blocked, headSha: "bbbbbbbbbb" }, | | 116 | + noRemarks, | | 117 | + ).changes.map((change) => change.kind), | | 118 | + "needs-rebase", | | 119 | + ); | | 120 | + }, | | 121 | + ); | | 122 | + | 84 | 123 | it.each([false, true])("baselines already-passed checks (required: %s)", (required) => { | 85 | 124 | const green = detail({ checks: [{ ...check("test", "success"), required }] }); | 86 | 125 | const baseline = evaluatePullRequestWatch(watch({ awaitingBaseline: "all" }), green, noRemarks); | @@ -115,6 +154,7 @@ describe("evaluatePullRequestWatch", () => { | 115 | 154 | const broken = detail({ | 116 | 155 | checks: [check("lint", "failure"), check("test", "pending")], | 117 | 156 | mergeability: "conflicting", | | 157 | + rebaseRequired: true, | 118 | 158 | }); | 119 | 159 | const baseline = evaluatePullRequestWatch( | 120 | 160 | watch({ awaitingBaseline: "all" }), | @@ -125,6 +165,7 @@ describe("evaluatePullRequestWatch", () => { | 125 | 165 | assert.deepEqual(baseline.next.failedChecks, ["lint"]); | 126 | 166 | assert.isFalse(baseline.next.passed); | 127 | 167 | assert.isTrue(baseline.next.conflicting); | | 168 | + assert.isTrue(baseline.next.rebaseRequired); | 128 | 169 | assert.deepEqual(evaluatePullRequestWatch(baseline.next, broken, noRemarks).changes, []); | 129 | 170 |
| 130 | 171 | const failed = evaluatePullRequestWatch( | @@ -135,11 +176,16 @@ describe("evaluatePullRequestWatch", () => { | 135 | 176 | assert.deepEqual(failed.changes, [ | 136 | 177 | { kind: "checks-failed", failed: [check("test", "failure")] }, | 137 | 178 | ]); | 138 | | - const clean = evaluatePullRequestWatch(failed.next, detail(), noRemarks); | | 179 | + const clean = evaluatePullRequestWatch( | | 180 | + failed.next, | | 181 | + detail({ rebaseRequired: false }), | | 182 | + noRemarks, | | 183 | + ); | 139 | 184 | assert.deepEqual(clean.changes, []); | 140 | 185 | assert.deepEqual(evaluatePullRequestWatch(clean.next, broken, noRemarks).changes, [ | 141 | 186 | { kind: "checks-failed", failed: [check("lint", "failure")] }, | 142 | 187 | { kind: "conflicting" }, | | 188 | + { kind: "needs-rebase" }, | 143 | 189 | ]); | 144 | 190 | }); | 145 | 191 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/pullRequestWatch.ts +13-1Lines changed: 13 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,6 +21,7 @@ export type PullRequestWatchChange = | 21 | 21 | | { readonly kind: "remarks"; readonly remarks: ReadonlyArray<PullRequestComment> } | 22 | 22 | | { readonly kind: "no-checks"; readonly minutes: number } | 23 | 23 | | { readonly kind: "conflicting" } | | 24 | + | { readonly kind: "needs-rebase" } | 24 | 25 | | { readonly kind: "merge-queue-removed"; readonly reason: string | null }; | 25 | 26 |
| 26 | 27 | export interface PullRequestWatchReport { | @@ -46,6 +47,7 @@ export function evaluatePullRequestWatch( | 46 | 47 | | "mergeability" | 47 | 48 | | "viewer" | 48 | 49 | | "author" | | 50 | + | "rebaseRequired" | 49 | 51 | | "mergeQueueRemoval" | 50 | 52 | >, | 51 | 53 | remarks: ReadonlyArray<PullRequestComment> | null, | @@ -196,11 +198,16 @@ export function evaluatePullRequestWatch( | 196 | 198 | ...atLatest.map((remark) => remark.id), | 197 | 199 | ]; | 198 | 200 |
| 199 | | - // Like a failed check, a conflict a push did not resolve is news for the new head. | | 201 | + // Like a failed check, a conflict or rebase a push did not resolve is news for the new head. | 200 | 202 | const toldConflict = !headMoved && watch.conflicting; | 201 | 203 | if (watch.awaitingBaseline !== "all" && detail.mergeability === "conflicting" && !toldConflict) { | 202 | 204 | changes.push({ kind: "conflicting" }); | 203 | 205 | } | | 206 | + const toldRebase = !headMoved && watch.rebaseRequired === true; | | 207 | + if (watch.awaitingBaseline !== "all" && detail.rebaseRequired === true && !toldRebase) { | | 208 | + changes.push({ kind: "needs-rebase" }); | | 209 | + } | | 210 | + const rebaseRequired = detail.rebaseRequired ?? watch.rebaseRequired; | 204 | 211 | // "unknown" is a host still computing after a push; only a clean answer clears a conflict. | 205 | 212 | const conflicting = | 206 | 213 | detail.mergeability === "unknown" ? toldConflict : detail.mergeability === "conflicting"; | @@ -239,6 +246,7 @@ export function evaluatePullRequestWatch( | 239 | 246 | remarksThrough, | 240 | 247 | remarkIds, | 241 | 248 | conflicting, | | 249 | + rebaseRequired, | 242 | 250 | mergeQueueRemovalId, | 243 | 251 | wakes, | 244 | 252 | // Only a read that cannot be trusted to show the checks leaves the baseline to the next one. | @@ -308,6 +316,8 @@ function changeLines( | 308 | 316 | return [ | 309 | 317 | `- No checks have reported${context.commit} after ${change.minutes} minutes. None may be configured to run on this change.`, | 310 | 318 | ]; | | 319 | + case "needs-rebase": | | 320 | + return [`- The branch requires a rebase onto ${context.baseBranch}.`]; | 311 | 321 | case "conflicting": | 312 | 322 | return [`- The branch now conflicts with ${context.baseBranch}.`]; | 313 | 323 | case "merge-queue-removed": | @@ -324,6 +334,7 @@ const SUMMARY: Record<PullRequestWatchChange["kind"], string> = { | 324 | 334 | remarks: "new comments", | 325 | 335 | "no-checks": "no checks reported", | 326 | 336 | conflicting: "merge conflict", | | 337 | + "needs-rebase": "rebase required", | 327 | 338 | "merge-queue-removed": "removed from merge queue", | 328 | 339 | }; | 329 | 340 |
| @@ -388,6 +399,7 @@ export function pullRequestWatchMessage(input: { | 388 | 399 | (change) => | 389 | 400 | change.kind === "checks-failed" || | 390 | 401 | change.kind === "conflicting" || | | 402 | + change.kind === "needs-rebase" || | 391 | 403 | change.kind === "merge-queue-removed", | 392 | 404 | ); | 393 | 405 | const summary = changes.map((change) => SUMMARY[change.kind]); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/PullRequestService.test.ts +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3458,6 +3458,7 @@ it.effect( | 3458 | 3458 | Effect.succeed({ | 3459 | 3459 | ...changeRequest(1, "2026-07-02T00:00:00Z"), | 3460 | 3460 | isDraft: true, | | 3461 | + rebaseRequired: false, | 3461 | 3462 | reviewDecision: "approved", | 3462 | 3463 | checksState: "passing", | 3463 | 3464 | }), | @@ -3467,13 +3468,16 @@ it.effect( | 3467 | 3468 | deletions: 3, | 3468 | 3469 | changedFiles: 5, | 3469 | 3470 | mergeability: "conflicting", | | 3471 | + rebaseRequired: true, | 3470 | 3472 | }), | 3471 | 3473 | }), | 3472 | 3474 | ], | 3473 | 3475 | }); | 3474 | 3476 | yield* service.summary(reference); | 3475 | 3477 | const detail = yield* service.detail(reference); | 3476 | 3478 | const summary = yield* service.summary(reference); | | 3479 | + assert.strictEqual(detail.rebaseRequired, true); | | 3480 | + assert.strictEqual(summary.rebaseRequired, true); | 3477 | 3481 | assert.strictEqual(summary.isDraft, false); | 3478 | 3482 | assert.deepStrictEqual(summary.author, detail.author); | 3479 | 3483 | assert.strictEqual(summary.additions, 14); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/PullRequestService.ts +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1309,6 +1309,9 @@ export const make = Effect.gen(function* () { | 1309 | 1309 | state: input.item.state, | 1310 | 1310 | isDraft: input.item.isDraft, | 1311 | 1311 | mergeability: input.item.mergeability, | | 1312 | + ...(input.item.rebaseRequired === undefined | | 1313 | + ? {} | | 1314 | + : { rebaseRequired: input.item.rebaseRequired }), | 1312 | 1315 | additions: input.item.additions, | 1313 | 1316 | deletions: input.item.deletions, | 1314 | 1317 | createdAt: input.item.createdAt, | @@ -1792,6 +1795,9 @@ export const make = Effect.gen(function* () { | 1792 | 1795 | ...(changeRequest.mergeability === undefined | 1793 | 1796 | ? {} | 1794 | 1797 | : { mergeability: changeRequest.mergeability }), | | 1798 | + ...(changeRequest.rebaseRequired === undefined | | 1799 | + ? {} | | 1800 | + : { rebaseRequired: changeRequest.rebaseRequired }), | 1795 | 1801 | ...(changeRequest.stack === undefined ? {} : { stack: changeRequest.stack }), | 1796 | 1802 | ...(changeRequest.headSha?.trim() ? { headSha: changeRequest.headSha.trim() } : {}), | 1797 | 1803 | ...(changeRequest.autoMergeEnabled === undefined | @@ -1891,6 +1897,9 @@ export const make = Effect.gen(function* () { | 1891 | 1897 | state: changeRequest.state, | 1892 | 1898 | isDraft: changeRequest.isDraft, | 1893 | 1899 | mergeability: changeRequest.mergeability, | | 1900 | + ...(changeRequest.rebaseRequired === undefined | | 1901 | + ? {} | | 1902 | + : { rebaseRequired: changeRequest.rebaseRequired }), | 1894 | 1903 | additions: changeRequest.additions, | 1895 | 1904 | deletions: changeRequest.deletions, | 1896 | 1905 | changedFiles: changeRequest.changedFiles, | @@ -3330,6 +3339,7 @@ export const make = Effect.gen(function* () { | 3330 | 3339 | deletions: detail.deletions, | 3331 | 3340 | changedFiles: detail.changedFiles, | 3332 | 3341 | mergeability: detail.mergeability, | | 3342 | + ...(detail.rebaseRequired === undefined ? {} : { rebaseRequired: detail.rebaseRequired }), | 3333 | 3343 | headBranch: detail.headBranch, | 3334 | 3344 | baseBranch: detail.baseBranch, | 3335 | 3345 | closedAt: detail.closedAt, | |
Collapse file Copy file name to clipboardExpand all lines: packages/contracts/src/pullRequest.ts +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -370,6 +370,7 @@ export const PullRequestListEntry = Schema.Struct({ | 370 | 370 | state: PullRequestState, | 371 | 371 | isDraft: Schema.Boolean, | 372 | 372 | mergeability: PullRequestMergeability, | | 373 | + rebaseRequired: Schema.optional(Schema.Boolean), | 373 | 374 | /** Zero until fetched through `PullRequestListStatsInput`; GitHub listings omit counts. */ | 374 | 375 | additions: NonNegativeInt, | 375 | 376 | deletions: NonNegativeInt, | @@ -528,6 +529,7 @@ export const PullRequestSummary = Schema.Struct({ | 528 | 529 | reviewDecision: Schema.optional(Schema.NullOr(PullRequestReviewDecision)), | 529 | 530 | checksState: Schema.optional(Schema.NullOr(PullRequestChecksState)), | 530 | 531 | mergeability: Schema.optional(PullRequestMergeability), | | 532 | + rebaseRequired: Schema.optional(Schema.Boolean), | 531 | 533 | /** Null when the host says the pull request is in no stack; absent when the read did not ask. */ | 532 | 534 | stack: Schema.optional(Schema.NullOr(PullRequestStackMembership)), | 533 | 535 | headSha: Schema.optional(TrimmedNonEmptyString), | @@ -651,6 +653,7 @@ export const PullRequestDetail = Schema.Struct({ | 651 | 653 | state: PullRequestState, | 652 | 654 | isDraft: Schema.Boolean, | 653 | 655 | mergeability: PullRequestMergeability, | | 656 | + rebaseRequired: Schema.optional(Schema.Boolean), | 654 | 657 | additions: NonNegativeInt, | 655 | 658 | deletions: NonNegativeInt, | 656 | 659 | changedFiles: NonNegativeInt, | |
Collapse file Copy file name to clipboardExpand all lines: packages/contracts/src/threadPullRequest.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,6 +51,7 @@ export const ThreadPullRequestSnapshot = Schema.Struct({ | 51 | 51 | reviewDecision: Schema.optional(Schema.NullOr(PullRequestReviewDecision)), | 52 | 52 | checksState: Schema.optional(Schema.NullOr(PullRequestChecksState)), | 53 | 53 | mergeability: Schema.optional(PullRequestMergeability), | | 54 | + rebaseRequired: Schema.optional(Schema.Boolean), | 54 | 55 | }); | 55 | 56 | export type ThreadPullRequestSnapshot = typeof ThreadPullRequestSnapshot.Type; | 56 | 57 |
| @@ -97,6 +98,7 @@ export const ThreadPullRequestWatch = Schema.Struct({ | 97 | 98 | /** Reported remarks at remarksThrough, so late arrivals at that timestamp still count. */ | 98 | 99 | remarkIds: Schema.Array(TrimmedNonEmptyString), | 99 | 100 | conflicting: Schema.Boolean, | | 101 | + rebaseRequired: Schema.optional(Schema.Boolean), | 100 | 102 | /** Last removal seen; null after an empty read, absent before the first read. */ | 101 | 103 | mergeQueueRemovalId: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)), | 102 | 104 | /** Consecutive comment-only wakes; limited to prevent bot loops. */ | |
|