@devries-cameron20 / t3code Mirror · read-only / commits / 5e59fc677f
Fork 0

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 21, 03:37 UTC

fix(server): pull_request_merge accepts an abbreviated head SHA (#39906)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 20, 2026 at 14:57 UTC 5e59fc677fbb52b75488659745c174c4a14a4b63
4 files changed +49 -20
apps/server/src/mcp/toolkits/pullRequests/handlers.test.ts
+10 -2
@@ -1024,6 +1024,7 @@ describe("source control tools", () => {
1024 Effect.gen(function* () {
1025 const actions: Array<PullRequestActionInput> = [];
1026 let lowerHead: string | undefined = "bbb";
1027 + let targetHead = "stale";
1028 const layer = (number: number, state: "open" | "merged", headSha: string | undefined) => ({
1029 number,
1030 state,
@@ -1044,7 +1045,7 @@ describe("source control tools", () => {
1045 layers: [
1046 layer(40, "merged", "aaa"),
1047 layer(41, "open", lowerHead),
1047 - layer(42, "open", "stale"),
1048 + layer(42, "open", targetHead),
1049 layer(43, "open", "ddd"),
1050 ],
1051 }),
@@ -1064,12 +1065,19 @@ describe("source control tools", () => {
1065 ],
1066 },
1067 ]);
1068 + const fullHead = "c0ffee1234567890abcdef1234567890abcdef12";
1069 + targetHead = fullHead;
1070 + yield* harness.call("pull_request_merge", { expectedHeadSha: "c0ffee1", stack: true });
1071 + expect(actions[1]?.expectedStackHeads).toEqual([
1072 + { number: 41, headSha: "bbb" },
1073 + { number: 42, headSha: fullHead },
1074 + ]);
1075 lowerHead = undefined;
1076 const unpinned = yield* harness
1077 .call("pull_request_merge", { expectedHeadSha: "ccc", stack: true })
1078 .pipe(Effect.flip);
1079 expect(unpinned._tag).toBe("PullRequestForgeError");
1072 - expect(actions).toHaveLength(1);
1080 + expect(actions).toHaveLength(2);
1081 }),
1082 );
1083
apps/server/src/mcp/toolkits/pullRequests/handlers.ts
+7 -1
@@ -418,7 +418,13 @@ const make = Effect.gen(function* () {
418 const expectedStackHeads: Array<{ readonly number: number; readonly headSha: string }> = [];
419 for (const layer of stack.layers.slice(0, end + 1)) {
420 if (layer.state === "merged") continue;
421 - const headSha = layer.number === ref.number ? input.expectedHeadSha : layer.headSha;
421 + const headSha =
422 + layer.number !== ref.number
423 + ? layer.headSha
424 + : layer.headSha !== undefined &&
425 + PullRequestService.isHeadSha(layer.headSha, input.expectedHeadSha)
426 + ? layer.headSha
427 + : input.expectedHeadSha;
428 if (headSha === undefined)
429 return yield* new PullRequestForgeError({
430 detail: `The host did not report PR #${layer.number}'s head, so the stack cannot be pinned. Try again.`,
apps/server/src/pullRequest/PullRequestService.test.ts
+11 -6
@@ -1550,13 +1550,13 @@ it.effect.each([false, true])(
1550
1551 it.effect("refuses a merge whose head moved past expectedHeadSha and pins the host merge", () =>
1552 Effect.gen(function* () {
1553 + const head = "0a1b2c3d4e5f60718293a4b5c6d7e8f901234567";
1554 const pinned: Array<string | undefined> = [];
1555 const service = yield* makeService({
1556 projects: [project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" })],
1557 providers: [
1558 fakePullRequestProvider(SourceControlProviderKind.make("github"), {
1558 - getChangeRequest: () =>
1559 - Effect.succeed({ ...hostedChangeRequest("Body"), headSha: "new-head" }),
1559 + getChangeRequest: () => Effect.succeed({ ...hostedChangeRequest("Body"), headSha: head }),
1560 getChangeRequestSummary: () => Effect.succeed(changeRequest(1, "2026-09-03T00:00:00Z")),
1561 runAction: (input) => Effect.sync(() => void pinned.push(input.expectedHeadSha)),
1562 }),
@@ -1564,11 +1564,16 @@ it.effect("refuses a merge whose head moved past expectedHeadSha and pins the ho
1564 });
1565 const reference = { projectId: "p1" as ProjectId, repository: "acme/web", number: 1 };
1566 const refused = yield* Effect.flip(
1567 - service.runAction({ ...reference, action: "merge", expectedHeadSha: "reviewed-head" }),
1567 + service.runAction({ ...reference, action: "merge", expectedHeadSha: "0a1b2c4" }),
1568 + );
1569 + assert.include(refused.message, head);
1570 + const tooShort = yield* Effect.flip(
1571 + service.runAction({ ...reference, action: "merge", expectedHeadSha: "0a1b2c" }),
1572 );
1569 - assert.include(refused.message, "new-head");
1570 - yield* service.runAction({ ...reference, action: "merge", expectedHeadSha: "new-head" });
1571 - assert.deepStrictEqual(pinned, ["new-head"]);
1573 + assert.include(tooShort.message, head);
1574 + yield* service.runAction({ ...reference, action: "merge", expectedHeadSha: head });
1575 + yield* service.runAction({ ...reference, action: "merge", expectedHeadSha: "0A1B2C3D4" });
1576 + assert.deepStrictEqual(pinned, [head, head]);
1577 }),
1578 );
1579
apps/server/src/pullRequest/PullRequestService.ts
+21 -11
@@ -753,6 +753,12 @@ function httpRemoteHost(remoteUrl: string): string | null {
753 }
754 }
755
756 +/** Whether `expected` names `head`: the full SHA, or a hex prefix of at least 7 characters. */
757 +export const isHeadSha = (head: string, expected: string) => {
758 + const wanted = expected.toLowerCase();
759 + return /^[0-9a-f]{7,}$/.test(wanted) ? head.toLowerCase().startsWith(wanted) : head === expected;
760 +};
761 +
762 // Capture before the provider read so a slow response keeps its original freshness through caches.
763 const observeRead = Effect.fnUntraced(function* <A, E, R>(read: Effect.Effect<A, E, R>) {
764 const observedAt = yield* Clock.currentTimeMillis;
@@ -2285,9 +2291,10 @@ export const make = Effect.gen(function* () {
2291 )
2292 : Effect.succeed(false);
2293 // Hosts that cannot pin a merge to a commit still refuse a head that already moved.
2288 - const headPinned =
2289 - input.expectedHeadSha === undefined
2290 - ? Effect.void
2294 + const expected = input.expectedHeadSha;
2295 + const headPinned: Effect.Effect<string | undefined, PullRequestError> =
2296 + expected === undefined
2297 + ? Effect.undefined
2298 : project.api
2299 .getChangeRequest({
2300 cwd: project.project.workspaceRoot,
@@ -2298,19 +2305,24 @@ export const make = Effect.gen(function* () {
2305 .pipe(
2306 Effect.mapError(toPullRequestError("runAction")),
2307 Effect.flatMap((current) =>
2301 - current.headSha === input.expectedHeadSha
2302 - ? Effect.void
2308 + typeof current.headSha === "string" && isHeadSha(current.headSha, expected)
2309 + ? Effect.succeed(current.headSha)
2310 : Effect.fail(
2311 new PullRequestOperationError({
2312 operation: "runAction",
2306 - detail: `The head is now ${current.headSha ?? "unknown"}, not ${input.expectedHeadSha}. Review the new commits first.`,
2313 + detail: `The head is now ${current.headSha ?? "unknown"}, not ${expected}. Review the new commits first.`,
2314 }),
2315 ),
2316 ),
2317 );
2318 return headPinned.pipe(
2312 - Effect.andThen(mergeSettings),
2313 - Effect.flatMap((removeAgentCreditsOnMerge) =>
2319 + Effect.flatMap((expectedHeadSha) =>
2320 + Effect.map(mergeSettings, (removeAgentCreditsOnMerge) => ({
2321 + expectedHeadSha,
2322 + removeAgentCreditsOnMerge,
2323 + })),
2324 + ),
2325 + Effect.flatMap(({ expectedHeadSha, removeAgentCreditsOnMerge }) =>
2326 project.api
2327 .runAction({
2328 cwd: project.project.workspaceRoot,
@@ -2323,9 +2335,7 @@ export const make = Effect.gen(function* () {
2335 ...(input.expectedStackHeads === undefined
2336 ? {}
2337 : { expectedStackHeads: input.expectedStackHeads }),
2326 - ...(input.expectedHeadSha === undefined
2327 - ? {}
2328 - : { expectedHeadSha: input.expectedHeadSha }),
2338 + ...(expectedHeadSha === undefined ? {} : { expectedHeadSha }),
2339 ...(input.mergeMethod === undefined ? {} : { mergeMethod: input.mergeMethod }),
2340 ...(input.updateMethod === undefined
2341 ? {}