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, 18:15 UTC
fix: canonicalize git.cafe pull request links (#22634)
maria committed
Oct 25, 2026 at 01:51 UTC
eabcfa2feaba3be169aeec2da0207b8ed694d79d
11 files changed
+174
-28
apps/server/src/mcp/toolkits/pullRequests/handlers.test.ts
+33
@@ -353,6 +353,39 @@ describe("pull request toolkit handlers", () => {
353
}),
354
);
355
356
+ it.effect("canonicalizes GitCafe links independently of the thread's project host", () =>
357
+ Effect.gen(function* () {
358
+ for (const host of ["git.cafe", "staging.git.cafe"]) {
359
+ for (const project of [makeProject(), makeProject(null)]) {
360
+ for (const target of [
361
+ { host, repository: "PingDotGG/T3Code", number: 21353 },
362
+ { url: `https://${host}/PingDotGG/T3Code/pull/21353` },
363
+ { url: `https://${host}/PingDotGG/T3Code/pulls/21353` },
364
+ ]) {
365
+ const harness = yield* makeHarness({ project });
366
+ const result = yield* harness.call("link_pull_request", target);
367
+ const url = `https://${host}/pingdotgg/t3code/pulls/21353`;
368
+ expect(result).toMatchObject({
369
+ host,
370
+ repository: "pingdotgg/t3code",
371
+ number: 21353,
372
+ url,
373
+ });
374
+ expect(yield* Ref.get(harness.commands)).toMatchObject([
375
+ {
376
+ type: "thread.pull-request.link",
377
+ host,
378
+ repository: "pingdotgg/t3code",
379
+ number: 21353,
380
+ url,
381
+ },
382
+ ]);
383
+ }
384
+ }
385
+ }
386
+ }),
387
+ );
388
+
389
it.effect("builds the URL in the project host's own shape", () =>
390
Effect.gen(function* () {
391
const harness = yield* makeHarness({
apps/server/src/mcp/toolkits/pullRequests/handlers.ts
+10
-3
@@ -6,6 +6,7 @@ import {
6
type ThreadId,
7
type ThreadPullRequestLink,
8
} from "@t3tools/contracts";
9
+import { canonicalizeGitCafePullRequestUrl } from "@t3tools/source-control-definitions/registry";
10
import * as Cause from "effect/Cause";
11
import * as Crypto from "effect/Crypto";
12
import * as Effect from "effect/Effect";
@@ -76,7 +77,10 @@ const resolveTarget = Effect.fn("PullRequestsToolkit.resolveTarget")(function* (
77
if (parsed === undefined) {
78
return yield* new PullRequestUrlInvalidError({});
79
}
79
- return { ...normalizeThreadPullRequestKey(parsed), url: input.url } satisfies ResolvedTarget;
80
+ return {
81
+ ...normalizeThreadPullRequestKey(parsed),
82
+ url: canonicalizeGitCafePullRequestUrl(input.url),
83
+ } satisfies ResolvedTarget;
84
}
85
if (input.repository === undefined || input.number === undefined) {
86
return yield* new PullRequestTargetIncompleteError({});
@@ -89,7 +93,10 @@ const resolveTarget = Effect.fn("PullRequestsToolkit.resolveTarget")(function* (
93
const repository = input.repository.toLowerCase();
94
// Without a URL, a public forge host says what shape its change request URLs take;
95
// any other host is taken to run the project's own forge.
92
- const kind = sourceControlDefinitions.findByPublicHost(host)?.kind ?? projectHost.kind;
96
+ const recognizedKind = sourceControlDefinitions.recognizeRemote(`https://${host}`)?.kind;
97
+ const kind =
98
+ sourceControlDefinitions.findByPublicHost(host)?.kind ??
99
+ (recognizedKind === "gitcafe" ? recognizedKind : projectHost.kind);
100
const url =
101
kind === null
102
? null
@@ -104,7 +111,7 @@ const resolveTarget = Effect.fn("PullRequestsToolkit.resolveTarget")(function* (
111
}
112
return {
113
...normalizeThreadPullRequestKey({ host, repository, number: input.number, url }),
107
- url,
114
+ url: canonicalizeGitCafePullRequestUrl(url),
115
} satisfies ResolvedTarget;
116
});
117
apps/server/src/orchestration-v2/Orchestrator.ts
+6
-5
@@ -10,6 +10,7 @@ import {
10
runRanAfter,
11
usageLimitBlockedRun,
12
} from "@t3tools/shared/orchestrationV2ThreadError";
13
+import { canonicalizeGitCafePullRequestUrl } from "@t3tools/source-control-definitions/registry";
14
import { threadPullRequestsOf } from "../sourceControl/threadPullRequests.ts";
15
import {
16
normalizeThreadPullRequestKey,
@@ -641,7 +642,7 @@ function legacyPullRequestLink(
642
return withPullRequestWatch(
643
{
644
...key,
644
- url: linked.url,
645
+ url: canonicalizeGitCafePullRequestUrl(linked.url),
646
source: "manual",
647
linkedAt: DateTime.formatIso(now),
648
snapshot: null,
@@ -3415,14 +3416,14 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
3416
? {
3417
...existing,
3418
source: command.source,
3418
- url: command.url,
3419
+ url: canonicalizeGitCafePullRequestUrl(command.url),
3420
...(command.repositoryWebUrl !== undefined && {
3421
repositoryWebUrl: command.repositoryWebUrl,
3422
}),
3423
}
3424
: {
3425
...key,
3425
- url: command.url,
3426
+ url: canonicalizeGitCafePullRequestUrl(command.url),
3427
...(command.repositoryWebUrl !== undefined && {
3428
repositoryWebUrl: command.repositoryWebUrl,
3429
}),
@@ -3443,7 +3444,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
3444
? [
3445
{
3446
...branchKey,
3446
- url: branch.url,
3447
+ url: canonicalizeGitCafePullRequestUrl(branch.url),
3448
source: "manual" as const,
3449
linkedAt: DateTime.formatIso(now),
3450
snapshot: null,
@@ -3518,7 +3519,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
3519
...linked.filter((link) => !threadPullRequestKeysEqual(link, key)),
3520
{
3521
...key,
3521
- url: command.link.url,
3522
+ url: canonicalizeGitCafePullRequestUrl(command.link.url),
3523
...((command.link.repositoryWebUrl ?? dismissed?.repositoryWebUrl) !==
3524
undefined && {
3525
repositoryWebUrl:
apps/server/src/orchestration-v2/runtimeLayer.test.ts
+19
@@ -2247,6 +2247,25 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
2247
(yield* orchestrator.getThreadShell(threadId))?.pullRequests?.map((link) => link.number),
2248
[2, 3, 4],
2249
);
2250
+ for (const [index, route] of ["pull", "pulls"].entries()) {
2251
+ yield* orchestrator.dispatch({
2252
+ type: "thread.pull-request.link",
2253
+ commandId: CommandId.make(`gitcafe-pr-link-${index}`),
2254
+ threadId,
2255
+ host: "git.cafe",
2256
+ repository: "pingdotgg/t3code",
2257
+ number: 21353 + index,
2258
+ url: `https://git.cafe/pingdotgg/t3code/${route}/${21353 + index}`,
2259
+ source: "manual",
2260
+ });
2261
+ }
2262
+ assert.isTrue((yield* maintenance.rebuild).valid);
2263
+ assert.deepEqual(
2264
+ (yield* orchestrator.getThreadShell(threadId))?.pullRequests
2265
+ ?.filter((link) => link.host === "git.cafe")
2266
+ .map((link) => link.url),
2267
+ [21353, 21354].map((number) => `https://git.cafe/pingdotgg/t3code/pulls/${number}`),
2268
+ );
2269
}),
2270
);
2271
packages/client-runtime/src/pullRequestLinkInput.test.ts
+27
@@ -15,6 +15,33 @@ const project = {
15
};
16
17
describe("resolveLinkPullRequestInput", () => {
18
+ it.each(["git.cafe", "staging.git.cafe"])("canonicalizes both GitCafe routes on %s", (host) => {
19
+ for (const [repository, route] of [
20
+ ["web", "pull"],
21
+ ["web", "pulls"],
22
+ ["pull", "pull"],
23
+ ["pull", "pulls"],
24
+ ["pulls", "pull"],
25
+ ["pulls", "pulls"],
26
+ ]) {
27
+ const url = `https://${host}/acme/${repository}/${route}/42`;
28
+ expect(
29
+ sourceControlClients.get("gitcafe").parseChangeRequestUrl(new URL(url)),
30
+ ).not.toBeNull();
31
+ expect(parsePullRequestReference(url)).toBe(url);
32
+ expect(
33
+ resolveLinkPullRequestInput({ reference: url, project: null, hasProject: () => true }),
34
+ ).toEqual({
35
+ link: {
36
+ host,
37
+ repository: `acme/${repository}`,
38
+ number: 42,
39
+ url: `https://${host}/acme/${repository}/pulls/42`,
40
+ },
41
+ });
42
+ }
43
+ });
44
+
45
it.each([
46
["https://bitbucket.org/acme/web/pull-requests/42", "bitbucket.org"],
47
["https://github.acme.test/acme/web/pull/42", "github.acme.test"],
packages/client-runtime/src/pullRequestLinkInput.ts
+7
-1
@@ -1,4 +1,5 @@
1
import type { RepositoryIdentity } from "@t3tools/contracts";
2
+import { canonicalizeGitCafePullRequestUrl } from "@t3tools/source-control-definitions/registry";
3
4
import { sourceControlClients, type ChangeRequestTerminology } from "./sourceControlClients.ts";
5
@@ -86,7 +87,12 @@ export function resolveLinkPullRequestInput(input: {
87
return { error: `No project in this environment can read ${url.host}/${url.repository}.` };
88
}
89
return {
89
- link: { host: url.host, repository: url.repository, number: url.number, url: parsed },
90
+ link: {
91
+ host: url.host,
92
+ repository: url.repository,
93
+ number: url.number,
94
+ url: canonicalizeGitCafePullRequestUrl(parsed),
95
+ },
96
};
97
}
98
const number = Number(parsed);
packages/source-control-definitions/src/registry.ts
+2
@@ -6,6 +6,8 @@ import * as GitCafe from "@t3tools/source-control-gitcafe/shared/definition";
6
import * as GitHub from "@t3tools/source-control-github/shared/definition";
7
import * as GitLab from "@t3tools/source-control-gitlab/shared/definition";
8
9
+export { canonicalizePullRequestUrl as canonicalizeGitCafePullRequestUrl } from "@t3tools/source-control-gitcafe/shared/definition";
10
+
11
/**
12
* The server and every client read hosts through this one registry, so they agree on which host
13
* owns a URL or remote. GitHub comes first because a repository that has not reported its host
packages/source-control-gitcafe/src/server/GitCafeSourceControlProvider.test.ts
+8
-6
@@ -242,12 +242,14 @@ describe("GitCafeSourceControlProvider", () => {
242
};
243
return Effect.gen(function* () {
244
const provider = yield* GitCafeSourceControlProvider.make;
245
- yield* provider.checkoutChangeRequest({
246
- cwd: "/repo",
247
- reference: "https://git.cafe/team/project/pulls/7",
248
- ...(context === undefined ? {} : { context }),
249
- });
250
- assert.deepStrictEqual(remotes, [expected]);
245
+ for (const route of ["pull", "pulls"]) {
246
+ yield* provider.checkoutChangeRequest({
247
+ cwd: "/repo",
248
+ reference: `https://git.cafe/team/project/${route}/7`,
249
+ ...(context === undefined ? {} : { context }),
250
+ });
251
+ }
252
+ assert.deepStrictEqual(remotes, [expected, expected]);
253
}).pipe(
254
Effect.provide(
255
Layer.merge(GitCafeApi.layer, NoFiles).pipe(
packages/source-control-gitcafe/src/server/GitCafeSourceControlProvider.ts
+6
-7
@@ -20,6 +20,7 @@ import {
20
import { randomUuidV4 } from "@t3tools/provider-core/server/randomUuid";
21
import * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";
22
import * as SourceControlProvider from "@t3tools/source-control-core/server/SourceControlProvider";
23
+import { parsePullRequestUrl } from "../shared/definition.ts";
24
25
import * as GitCafeApi from "./GitCafeApi.ts";
26
import * as GitCafeCredentials from "./GitCafeCredentials.ts";
@@ -166,8 +167,6 @@ const cloneUrls = (target: Target) => ({
167
const isSshRemote = (remoteUrl: string | undefined) =>
168
remoteUrl !== undefined && (/^ssh:\/\//iu.test(remoteUrl) || /^[^/:]+@[^/:]+:/u.test(remoteUrl));
169
169
-const pullUrlPattern = /^https:\/\/([^/]+)\/([^/]+\/[^/]+)\/pulls\/(\d+)\/?(?:[?#].*)?$/u;
170
-
170
export const make = Effect.gen(function* () {
171
const api = yield* GitCafeApi.GitCafeApi;
172
const host = yield* SourceControlHost.SourceControlHost;
@@ -242,15 +241,15 @@ export const make = Effect.gen(function* () {
241
readonly context?: SourceControlProvider.SourceControlProviderContext;
242
readonly reference: string;
243
}) {
245
- const match = pullUrlPattern.exec(input.reference.trim());
246
- const urlHost = match?.[1] ? GitCafeHosts.gitCafeHost(match[1]) : null;
244
+ const match = parsePullRequestUrl(input.reference.trim());
245
+ const urlHost = match === null ? null : GitCafeHosts.gitCafeHost(match.host);
246
const target: Target =
248
- urlHost && match?.[2]
249
- ? { host: urlHost, repository: match[2] }
247
+ urlHost && match
248
+ ? { host: urlHost, repository: match.repository }
249
: yield* resolveTarget("getChangeRequest", input);
250
const number = match
251
? urlHost
253
- ? match[3]
252
+ ? String(match.number)
253
: undefined
254
: /^#?([1-9]\d*)$/u.exec(input.reference.trim())?.[1];
255
if (number === undefined)
packages/source-control-gitcafe/src/shared/definition.test.ts
+35
-1
@@ -1,11 +1,45 @@
1
import { recognizeRemoteWith } from "@t3tools/source-control-core/shared/definition";
2
import { describe, expect, it } from "vite-plus/test";
3
4
-import { definition } from "./definition.ts";
4
+import { canonicalizePullRequestUrl, definition, parsePullRequestUrl } from "./definition.ts";
5
6
const parse = (url: string) => definition.parseChangeRequestUrl(new URL(url));
7
8
describe("GitCafe change request URLs", () => {
9
+ it.each(["git.cafe", "staging.git.cafe"])("normalizes links for storage on %s", (host) => {
10
+ for (const repository of ["web", "pull", "pulls"]) {
11
+ for (const route of ["pull", "pulls"]) {
12
+ const url = `https://${host}/Acme/${repository}/${route}/42/files?w=1#diff`;
13
+ expect(parsePullRequestUrl(url)).toMatchObject({
14
+ host,
15
+ repository: `acme/${repository}`,
16
+ number: 42,
17
+ });
18
+ expect(definition.isChangeRequestReference(url)).toBe(true);
19
+ expect(canonicalizePullRequestUrl(url)).toBe(`https://${host}/acme/${repository}/pulls/42`);
20
+ }
21
+ }
22
+ });
23
+
24
+ it("preserves other URLs and rejects invalid GitCafe references", () => {
25
+ for (const url of [
26
+ "https://github.com/team/repo/pull/7",
27
+ "https://forge.example/team/repo/pulls/7",
28
+ "https://not.git.cafe/team/repo/pull/7",
29
+ "https://git.cafe.evil.test/team/repo/pull/7",
30
+ "https://git.cafe/tfs/collection/project/_git/repo/pullrequest/7",
31
+ "https://git.cafe/team/repo/pull/0",
32
+ "https://git.cafe/team/repo/pulls/9007199254740992",
33
+ "https://staging.git.cafe/team/repo/pull/7suffix",
34
+ "ftp://git.cafe/team/repo/pull/7",
35
+ "not a url",
36
+ ]) {
37
+ expect(parsePullRequestUrl(url), url).toBeNull();
38
+ expect(definition.isChangeRequestReference(url), url).toBe(false);
39
+ expect(canonicalizePullRequestUrl(url), url).toBe(url);
40
+ }
41
+ });
42
+
43
it("reads its canonical /pull/ path and the older /pulls/ path on its own hosts", () => {
44
for (const path of ["pull", "pulls"]) {
45
expect(parse(`https://git.cafe/PingDotGG/T3Code/${path}/23897`), path).toEqual({
packages/source-control-gitcafe/src/shared/definition.ts
+21
-5
@@ -22,6 +22,12 @@ const GITCAFE_HOSTS = new Set(["git.cafe", "staging.git.cafe"]);
22
/** GitCafe serves pull requests at `/pull/<n>` and redirects the older `/pulls/<n>` there. */
23
const CHANGE_REQUEST_PATH = /^\/([^/]+\/[^/]+)\/pulls?\/(\d+)(?:\/|$)/u;
24
25
+function parseChangeRequestUrl(url: URL) {
26
+ return GITCAFE_HOSTS.has(url.hostname.toLowerCase())
27
+ ? parseChangeRequestPath(url, CHANGE_REQUEST_PATH)
28
+ : null;
29
+}
30
+
31
const KIND = SourceControlProviderKind.make("gitcafe");
32
33
export const settings = makeProviderSettingsSchema({
@@ -61,10 +67,7 @@ export const definition = defineSourceControl({
67
: `https://${host}/${repository}/pulls/${number}`,
68
// `/pull/` and `/pulls/` are GitHub's and Forgejo's shapes too, so only GitCafe's own hosts
69
// claim them.
64
- parseChangeRequestUrl: (url) =>
65
- GITCAFE_HOSTS.has(url.hostname.toLowerCase())
66
- ? parseChangeRequestPath(url, CHANGE_REQUEST_PATH)
67
- : null,
70
+ parseChangeRequestUrl,
71
changeRequestUrlFromReferenceAutolink: () => null,
72
changeRequestActions: new Set([
73
"ready",
@@ -79,7 +82,7 @@ export const definition = defineSourceControl({
82
authorProfileUrl: () => null,
83
reviewSummaryRequired: () => false,
84
checkoutCommandArgument: () => null,
82
- isChangeRequestReference: () => false,
85
+ isChangeRequestReference: (url) => parsePullRequestUrl(url) !== null,
86
checkoutChangeRequestHost: () => null,
87
recognizeRemote: ({ hostname }) =>
88
GITCAFE_HOSTS.has(hostname)
@@ -91,3 +94,16 @@ export const definition = defineSourceControl({
94
isChangeRequestOnProjectHost(projectChangeRequestHost(identity, KIND), identity, link),
95
settings,
96
});
97
+
98
+export function parsePullRequestUrl(value: string) {
99
+ try {
100
+ return parseChangeRequestUrl(new URL(value));
101
+ } catch {
102
+ return null;
103
+ }
104
+}
105
+
106
+export function canonicalizePullRequestUrl(value: string): string {
107
+ const link = parsePullRequestUrl(value);
108
+ return link === null ? value : definition.changeRequestUrl(link);
109
+}