GeezerVison is showing github.com — fix(gitlab): a watch reports a pipeline retry that fails again (#33671) · ryush00/t3code@a674a2d
File treeExpand file treeCollapse file tree Open diff view settings apps/server/src/orchestration-v2 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/pullRequestWatch.test.ts +23Lines changed: 23 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -561,6 +561,29 @@ describe("evaluatePullRequestWatch", () => { | 561 | 561 | } | 562 | 562 | }); | 563 | 563 |
| | 564 | + it("reports a retry that fails again where the run keeps its URL", () => { | | 565 | + // GitLab retries failed jobs inside the same pipeline, so only the run ID moves. | | 566 | + const pipeline = (finishedAt: string): PullRequestCheck => ({ | | 567 | + ...check("Pipeline", "failure"), | | 568 | + url: "https://gitlab.example/o/r/-/pipelines/7", | | 569 | + runId: `7@${finishedAt}`, | | 570 | + }); | | 571 | + const first = pipeline("2026-11-10T00:28:57.000Z"); | | 572 | + const again = pipeline("2026-11-10T00:39:53.000Z"); | | 573 | + const told = evaluatePullRequestWatch(watch(), detail({ checks: [first] }), noRemarks); | | 574 | + assert.deepEqual(told.changes, [{ kind: "checks-failed", failed: [first] }]); | | 575 | + assert.deepEqual( | | 576 | + evaluatePullRequestWatch(told.next, detail({ checks: [first] }), noRemarks).changes, | | 577 | + [], | | 578 | + ); | | 579 | + const retried = evaluatePullRequestWatch(told.next, detail({ checks: [again] }), noRemarks); | | 580 | + assert.deepEqual(retried.changes, [{ kind: "checks-failed", failed: [again] }]); | | 581 | + assert.deepEqual( | | 582 | + evaluatePullRequestWatch(retried.next, detail({ checks: [again] }), noRemarks).changes, | | 583 | + [], | | 584 | + ); | | 585 | + }); | | 586 | + | 564 | 587 | it("does not repeat a failure an older watch told by name", () => { | 565 | 588 | const older = watch({ headSha: "aaaaaaaaaa", failedChecks: ["lint"] }); | 566 | 589 | const failed = detail({ checks: [check("lint", "failure")] }); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/pullRequestWatch.ts +6-3Lines changed: 6 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -82,10 +82,13 @@ export function evaluatePullRequestWatch( | 82 | 82 | const failed = checks.filter(isFailedCheck); | 83 | 83 | const awaiting = checks.filter((check) => check.status === "action-required"); | 84 | 84 | const failedBefore = failedChecks; | 85 | | - // A new run URL under a failing name is a rerun that failed again between reads. | | 85 | + // A new run under a failing name is a rerun that failed again between reads. A run is its | | 86 | + // URL, or the host's run ID where the URL stays the same across reruns. | 86 | 87 | const toldRuns = failedRuns; | 87 | | - const runOf = (check: PullRequestCheck) => | 88 | | - check.url === null ? null : JSON.stringify([check.name, check.url]); | | 88 | + const runOf = (check: PullRequestCheck) => { | | 89 | + const run = check.runId ?? check.url; | | 90 | + return run === null ? null : JSON.stringify([check.name, run]); | | 91 | + }; | 89 | 92 | const newlyFailed = failed.filter((check) => { | 90 | 93 | const run = runOf(check); | 91 | 94 | return ( | |
Collapse file Copy file name to clipboardExpand all lines: packages/contracts/src/pullRequest.ts +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -121,6 +121,11 @@ export const PullRequestCheck = Schema.Struct({ | 121 | 121 | * approval when that read fails, so nothing waits on it or counts it as passing. | 122 | 122 | */ | 123 | 123 | placeholder: Schema.optional(Schema.Boolean), | | 124 | + /** | | 125 | + * Tells this run of the check apart from earlier ones where its URL does not change on a | | 126 | + * rerun, such as a GitLab pipeline whose failed jobs were retried in place. | | 127 | + */ | | 128 | + runId: Schema.optional(TrimmedNonEmptyString), | 124 | 129 | }); | 125 | 130 | export type PullRequestCheck = typeof PullRequestCheck.Type; | 126 | 131 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/source-control-gitlab/src/server/gitLabMergeRequestJson.test.ts +26Lines changed: 26 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -196,6 +196,32 @@ describe("decodeMergeRequestDetailJson", () => { | 196 | 196 | ]); | 197 | 197 | }); | 198 | 198 |
| | 199 | + it("tells each finish of a pipeline apart, since a job retry keeps its URL", () => { | | 200 | + const pipelineCheck = (pipeline: Record<string, unknown>) => | | 201 | + expectSuccess(decodeMergeRequestDetailJson(detailJson({ head_pipeline: pipeline }))) | | 202 | + .checks[0]; | | 203 | + const failed = (finishedAt: string) => | | 204 | + pipelineCheck({ | | 205 | + id: 3047545127, | | 206 | + status: "failed", | | 207 | + web_url: "https://gitlab.com/acme/web/-/pipelines/3047545127", | | 208 | + finished_at: finishedAt, | | 209 | + }); | | 210 | + | | 211 | + const first = failed("2026-11-10T00:28:57.753Z"); | | 212 | + const retried = failed("2026-11-10T00:39:53.753Z"); | | 213 | + expect(first?.url).toBe(retried?.url); | | 214 | + expect(first?.runId).toBe("3047545127@2026-11-10T00:28:57.753Z"); | | 215 | + expect(retried?.runId).toBe("3047545127@2026-11-10T00:39:53.753Z"); | | 216 | + // A running pipeline has no finish time yet, and one without an ID has nothing to key on. | | 217 | + expect(pipelineCheck({ id: 3047545127, status: "running", finished_at: null })?.runId).toBe( | | 218 | + undefined, | | 219 | + ); | | 220 | + expect( | | 221 | + pipelineCheck({ status: "failed", finished_at: "2026-11-10T00:39:53.753Z" })?.runId, | | 222 | + ).toBe(undefined); | | 223 | + }); | | 224 | + | 199 | 225 | it.each(["canceled", "canceling"])("maps a %s pipeline to cancelled", (status) => { | 200 | 226 | const detail = expectSuccess( | 201 | 227 | decodeMergeRequestDetailJson(detailJson({ head_pipeline: { status } })), | |
Collapse file Copy file name to clipboardExpand all lines: packages/source-control-gitlab/src/server/gitLabMergeRequestJson.ts +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -41,6 +41,7 @@ const RawPipelineSchema = Schema.Struct({ | 41 | 41 | status: Schema.optional(Schema.NullOr(Schema.String)), | 42 | 42 | web_url: Schema.optional(Schema.NullOr(Schema.String)), | 43 | 43 | source: Schema.optional(Schema.NullOr(Schema.String)), | | 44 | + finished_at: Schema.optional(Schema.NullOr(Schema.String)), | 44 | 45 | }); | 45 | 46 |
| 46 | 47 | const RawTriggerJobSchema = Schema.Struct({ | @@ -335,12 +336,18 @@ function toChecks( | 335 | 336 | ): ReadonlyArray<PullRequestCheck> { | 336 | 337 | const pipeline = raw.head_pipeline; | 337 | 338 | if (!pipeline) return []; | | 339 | + // Retrying jobs reruns them inside the same pipeline, so its URL stays the same. Each time it | | 340 | + // finishes again, its finish time moves, and that tells a retry that failed again apart. | | 341 | + const finishedAt = trimmed(pipeline.finished_at); | 338 | 342 | return [ | 339 | 343 | { | 340 | 344 | name: "Pipeline", | 341 | 345 | status: toPipelineStatus(pipeline.status), | 342 | 346 | description: trimmed(pipeline.source), | 343 | 347 | url: trimmed(pipeline.web_url), | | 348 | + ...(pipeline.id == null || finishedAt === null | | 349 | + ? {} | | 350 | + : { runId: `${pipeline.id}@${finishedAt}` }), | 344 | 351 | }, | 345 | 352 | ]; | 346 | 353 | } | |
|