The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 19:30 UTC
fix(gitcafe): authored lists, merge progress, and author reviews match git.cafe (#23887)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 22, 2026 at 15:52 UTC
f9c1d023f1dad68360e19a8db89c9c485e2da410
3 files changed
+134
-27
packages/source-control-gitcafe/src/server/GitCafePullRequestProvider.test.ts
+74
-6
@@ -271,6 +271,23 @@ describe("GitCafePullRequestProvider", () => {
271
}).pipe(Effect.provide(server.layer));
272
});
273
274
+ it.effect("keeps the timeline when GitCafe no longer has the head's commits", () => {
275
+ const comment = { ...root, id: "c1", threadId: "c1", body: "Looks good", path: null };
276
+ const server = fakeGitCafe({
277
+ "GET /repos/owner/repo/pulls/7": { ...pull, state: "closed", closedAt: timestamp },
278
+ "GET /repos/owner/repo/pulls/7/comments": { items: [comment], next: null },
279
+ "GET /repos/owner/repo/pulls/7/reviews": { items: [], next: null },
280
+ });
281
+ return Effect.gen(function* () {
282
+ const provider = yield* GitCafePullRequestProvider.make;
283
+ const activity = yield* provider.getChangeRequestActivity(target);
284
+ assert.deepStrictEqual(
285
+ activity.comments.map((entry) => entry.body),
286
+ ["Looks good"],
287
+ );
288
+ }).pipe(Effect.provide(server.layer));
289
+ });
290
+
291
it.effect("submits a review against the pull request's current head", () => {
292
const server = fakeGitCafe({
293
"GET /repos/owner/repo/pulls/7": pull,
@@ -381,9 +398,7 @@ describe("GitCafePullRequestProvider", () => {
398
["reviewing", "reviewers"],
399
] as const)("filters %s pull requests by the viewer's actor on GitCafe", ([involvement, key]) => {
400
const server = fakeGitCafe({
384
- "GET /repos/owner/repo/filter-options": {
385
- actors: [{ actorId: "act_one", handle: "Alice" }],
386
- },
401
+ "GET /auth/principal": { actorId: "act_one", handle: "Alice" },
402
"GET /repos/owner/repo/pulls": { items: [pull], next: null },
403
});
404
return Effect.gen(function* () {
@@ -403,9 +418,9 @@ describe("GitCafePullRequestProvider", () => {
418
}).pipe(Effect.provide(server.layer));
419
});
420
406
- it.effect("lists nothing for a viewer GitCafe has no actor for", () => {
421
+ it.effect("lists nothing for a viewer the token does not belong to", () => {
422
const server = fakeGitCafe({
408
- "GET /repos/owner/repo/filter-options": { actors: [] },
423
+ "GET /auth/principal": { actorId: "act_two", handle: "bob" },
424
});
425
return Effect.gen(function* () {
426
const provider = yield* GitCafePullRequestProvider.make;
@@ -419,7 +434,7 @@ describe("GitCafePullRequestProvider", () => {
434
assert.deepStrictEqual(page.items, []);
435
assert.deepStrictEqual(
436
server.sent.map((request) => request.path),
422
- ["/repos/owner/repo/filter-options"],
437
+ ["/auth/principal"],
438
);
439
}).pipe(Effect.provide(server.layer));
440
});
@@ -557,6 +572,59 @@ describe("GitCafePullRequestProvider", () => {
572
}).pipe(Effect.provide(server.layer));
573
});
574
575
+ const detailWith = (overrides: Record<string, unknown>, reasons: ReadonlyArray<string> = []) =>
576
+ fakeGitCafe({
577
+ "GET /repos/owner/repo/pulls/7": { ...pull, headOid: null, ...overrides },
578
+ "GET /repos/owner/repo/pulls/7/reviewers": { items: [], next: null },
579
+ "GET /repos/owner/repo/pulls/7/labels": { items: [], next: null },
580
+ "GET /repos/owner/repo/pulls/7/status": {
581
+ merge: { conflicts: "none", fastForward: null, strategies: ["squash"], reasons },
582
+ checks: { pending: 0, failing: 0, total: 0 },
583
+ },
584
+ });
585
+
586
+ it.effect("shows a merge GitCafe accepted as armed until it lands", () => {
587
+ const server = detailWith({}, ["provider-merge-pending"]);
588
+ return Effect.gen(function* () {
589
+ const provider = yield* GitCafePullRequestProvider.make;
590
+ const detail = yield* provider.getChangeRequest(target);
591
+ assert.strictEqual(detail.autoMergeEnabled, true);
592
+ assert.notInclude(detail.viewerPermissions?.actions ?? [], "merge");
593
+ }).pipe(Effect.provide(server.layer));
594
+ });
595
+
596
+ it.effect("reads a pull request GitHub merged as merged before the sync reports it", () => {
597
+ const mergedAt = "2026-09-12T13:00:00Z";
598
+ const server = detailWith({ providerMerge: { mergedAt } });
599
+ return Effect.gen(function* () {
600
+ const provider = yield* GitCafePullRequestProvider.make;
601
+ const detail = yield* provider.getChangeRequest(target);
602
+ assert.strictEqual(detail.state, "merged");
603
+ assert.strictEqual(detail.mergedAt, mergedAt);
604
+ }).pipe(Effect.provide(server.layer));
605
+ });
606
+
607
+ it.effect.each([
608
+ ["their own pull request", actor],
609
+ [
610
+ "the pull request GitHub sync opened for them",
611
+ {
612
+ kind: "github",
613
+ actorId: "act_github",
614
+ login: "alice",
615
+ avatarUrl: null,
616
+ linkedProfile: { handle: "alice", actorId: "act_one" },
617
+ },
618
+ ],
619
+ ] as const)("leaves the author only a comment on %s", ([, author]) => {
620
+ const server = detailWith({ author, viewerActorId: "act_one" });
621
+ return Effect.gen(function* () {
622
+ const provider = yield* GitCafePullRequestProvider.make;
623
+ const detail = yield* provider.getChangeRequest(target);
624
+ assert.deepStrictEqual(detail.viewerPermissions?.verdicts, ["comment"]);
625
+ }).pipe(Effect.provide(server.layer));
626
+ });
627
+
628
it.effect("requests and withdraws reviewers by rewriting the whole list", () => {
629
const bob = { ...actor, actorId: "act_two", handle: "bob" };
630
let requested = [{ id: "act_two", actor: bob }];
packages/source-control-gitcafe/src/server/GitCafePullRequestProvider.ts
+35
-19
@@ -73,7 +73,7 @@ const mergeStrategyOpen = (status: typeof Status.Type, strategy: string) =>
73
const Id = TrimmedNonEmptyString.check(Schema.isPattern(/^[A-Za-z0-9_-]+$/u));
74
const isId = Schema.is(Id);
75
const isApiError = Schema.is(GitCafeApi.GitCafeApiError);
76
-const Principal = Schema.Struct({ handle: TrimmedNonEmptyString });
76
+const Principal = Schema.Struct({ actorId: TrimmedNonEmptyString, handle: TrimmedNonEmptyString });
77
const Written = Schema.Struct({ id: Id });
78
const Versioned = Schema.Struct({ version: NonNegativeInt });
79
const CommentDetail = Schema.Struct({ id: Id, version: NonNegativeInt });
@@ -85,6 +85,7 @@ const Status = Schema.Struct({
85
fastForward: Schema.NullOr(Schema.Boolean),
86
strategies: Schema.Array(Schema.String),
87
permitted: Schema.optional(Schema.Boolean),
88
+ reasons: Schema.optional(Schema.Array(Schema.String)),
89
blockers: Schema.optional(
90
Schema.Array(
91
Schema.Struct({ blockedStrategies: Schema.optional(Schema.Array(Schema.String)) }),
@@ -97,15 +98,12 @@ const Status = Schema.Struct({
98
total: NonNegativeInt,
99
}),
100
});
101
+/** A merge GitCafe accepted runs on afterwards: on GitHub for a synced pull request, or natively. */
102
+const MERGE_IN_FLIGHT = new Set(["provider-merge-pending", "native-operation-pending"]);
103
const Listed = Schema.Struct({
104
items: Schema.Array(Schema.Struct({ id: TrimmedNonEmptyString })),
105
next: Schema.NullOr(Schema.String),
106
});
104
-const FilterOptions = Schema.Struct({
105
- actors: Schema.Array(
106
- Schema.Struct({ actorId: TrimmedNonEmptyString, handle: TrimmedNonEmptyString }),
107
- ),
108
-});
107
const encodeActorIds = Schema.encodeSync(Schema.fromJsonString(Schema.Array(Schema.String)));
108
const BranchCommit = Schema.Struct({ oid: TrimmedNonEmptyString });
109
const Snapshot = {
@@ -136,6 +134,12 @@ const StackOutcome = Schema.Struct({ id: Schema.String, state: Schema.String });
134
const FAILED_STACK_STATES = new Set(["failed", "stopped", "cancelled", "reconciliation_required"]);
135
136
type PullRef = ProviderRepositoryRef & { readonly number: number };
137
+
138
+/** GitHub's merge counts as soon as GitCafe records it, ahead of the sync that reports it. */
139
+const settledMerge = (pull: Json.GitCafePullDetail) =>
140
+ pull.state === "open" && pull.providerMerge != null
141
+ ? { state: "merged" as const, mergedAt: pull.providerMerge.mergedAt }
142
+ : {};
143
type Paged<A> = { readonly items: ReadonlyArray<A>; readonly next: string | null };
144
145
function stackHeadsCurrent(
@@ -542,14 +546,15 @@ export const make = Effect.gen(function* () {
546
const involved = input.involvement === "authored" || input.involvement === "reviewing";
547
let actorId: string | undefined;
548
if (involved) {
545
- // A host narrows as far as it can: when the actor list can't be read, the listing comes
546
- // back unnarrowed and the page's own involvement filter does the rest. A refused token
547
- // or a rate limit still fails, since the service acts on those for the whole host.
548
- const options = yield* read(
549
+ // The viewer is the token's principal, whose actor also matches the pull requests GitHub
550
+ // sync authored for its linked profile. When it can't be read, the listing comes back
551
+ // unnarrowed and the page's own involvement filter does the rest. A refused token or a
552
+ // rate limit still fails, since the service acts on those for the whole host.
553
+ const principal = yield* read(
554
"listChangeRequests",
555
input,
551
- { path: `${base}/filter-options` },
552
- FilterOptions,
556
+ { path: "/auth/principal" },
557
+ Principal,
558
).pipe(
559
Effect.map(Option.some),
560
Effect.catchTags({
@@ -559,11 +564,10 @@ export const make = Effect.gen(function* () {
564
: Effect.succeed(Option.none()),
565
}),
566
);
562
- if (Option.isSome(options)) {
563
- actorId = options.value.actors.find(
564
- (actor) => actor.handle.toLowerCase() === input.viewer.toLowerCase(),
565
- )?.actorId;
566
- if (actorId === undefined) return { items: [], truncated: false, continues: false };
567
+ if (Option.isSome(principal)) {
568
+ if (principal.value.handle.toLowerCase() !== input.viewer.toLowerCase())
569
+ return { items: [], truncated: false, continues: false };
570
+ actorId = principal.value.actorId;
571
}
572
}
573
const limit = Math.max(1, input.limit);
@@ -624,6 +628,7 @@ export const make = Effect.gen(function* () {
628
...(changes === null ? {} : changes),
629
closedAt: pull.closedAt,
630
mergedAt: pull.mergedAt,
631
+ ...settledMerge(pull),
632
};
633
},
634
),
@@ -658,8 +663,10 @@ export const make = Effect.gen(function* () {
663
);
664
const listed = { ...pull, reviewers: reviewers.items, labels: labels.items };
665
const permissions = Json.toViewerPermissions(pull);
666
+ const merging = status.merge.reasons?.some((reason) => MERGE_IN_FLIGHT.has(reason)) ?? false;
667
return {
668
...Json.toChangeRequest(listed, input),
669
+ autoMergeEnabled: merging,
670
headSha: pull.headOid,
671
body: pull.description ?? "",
672
...(pull.sourceRepo === null
@@ -670,6 +677,7 @@ export const make = Effect.gen(function* () {
677
changedFiles: changes?.changedFiles ?? 0,
678
closedAt: pull.closedAt,
679
mergedAt: pull.mergedAt,
680
+ ...settledMerge(pull),
681
reviewers: Json.toReviewers(listed, input.host),
682
checks: checks === null ? [] : Json.toChecks(checks),
683
...(status.checks.total === 0
@@ -700,7 +708,7 @@ export const make = Effect.gen(function* () {
708
rebase: mergeStrategyOpen(status, "rebase"),
709
},
710
viewerPermissions:
703
- status.merge.permitted === false
711
+ status.merge.permitted === false || merging
712
? { ...permissions, actions: permissions.actions.filter((a) => a !== "merge") }
713
: permissions,
714
};
@@ -720,7 +728,15 @@ export const make = Effect.gen(function* () {
728
readPages(operation, input, `${path}/reviews`, Json.GitCafeReviews),
729
pull.headOid === null
730
? Effect.succeed({ items: [], next: null })
723
- : readPages(operation, input, `${path}/commits`, Json.GitCafeCommits),
731
+ : // A closed pull request whose branch is gone keeps its head, but git.cafe answers
732
+ // 404 for commits it no longer has; the conversation still stands without them.
733
+ readPages(operation, input, `${path}/commits`, Json.GitCafeCommits).pipe(
734
+ Effect.catch((error) =>
735
+ error.reason === "not-found"
736
+ ? Effect.succeed({ items: [], next: null })
737
+ : Effect.fail(error),
738
+ ),
739
+ ),
740
readPages(operation, input, `${path}/reactions/`, Json.GitCafeReactions).pipe(
741
Effect.orElseSucceed(() => undefined),
742
),
packages/source-control-gitcafe/src/server/gitCafePullRequestJson.ts
+25
-2
@@ -37,7 +37,11 @@ const Actor = Schema.Union([
37
actorId: Schema.String,
38
login: TrimmedNonEmptyString,
39
avatarUrl: Schema.NullOr(Schema.String),
40
- linkedProfile: Schema.optional(Schema.NullOr(Schema.Struct({ handle: TrimmedNonEmptyString }))),
40
+ linkedProfile: Schema.optional(
41
+ Schema.NullOr(
42
+ Schema.Struct({ handle: TrimmedNonEmptyString, actorId: Schema.optional(Schema.String) }),
43
+ ),
44
+ ),
45
}),
46
Schema.Struct({ kind: Schema.Literal("unavailable"), actorId: Schema.String }),
47
]);
@@ -81,6 +85,10 @@ export const GitCafePullDetail = Schema.Struct({
85
observedBaseOid: Schema.optional(Schema.NullOr(Schema.String)),
86
mergeRoute: Schema.optional(Schema.Literals(["native", "provider", "unsupported"])),
87
lockedAt: Schema.optional(Schema.NullOr(IsoDateTime)),
88
+ viewerActorId: Schema.optional(Schema.NullOr(Schema.String)),
89
+ // Set once GitHub has merged a pull request GitCafe routed there, which can be before the
90
+ // sync brings the merged state back.
91
+ providerMerge: Schema.optional(Schema.NullOr(Schema.Struct({ mergedAt: IsoDateTime }))),
92
capabilities: Schema.Struct({
93
comment: Schema.Boolean,
94
review: Schema.Boolean,
@@ -334,6 +342,16 @@ export function toChangeRequest(
342
};
343
}
344
345
+function isViewerAuthor(detail: GitCafePullDetail): boolean {
346
+ const viewer = detail.viewerActorId;
347
+ if (viewer == null) return false;
348
+ const { author } = detail;
349
+ return (
350
+ author.actorId === viewer ||
351
+ (author.kind === "github" && author.linkedProfile?.actorId === viewer)
352
+ );
353
+}
354
+
355
export function toViewerPermissions(detail: GitCafePullDetail): PullRequestViewerPermissions {
356
const { comment, edit, review, merge, moderate } = detail.capabilities;
357
const open = comment && (detail.lockedAt == null || moderate);
@@ -349,7 +367,12 @@ export function toViewerPermissions(detail: GitCafePullDetail): PullRequestViewe
367
stackRebase: merge,
368
comment: open,
369
resolve: open,
352
- verdicts: review ? ["approve", "request-changes", "comment"] : [],
370
+ // GitCafe refuses an author's approval and request for changes, as GitHub does.
371
+ verdicts: !review
372
+ ? []
373
+ : isViewerAuthor(detail)
374
+ ? ["comment"]
375
+ : ["approve", "request-changes", "comment"],
376
requestReviewers: edit && detail.state === "open",
377
labels: edit && detail.state === "open",
378
editChangeRequest: edit,