GeezerVison is showing github.com — fix(gitlab): a watch reports a pipeline retry that fails again (#33671) · ryush00/t3code@0d1f688
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 |
|---|
@@ -616,6 +616,29 @@ describe("evaluatePullRequestWatch", () => { | 616 | 616 | } | 617 | 617 | }); | 618 | 618 |
| | 619 | + it("reports a retry that fails again where the run keeps its URL", () => { | | 620 | + // GitLab retries failed jobs inside the same pipeline, so only the run ID moves. | | 621 | + const pipeline = (finishedAt: string): PullRequestCheck => ({ | | 622 | + ...check("Pipeline", "failure"), | | 623 | + url: "https://gitlab.example/o/r/-/pipelines/7", | | 624 | + runId: `7@${finishedAt}`, | | 625 | + }); | | 626 | + const first = pipeline("2026-11-10T00:28:57.000Z"); | | 627 | + const again = pipeline("2026-11-10T00:39:53.000Z"); | | 628 | + const told = evaluatePullRequestWatch(watch(), detail({ checks: [first] }), noRemarks); | | 629 | + assert.deepEqual(told.changes, [{ kind: "checks-failed", failed: [first] }]); | | 630 | + assert.deepEqual( | | 631 | + evaluatePullRequestWatch(told.next, detail({ checks: [first] }), noRemarks).changes, | | 632 | + [], | | 633 | + ); | | 634 | + const retried = evaluatePullRequestWatch(told.next, detail({ checks: [again] }), noRemarks); | | 635 | + assert.deepEqual(retried.changes, [{ kind: "checks-failed", failed: [again] }]); | | 636 | + assert.deepEqual( | | 637 | + evaluatePullRequestWatch(retried.next, detail({ checks: [again] }), noRemarks).changes, | | 638 | + [], | | 639 | + ); | | 640 | + }); | | 641 | + | 619 | 642 | it("does not repeat a failure an older watch told by name", () => { | 620 | 643 | const older = watch({ headSha: "aaaaaaaaaa", failedChecks: ["lint"] }); | 621 | 644 | 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 |
|---|
@@ -91,10 +91,13 @@ export function evaluatePullRequestWatch( | 91 | 91 | const failed = checks.filter(isFailedCheck); | 92 | 92 | const awaiting = checks.filter((check) => check.status === "action-required"); | 93 | 93 | const failedBefore = failedChecks; | 94 | | - // A new run URL under a failing name is a rerun that failed again between reads. | | 94 | + // A new run under a failing name is a rerun that failed again between reads. A run is its | | 95 | + // URL, or the host's run ID where the URL stays the same across reruns. | 95 | 96 | const toldRuns = failedRuns; | 96 | | - const runOf = (check: PullRequestCheck) => | 97 | | - check.url === null ? null : JSON.stringify([check.name, check.url]); | | 97 | + const runOf = (check: PullRequestCheck) => { | | 98 | + const run = check.runId ?? check.url; | | 99 | + return run === null ? null : JSON.stringify([check.name, run]); | | 100 | + }; | 98 | 101 | const newlyFailed = failed.filter((check) => { | 99 | 102 | const run = runOf(check); | 100 | 103 | 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 |
|---|
@@ -122,6 +122,11 @@ export const PullRequestCheck = Schema.Struct({ | 122 | 122 | * approval when that read fails, so nothing waits on it or counts it as passing. | 123 | 123 | */ | 124 | 124 | placeholder: Schema.optional(Schema.Boolean), | | 125 | + /** | | 126 | + * Tells this run of the check apart from earlier ones where its URL does not change on a | | 127 | + * rerun, such as a GitLab pipeline whose failed jobs were retried in place. | | 128 | + */ | | 129 | + runId: Schema.optional(TrimmedNonEmptyString), | 125 | 130 | }); | 126 | 131 | export type PullRequestCheck = typeof PullRequestCheck.Type; | 127 | 132 |
| |
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 | } | |
|