The best way to control Claude Code, Codex and more from any computer or phone
fix(source-control): GitCafe checks show each check's newest run (#24406)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 24, 2026 at 12:49 UTC
ea41701979c3cb110addeacd144923abe1ba07b2
4 files changed
+142
-14
packages/source-control-gitcafe/src/server/GitCafePullRequestProvider.test.ts
+51
@@ -648,6 +648,57 @@ describe("GitCafePullRequestProvider", () => {
648
}).pipe(Effect.provide(server.layer));
649
});
650
651
+ it.effect("reads the checks state from each check's newest run", () => {
652
+ const run = (id: string, conclusion: string) => ({
653
+ id,
654
+ name: "Check",
655
+ status: "completed",
656
+ conclusion,
657
+ summary: null,
658
+ detailsUrl: null,
659
+ });
660
+ const items = [run("120859457782", "success"), run("120857059247", "failure")];
661
+ const detailWith = (checks: (request: SentRequest) => unknown) => {
662
+ const server = fakeGitCafe({
663
+ "GET /repos/owner/repo/pulls/7": pull,
664
+ "GET /repos/owner/repo/pulls/7/reviewers": { items: [], next: null },
665
+ "GET /repos/owner/repo/pulls/7/labels": { items: [], next: null },
666
+ "GET /repos/owner/repo/pulls/7/status": {
667
+ merge: { conflicts: "none", fastForward: null, strategies: [] },
668
+ // GitCafe counts the cancelled run's failure beside the re-run that passed.
669
+ checks: { pending: 0, failing: 1, total: 2 },
670
+ },
671
+ [`GET /repos/owner/repo/commits/${headOid}/checks`]: checks,
672
+ "GET /repos/owner/repo/pulls/7/changes": {
673
+ version: 4,
674
+ headOid,
675
+ comparisonBaseOid: baseOid,
676
+ items: [],
677
+ next: null,
678
+ },
679
+ });
680
+ return Effect.gen(function* () {
681
+ const provider = yield* GitCafePullRequestProvider.make;
682
+ return yield* provider.getChangeRequest(target);
683
+ }).pipe(Effect.provide(server.layer));
684
+ };
685
+ return Effect.gen(function* () {
686
+ const detail = yield* detailWith(() => ({ items, next: null }));
687
+ assert.deepStrictEqual(
688
+ detail.checks.map((check) => [check.name, check.status]),
689
+ [["Check", "success"]],
690
+ );
691
+ assert.strictEqual(detail.checksState, "passing");
692
+
693
+ // A listing cut off at the page limit may hide a failure, so GitCafe's counts decide.
694
+ const truncated = yield* detailWith((request) => ({
695
+ items,
696
+ next: String(Number(request.query.get("after") ?? 0) + 1),
697
+ }));
698
+ assert.strictEqual(truncated.checksState, "failing");
699
+ });
700
+ });
701
+
702
it.effect("still reads a pull request whose reviewers the token may not see", () => {
703
const server = fakeGitCafe({
704
"GET /repos/owner/repo/pulls/7": { ...pull, headOid: null },
packages/source-control-gitcafe/src/server/GitCafePullRequestProvider.ts
+15
-11
@@ -796,6 +796,19 @@ export const make = Effect.gen(function* () {
796
{ concurrency: 5 },
797
);
798
const listed = { ...pull, reviewers: reviewers.items, labels: labels.items };
799
+ const checkList = checks === null ? [] : Json.toChecks(checks);
800
+ // GitCafe's own counts include runs a re-run replaced, so the newest runs are the state. A
801
+ // truncated listing may be missing a failure; the counts never call failing checks passing.
802
+ const checksState =
803
+ checks !== null && checks.next === null
804
+ ? Json.checksStateOf(checkList)
805
+ : status.checks.total === 0
806
+ ? null
807
+ : status.checks.failing > 0
808
+ ? ("failing" as const)
809
+ : status.checks.pending > 0
810
+ ? ("pending" as const)
811
+ : ("passing" as const);
812
const permissions = Json.toViewerPermissions(pull);
813
const merging = status.merge.reasons?.some((reason) => MERGE_IN_FLIGHT.has(reason)) ?? false;
814
return {
@@ -813,17 +826,8 @@ export const make = Effect.gen(function* () {
826
mergedAt: pull.mergedAt,
827
...settledMerge(pull),
828
reviewers: Json.toReviewers(listed, input.host),
816
- checks: checks === null ? [] : Json.toChecks(checks),
817
- ...(status.checks.total === 0
818
- ? {}
819
- : {
820
- checksState:
821
- status.checks.failing > 0
822
- ? ("failing" as const)
823
- : status.checks.pending > 0
824
- ? ("pending" as const)
825
- : ("passing" as const),
826
- }),
829
+ checks: checkList,
830
+ ...(checksState === null ? {} : { checksState }),
831
mergeability:
832
status.merge.conflicts === "conflicting"
833
? ("conflicting" as const)
packages/source-control-gitcafe/src/server/gitCafePullRequestJson.test.ts
+31
-2
@@ -429,7 +429,7 @@ describe("toChecks", () => {
429
check("completed", "success", "Build"),
430
check("completed", "cancelled"),
431
check("completed", "action_required"),
432
- check("completed", "timed_out", "Build"),
432
+ check("completed", "timed_out", "Lint"),
433
],
434
next: null,
435
}),
@@ -438,7 +438,7 @@ describe("toChecks", () => {
438
checks.map((item) => [item.name, item.status]),
439
[
440
["completed-cancelled", "cancelled"],
441
- ["Build", "failure"],
441
+ ["Lint", "failure"],
442
["queued-null", "pending"],
443
["in_progress-null", "pending"],
444
["Build", "success"],
@@ -446,4 +446,33 @@ describe("toChecks", () => {
446
],
447
);
448
});
449
+
450
+ it("keeps only the newest run of a re-run check", () => {
451
+ const run = (id: string, conclusion: string, githubApp = "github-actions") => ({
452
+ id,
453
+ provider: "github",
454
+ githubApp,
455
+ name: "Check",
456
+ status: "completed",
457
+ conclusion,
458
+ summary: null,
459
+ detailsUrl: null,
460
+ });
461
+ const statusOf = (items: ReadonlyArray<ReturnType<typeof run>>) =>
462
+ GitCafePullRequestJson.toChecks(decodeChecks({ items, next: null })).map(
463
+ (check) => check.status,
464
+ );
465
+ assert.deepStrictEqual(statusOf([run("99", "failure"), run("100", "success")]), ["success"]);
466
+ assert.deepStrictEqual(statusOf([run("101", "failure"), run("100", "success")]), ["failure"]);
467
+ // Another app's run of the same name is a separate check, not a re-run.
468
+ assert.deepStrictEqual(statusOf([run("100", "failure", "a"), run("101", "success", "b")]), [
469
+ "failure",
470
+ "success",
471
+ ]);
472
+ // Commit statuses carry no run order, so neither is taken for the other's re-run.
473
+ assert.deepStrictEqual(statusOf([run("status:2", "failure"), run("status:1", "success")]), [
474
+ "failure",
475
+ "success",
476
+ ]);
477
+ });
478
});
packages/source-control-gitcafe/src/server/gitCafePullRequestJson.ts
+45
-1
@@ -9,6 +9,7 @@ import {
9
TrimmedNonEmptyString,
10
type PullRequestActor,
11
type PullRequestCheck,
12
+ type PullRequestChecksState,
13
type PullRequestComment,
14
type PullRequestReaction,
15
type PullRequestReactionContent,
@@ -258,6 +259,9 @@ export const GitCafeDiff = Schema.Struct({
259
export const GitCafeChecks = Schema.Struct({
260
items: Schema.Array(
261
Schema.Struct({
262
+ id: Schema.optional(Schema.NullOr(Schema.String)),
263
+ provider: Schema.optional(Schema.NullOr(Schema.String)),
264
+ githubApp: Schema.optional(Schema.NullOr(Schema.String)),
265
name: TrimmedNonEmptyString,
266
status: Schema.Literals(["queued", "in_progress", "completed"]),
267
conclusion: Schema.NullOr(Schema.String),
@@ -638,9 +642,40 @@ function checkStatus(check: (typeof GitCafeChecks.Type.items)[number]): PullRequ
642
}
643
}
644
645
+type GitCafeCheck = (typeof GitCafeChecks.Type.items)[number];
646
+
647
+/** A check run's id, which grows with each run. Commit statuses (`status:…`) carry no such order. */
648
+function runOrder(check: GitCafeCheck): bigint | null {
649
+ return check.id != null && /^\d+$/u.test(check.id) ? BigInt(check.id) : null;
650
+}
651
+
652
+/**
653
+ * GitCafe lists every run of a commit's checks, so a re-run arrives beside the run it replaced.
654
+ * The newest run is the check's state; an older failure is history, not a failing check. Runs whose
655
+ * order cannot be told apart are all kept, so no failure is hidden. Two reporters may share a check
656
+ * name, so a run only replaces runs from the same provider and GitHub app.
657
+ */
658
export function toChecks(checks: typeof GitCafeChecks.Type): ReadonlyArray<PullRequestCheck> {
659
+ const kept: Array<GitCafeCheck> = [];
660
+ const newestByKey = new Map<string, { index: number; order: bigint }>();
661
+ for (const check of checks.items) {
662
+ const order = runOrder(check);
663
+ if (order === null) {
664
+ kept.push(check);
665
+ continue;
666
+ }
667
+ const key = JSON.stringify([check.provider ?? null, check.githubApp ?? null, check.name]);
668
+ const newest = newestByKey.get(key);
669
+ if (newest === undefined) {
670
+ newestByKey.set(key, { index: kept.length, order });
671
+ kept.push(check);
672
+ } else if (order > newest.order) {
673
+ kept[newest.index] = check;
674
+ newest.order = order;
675
+ }
676
+ }
677
return sortChecks(
643
- checks.items.map((check) => ({
678
+ kept.map((check) => ({
679
name: check.name,
680
status: checkStatus(check),
681
description: check.summary,
@@ -648,3 +683,12 @@ export function toChecks(checks: typeof GitCafeChecks.Type): ReadonlyArray<PullR
683
})),
684
);
685
}
686
+
687
+export function checksStateOf(
688
+ checks: ReadonlyArray<PullRequestCheck>,
689
+): PullRequestChecksState | null {
690
+ const statuses = new Set(checks.map((check) => check.status));
691
+ if (statuses.has("failure") || statuses.has("cancelled")) return "failing";
692
+ if (statuses.has("pending") || statuses.has("action-required")) return "pending";
693
+ return statuses.has("success") ? "passing" : null;
694
+}