GeezerVison is showing github.com — fix(gitlab): a watch reports a pipeline retry that fails again (#33671) · ryush00/t3code@8e0458f
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 |
|---|
@@ -510,6 +510,29 @@ describe("evaluatePullRequestWatch", () => { | 510 | 510 | } | 511 | 511 | }); | 512 | 512 |
| | 513 | + it("reports a retry that fails again where the run keeps its URL", () => { | | 514 | + // GitLab retries failed jobs inside the same pipeline, so only the run ID moves. | | 515 | + const pipeline = (finishedAt: string): PullRequestCheck => ({ | | 516 | + ...check("Pipeline", "failure"), | | 517 | + url: "https://gitlab.example/o/r/-/pipelines/7", | | 518 | + runId: `7@${finishedAt}`, | | 519 | + }); | | 520 | + const first = pipeline("2026-11-10T00:28:57.000Z"); | | 521 | + const again = pipeline("2026-11-10T00:39:53.000Z"); | | 522 | + const told = evaluatePullRequestWatch(watch(), detail({ checks: [first] }), noRemarks); | | 523 | + assert.deepEqual(told.changes, [{ kind: "checks-failed", failed: [first] }]); | | 524 | + assert.deepEqual( | | 525 | + evaluatePullRequestWatch(told.next, detail({ checks: [first] }), noRemarks).changes, | | 526 | + [], | | 527 | + ); | | 528 | + const retried = evaluatePullRequestWatch(told.next, detail({ checks: [again] }), noRemarks); | | 529 | + assert.deepEqual(retried.changes, [{ kind: "checks-failed", failed: [again] }]); | | 530 | + assert.deepEqual( | | 531 | + evaluatePullRequestWatch(retried.next, detail({ checks: [again] }), noRemarks).changes, | | 532 | + [], | | 533 | + ); | | 534 | + }); | | 535 | + | 513 | 536 | it("does not repeat a failure an older watch told by name", () => { | 514 | 537 | const older = watch({ headSha: "aaaaaaaaaa", failedChecks: ["lint"] }); | 515 | 538 | 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 |
|---|
@@ -78,10 +78,13 @@ export function evaluatePullRequestWatch( | 78 | 78 | if (checks.length > 0) { | 79 | 79 | // A run awaiting approval waits on a person, like a review, so only running checks count. | 80 | 80 | checksPending = checks.some((check) => check.status === "pending"); | 81 | | - // A new run URL under a failing name is a rerun that failed again between reads. | | 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. | 82 | 83 | const toldRuns = failedRuns; | 83 | | - const runOf = (check: PullRequestCheck) => | 84 | | - check.url === null ? null : JSON.stringify([check.name, check.url]); | | 84 | + const runOf = (check: PullRequestCheck) => { | | 85 | + const run = check.runId ?? check.url; | | 86 | + return run === null ? null : JSON.stringify([check.name, run]); | | 87 | + }; | 85 | 88 | const newlyFailed = failed.filter((check) => { | 86 | 89 | const run = runOf(check); | 87 | 90 | 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 |
|---|
@@ -186,6 +186,32 @@ describe("decodeMergeRequestDetailJson", () => { | 186 | 186 | ]); | 187 | 187 | }); | 188 | 188 |
| | 189 | + it("tells each finish of a pipeline apart, since a job retry keeps its URL", () => { | | 190 | + const pipelineCheck = (pipeline: Record<string, unknown>) => | | 191 | + expectSuccess(decodeMergeRequestDetailJson(detailJson({ head_pipeline: pipeline }))) | | 192 | + .checks[0]; | | 193 | + const failed = (finishedAt: string) => | | 194 | + pipelineCheck({ | | 195 | + id: 3047545127, | | 196 | + status: "failed", | | 197 | + web_url: "https://gitlab.com/acme/web/-/pipelines/3047545127", | | 198 | + finished_at: finishedAt, | | 199 | + }); | | 200 | + | | 201 | + const first = failed("2026-11-10T00:28:57.753Z"); | | 202 | + const retried = failed("2026-11-10T00:39:53.753Z"); | | 203 | + expect(first?.url).toBe(retried?.url); | | 204 | + expect(first?.runId).toBe("3047545127@2026-11-10T00:28:57.753Z"); | | 205 | + expect(retried?.runId).toBe("3047545127@2026-11-10T00:39:53.753Z"); | | 206 | + // A running pipeline has no finish time yet, and one without an ID has nothing to key on. | | 207 | + expect(pipelineCheck({ id: 3047545127, status: "running", finished_at: null })?.runId).toBe( | | 208 | + undefined, | | 209 | + ); | | 210 | + expect( | | 211 | + pipelineCheck({ status: "failed", finished_at: "2026-11-10T00:39:53.753Z" })?.runId, | | 212 | + ).toBe(undefined); | | 213 | + }); | | 214 | + | 189 | 215 | it.each(["canceled", "canceling"])("maps a %s pipeline to cancelled", (status) => { | 190 | 216 | const detail = expectSuccess( | 191 | 217 | 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({ | @@ -317,12 +318,18 @@ function toChecks( | 317 | 318 | ): ReadonlyArray<PullRequestCheck> { | 318 | 319 | const pipeline = raw.head_pipeline; | 319 | 320 | if (!pipeline) return []; | | 321 | + // Retrying jobs reruns them inside the same pipeline, so its URL stays the same. Each time it | | 322 | + // finishes again, its finish time moves, and that tells a retry that failed again apart. | | 323 | + const finishedAt = trimmed(pipeline.finished_at); | 320 | 324 | return [ | 321 | 325 | { | 322 | 326 | name: "Pipeline", | 323 | 327 | status: toPipelineStatus(pipeline.status), | 324 | 328 | description: trimmed(pipeline.source), | 325 | 329 | url: trimmed(pipeline.web_url), | | 330 | + ...(pipeline.id == null || finishedAt === null | | 331 | + ? {} | | 332 | + : { runId: `${pipeline.id}@${finishedAt}` }), | 326 | 333 | }, | 327 | 334 | ]; | 328 | 335 | } | |
|