Skip to content

Commit 0cc3732

Browse files
committed
fix: tighten URL-only PR identity handling
1 parent a8b5ee0 commit 0cc3732

4 files changed

Lines changed: 67 additions & 16 deletions

File tree

‎apps/server/src/pullRequest/PullRequestService.test.ts‎

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3118,10 +3118,6 @@ it.effect("shares linked summaries and reuses them for display without asking th
31183118
let calls = 0;
31193119
let failing = false;
31203120
const reference = { projectId: "p1" as ProjectId, repository: "acme/web", number: 1 };
3121-
const linkedReference = {
3122-
...reference,
3123-
url: "https://github.com/acme/web/pull/1",
3124-
};
31253121
const service = yield* makeService({
31263122
projects: [project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" })],
31273123
providers: [
@@ -3151,8 +3147,8 @@ it.effect("shares linked summaries and reuses them for display without asking th
31513147

31523148
yield* Effect.all(
31533149
[
3154-
service.summary(linkedReference, { recoverTransientFailure: false }),
3155-
service.summary(linkedReference, { recoverTransientFailure: false }),
3150+
service.summary(reference, { recoverTransientFailure: false }),
3151+
service.summary(reference, { recoverTransientFailure: false }),
31563152
],
31573153
{ concurrency: "unbounded" },
31583154
);
@@ -3161,7 +3157,7 @@ it.effect("shares linked summaries and reuses them for display without asking th
31613157
yield* TestClock.adjust("61 seconds");
31623158
failing = true;
31633159
const strict = yield* Effect.flip(
3164-
service.summary(linkedReference, { recoverTransientFailure: false }),
3160+
service.summary(reference, { recoverTransientFailure: false }),
31653161
);
31663162
assert.strictEqual(strict._tag, "PullRequestOperationError");
31673163

@@ -3216,6 +3212,43 @@ it.effect("reads a linked pull request URL from a non-Git project", () =>
32163212
}),
32173213
);
32183214

3215+
it.effect("keeps URL-only summaries on different hosts separate", () =>
3216+
Effect.gen(function* () {
3217+
let githubCalls = 0;
3218+
let bitbucketCalls = 0;
3219+
const service = yield* makeService({
3220+
projects: [project({ id: "parent", title: "work", workspaceRoot: "/work" })],
3221+
providers: [
3222+
fakeProvider("github", {
3223+
getChangeRequestSummary: () => {
3224+
githubCalls += 1;
3225+
return Effect.succeed(changeRequest(7, "2026-09-03T00:00:00Z"));
3226+
},
3227+
}),
3228+
fakeProvider("bitbucket", {
3229+
getChangeRequestSummary: () => {
3230+
bitbucketCalls += 1;
3231+
return Effect.succeed(changeRequest(7, "2026-09-03T00:00:00Z"));
3232+
},
3233+
}),
3234+
],
3235+
});
3236+
const reference = {
3237+
projectId: "parent" as ProjectId,
3238+
repository: "acme/web",
3239+
number: 7,
3240+
};
3241+
3242+
yield* service.summary({ ...reference, url: "https://github.com/acme/web/pull/7" });
3243+
yield* service.summary({
3244+
...reference,
3245+
url: "https://bitbucket.org/acme/web/pull-requests/7",
3246+
});
3247+
3248+
assert.deepStrictEqual([githubCalls, bitbucketCalls], [1, 1]);
3249+
}),
3250+
);
3251+
32193252
it.effect("does not use providers that cannot resolve URL-only summary hosts", () =>
32203253
Effect.gen(function* () {
32213254
for (const testCase of [
@@ -3234,6 +3267,11 @@ it.effect("does not use providers that cannot resolve URL-only summary hosts", (
32343267
repository: "pingdotgg/t3code",
32353268
url: "https://bitbucket.acme.test/pingdotgg/t3code/pull-requests/9435",
32363269
},
3270+
{
3271+
provider: "github" as const,
3272+
repository: "pingdotgg/t3code",
3273+
url: "https://github.acme.test/pingdotgg/t3code/pull/9435",
3274+
},
32373275
]) {
32383276
const service = yield* makeService({
32393277
projects: [project({ id: "parent", title: "work", workspaceRoot: "/work" })],

‎apps/server/src/pullRequest/PullRequestService.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,8 +2227,8 @@ export const make = Effect.gen(function* () {
22272227
},
22282228
);
22292229
const summary: PullRequestService["Service"]["summary"] = (input, options) => {
2230-
const key = refCacheKey(input);
2231-
const cached = Cache.get(summaryCache, summaryCacheKey(input));
2230+
const key = summaryCacheKey(input);
2231+
const cached = Cache.get(summaryCache, key);
22322232
if (options?.recoverTransientFailure !== false) {
22332233
return lastGoodSummary.serveHeld(key, cached, "reuse");
22342234
}

‎apps/web/src/lib/openPullRequestLink.test.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ describe("parseChangeRequestUrl", () => {
217217
provider: "github",
218218
});
219219
expect(parseChangeRequestUrl("https://github.acme.test:8443/platform/api/pull/7")).toEqual({
220-
host: "github.acme.test:8443",
220+
host: "github.acme.test",
221221
repository: "platform/api",
222222
number: 7,
223223
provider: "github",
@@ -364,6 +364,7 @@ describe("resolveThreadPullRequestLink", () => {
364364
"https://gitlab.com/pingdotgg/t3code/-/merge_requests/9435",
365365
"https://dev.azure.com/pingdotgg/t3code/_git/t3code/pullrequest/9435",
366366
"https://bitbucket.acme.test/pingdotgg/t3code/pull-requests/9435",
367+
"https://github.acme.test/pingdotgg/t3code/pull/9435",
367368
])("does not offer URL-only linking when the provider cannot resolve the host", (url) => {
368369
expect(resolveThreadPullRequestLink([parentProject], parentProjectId, url, true)).toBeNull();
369370
});
@@ -373,6 +374,18 @@ describe("findProjectForChangeRequest", () => {
373374
const project = (identity: Record<string, unknown>) =>
374375
({ id: "p1", repositoryIdentity: identity }) as never;
375376

377+
it("matches a custom-port link by its canonical hostname", () => {
378+
const candidate = project({
379+
canonicalKey: "github.acme.test/platform/api",
380+
provider: "github",
381+
displayName: "platform/api",
382+
});
383+
const link = parseChangeRequestUrl("https://github.acme.test:8443/platform/api/pull/7");
384+
385+
if (link === null) throw new Error("expected a GitHub Enterprise pull request");
386+
expect(findProjectForChangeRequest([candidate], link)).toBe(candidate);
387+
});
388+
376389
it("matches a nested GitLab group by the whole path below the host", () => {
377390
// The server identifies a repository by `displayName`, which keeps every group segment; the
378391
// two-segment owner/name form would look for `t3tools/t3code` and find nothing.

‎packages/shared/src/sourceControl.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export interface ParsedChangeRequestLink extends ChangeRequestLink {
2929
/** Providers whose linked-thread summary can be read without repository checkout context. */
3030
export function canReadChangeRequestSummaryWithoutCheckout(link: ParsedChangeRequestLink): boolean {
3131
return (
32-
link.provider === "github" || (link.provider === "bitbucket" && link.host === "bitbucket.org")
32+
(link.provider === "github" && link.host === "github.com") ||
33+
(link.provider === "bitbucket" && link.host === "bitbucket.org")
3334
);
3435
}
3536

@@ -59,22 +60,21 @@ export function parseChangeRequestUrl(targetUrl: string): ParsedChangeRequestLin
5960
return null;
6061
}
6162
if (url.protocol !== "https:" && url.protocol !== "http:") return null;
62-
const hostname = url.hostname.toLowerCase();
63-
const host = url.host.toLowerCase();
63+
const host = url.hostname.toLowerCase();
6464

65-
if (isHostOf(hostname, "github.com", "github")) {
65+
if (isHostOf(host, "github.com", "github")) {
6666
return claim(host, "github", /^\/([^/]+\/[^/]+)\/pull\/(\d+)(?:\/|$)/u.exec(url.pathname));
6767
}
6868
const gitlab = /^\/([^/]+(?:\/[^/]+)+)\/-\/merge_requests\/(\d+)(?:\/|$)/u.exec(url.pathname);
6969
if (gitlab) return claim(host, "gitlab", gitlab);
70-
if (isHostOf(hostname, "bitbucket.org", "bitbucket")) {
70+
if (isHostOf(host, "bitbucket.org", "bitbucket")) {
7171
return claim(
7272
host,
7373
"bitbucket",
7474
/^\/([^/]+\/[^/]+)\/pull-requests\/(\d+)(?:\/|$)/u.exec(url.pathname),
7575
);
7676
}
77-
if (isHostOf(hostname, "dev.azure.com") || hostname.endsWith(".visualstudio.com")) {
77+
if (isHostOf(host, "dev.azure.com") || host.endsWith(".visualstudio.com")) {
7878
return claim(
7979
host,
8080
"azure-devops",

0 commit comments

Comments
 (0)