From 615c7a598cc3219c4c06368303ea7b69681477ec Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Tue, 17 Nov 2026 17:52:02 +0100 Subject: [PATCH 1/6] test(client-runtime): issue links on custom GitHub Enterprise hostnames resolve to their project Co-authored-by: Claude Opus 5.5 --- .../client-runtime/src/issueLinks.test.ts | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/client-runtime/src/issueLinks.test.ts b/packages/client-runtime/src/issueLinks.test.ts index 004b526d99cfd..b9cf1e9d9b2e5 100644 --- a/packages/client-runtime/src/issueLinks.test.ts +++ b/packages/client-runtime/src/issueLinks.test.ts @@ -35,28 +35,28 @@ describe("resolveIssueLinkTarget", () => { expect(target?.ref).toMatchObject({ tracker: "github", host: "github.com", ...expected }); }); - it("prefers the project bound to the link's own port over one on the bare hostname", () => { - const enterprise = (id: string, host: string) => - ({ - id: ProjectId.make(id), - environmentId: EnvironmentId.make("env"), - repositoryIdentity: { - canonicalKey: `${host}/acme/web`, - provider: SourceControlProviderKind.make("github"), - displayName: "acme/web", - owner: "acme", - name: "web", - }, - }) as never; - const target = resolveIssueLinkTarget({ - url: "https://github.example.com:8443/acme/web/issues/7", - projects: [ - enterprise("bare", "github.example.com"), - enterprise("ported", "github.example.com:8443"), - ], - }); - expect(target?.ref.projectId).toBe("ported"); - }); + it.each(["github.example.com", "code.acme.test"])( + "prefers the project bound to an issue link's own port on %s", + (host) => { + const enterprise = (id: string, host: string) => + ({ + id: ProjectId.make(id), + environmentId: EnvironmentId.make("env"), + repositoryIdentity: { + canonicalKey: `${host}/acme/web`, + provider: SourceControlProviderKind.make("github"), + displayName: "acme/web", + owner: "acme", + name: "web", + }, + }) as never; + const target = resolveIssueLinkTarget({ + url: `https://${host}:8443/acme/web/issues/7`, + projects: [enterprise("bare", host), enterprise("ported", `${host}:8443`)], + }); + expect(target?.ref.projectId).toBe("ported"); + }, + ); it.each([ "https://github.com.evil.example/acme/web/issues/7", From 2b0f4d200bdefe6e30c3ca832147c238a8dd7a9b Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Tue, 17 Nov 2026 17:56:00 +0100 Subject: [PATCH 2/6] fix(client-runtime): issue links on custom GitHub Enterprise hostnames are recognized A GitHub or Forgejo server can run on any hostname, so the issue link resolver now asks a host's tracker to read a link when a project in the environment is bound to that host, the same way commit links already do. Co-authored-by: Claude Opus 5.5 --- packages/client-runtime/src/issueLinks.ts | 46 ++++++++++++------- .../src/shared/definition.ts | 20 +++++--- .../src/shared/definition.ts | 4 +- .../src/shared/definition.ts | 5 +- 4 files changed, 50 insertions(+), 25 deletions(-) diff --git a/packages/client-runtime/src/issueLinks.ts b/packages/client-runtime/src/issueLinks.ts index 528ea16f12d35..42a8c3cf24eac 100644 --- a/packages/client-runtime/src/issueLinks.ts +++ b/packages/client-runtime/src/issueLinks.ts @@ -1,4 +1,8 @@ -import type { IssueRef } from "@t3tools/contracts"; +import { + IssueTrackerKind, + type IssueRef, + type SourceControlProviderKind, +} from "@t3tools/contracts"; import { sourceControlClients } from "./sourceControlClients.ts"; import type { EnvironmentProject } from "./state/shell.ts"; @@ -7,7 +11,7 @@ type LinkProject = Pick(input: { readonly projects: ReadonlyArray; readonly preferredProjectId?: string | undefined; }): { readonly project: Project; readonly ref: IssueRef } | null { - const parsed = sourceControlClients.parseIssueUrl(input.url); - if (parsed === null) return null; - const { definition, link } = parsed; - // A link names its server's port; a binding does only when its remote or web URL did. - const authority = linkAuthority(input.url); - const onHost = input.projects.flatMap((project) => { + const bindings = input.projects.flatMap((project) => { const binding = projectIssueBinding(project); - return binding === null || - binding.tracker !== definition.kind || - (binding.host !== link.host && binding.host !== authority) - ? [] - : [{ project, binding }]; + return binding === null ? [] : [{ project, binding }]; }); + // A link names its server's port; a binding does only when its remote or web URL did. + const url = linkHost(input.url); + if (url === null) return null; + const { hostname, authority } = url; + // A self-hosted server can have any hostname, so a host a project is bound to names its tracker. + const parsed = + sourceControlClients.parseIssueUrl(input.url) ?? + bindings + .filter(({ binding }) => binding.host === hostname || binding.host === authority) + .map(({ binding }) => sourceControlClients.parseIssueUrl(input.url, binding.tracker)) + .find((candidate) => candidate !== null); + if (parsed == null) return null; + const { definition, link } = parsed; + const onHost = bindings.filter( + ({ binding }) => + binding.tracker === definition.kind && + (binding.host === link.host || binding.host === authority), + ); const onAuthority = onHost.filter((candidate) => candidate.binding.host === authority); const bound = onAuthority.length > 0 ? onAuthority : onHost; const preferFirst = (candidates: typeof bound) => @@ -67,7 +81,7 @@ export function resolveIssueLinkTarget(input: { project: lender.project, ref: { projectId: lender.project.id, - tracker: lender.binding.tracker as IssueRef["tracker"], + tracker: IssueTrackerKind.make(lender.binding.tracker), host: lender.binding.host, scope: own === undefined ? link.scope : lender.binding.scope, key: link.key, diff --git a/packages/source-control-core/src/shared/definition.ts b/packages/source-control-core/src/shared/definition.ts index d8e22b811fc96..1a4025e8e5027 100644 --- a/packages/source-control-core/src/shared/definition.ts +++ b/packages/source-control-core/src/shared/definition.ts @@ -274,8 +274,11 @@ export interface SourceControlDefinition { readonly parseCommitUrl?: (url: URL, known: boolean) => CommitLink | null; /** Null when the URL is not one of this host's change requests. */ readonly parseChangeRequestUrl: (url: URL) => ParsedChangeRequestUrl | null; - /** Null when the URL is not one of this host's issues. Absent for a host with none. */ - readonly parseIssueUrl?: (url: URL) => IssueLink | null; + /** + * Null when the URL is not one of this host's issues. Absent for a host with none. `known` is + * set when the caller already knows this host serves the URL's repository. + */ + readonly parseIssueUrl?: (url: URL, known: boolean) => IssueLink | null; /** * The repository URL when `url` is a page inside one of this host's repositories. `known` is set * when the caller already knows this host serves the URL's repository. Off a known host, return @@ -670,9 +673,13 @@ export interface SourceControlDefinitionRegistry { readonly findByPublicDomain: (hostname: string) => SourceControlDefinition | undefined; /** The first host, in registry order, that reads `url` as one of its change requests. */ readonly parseChangeRequestUrl: (url: string) => ParsedChangeRequest | null; - /** The first host, in registry order, that reads `url` as one of its issues. */ + /** + * The first host, in registry order, that reads `url` as one of its issues; with `kind`, only + * that host, which the caller knows serves the URL. + */ readonly parseIssueUrl: ( url: string, + kind?: SourceControlProviderKind, ) => { readonly definition: SourceControlDefinition; readonly link: IssueLink } | null; readonly parseCommitUrl: (url: string, kind?: SourceControlProviderKind) => ParsedCommit | null; readonly findByChangeRequestUrl: (url: string) => SourceControlDefinition | undefined; @@ -792,11 +799,12 @@ export function makeSourceControlDefinitionRegistry( ); }, parseChangeRequestUrl, - parseIssueUrl: (value) => { + parseIssueUrl: (value, kind) => { const url = httpUrl(value); if (url === null) return null; - for (const definition of claimOrder) { - const link = definition.parseIssueUrl?.(url) ?? null; + const preferred = kind === undefined ? undefined : byKind.get(kind); + for (const definition of kind === undefined ? claimOrder : preferred ? [preferred] : []) { + const link = definition.parseIssueUrl?.(url, preferred !== undefined) ?? null; if (link !== null) return { definition, link }; } return null; diff --git a/packages/source-control-forgejo/src/shared/definition.ts b/packages/source-control-forgejo/src/shared/definition.ts index 73bd2caa8ae8f..f3ae8cc9aef1a 100644 --- a/packages/source-control-forgejo/src/shared/definition.ts +++ b/packages/source-control-forgejo/src/shared/definition.ts @@ -100,7 +100,9 @@ export const definition = defineSourceControl({ return link === null ? null : { ...link, authority: url.host.toLowerCase() }; }, // `/issues/` is too generic a path to believe from a host not named after Forgejo or Gitea. - parseIssueUrl: (url) => (isForgejoHost(url.hostname) ? parseIssuePath(url, ISSUE_PATH) : null), + // A known project's host can be any self-hosted name. + parseIssueUrl: (url, known) => + known || isForgejoHost(url.hostname) ? parseIssuePath(url, ISSUE_PATH) : null, changeRequestUrlFromReferenceAutolink: () => null, commitUrl: (input) => buildCommitUrl(input, "commit"), parseCommitUrl: (url) => parseCommitPath(url, COMMIT_PATH), diff --git a/packages/source-control-github/src/shared/definition.ts b/packages/source-control-github/src/shared/definition.ts index dbc8ac9f80e20..5439d279a36b1 100644 --- a/packages/source-control-github/src/shared/definition.ts +++ b/packages/source-control-github/src/shared/definition.ts @@ -101,8 +101,9 @@ export const definition = defineSourceControl({ parseCommitUrl: (url, known) => known || isGitHubHost(url.hostname) ? parseCommitPath(url, COMMIT_PATH) : null, parseChangeRequestUrl: (url) => parseChangeRequestPath(url, CHANGE_REQUEST_PATH), - // `/issues/` is too generic a path to believe from a host that is not GitHub's. - parseIssueUrl: (url) => (isGitHubHost(url.hostname) ? parseIssuePath(url, ISSUE_PATH) : null), + // `/issues/` is too generic a path to believe from a host not known to be GitHub's. + parseIssueUrl: (url, known) => + known || isGitHubHost(url.hostname) ? parseIssuePath(url, ISSUE_PATH) : null, repositoryUrlFromPage: (url) => isGitHubHost(url.hostname) ? repositoryUrlFromPagePath(url, REPOSITORY_PAGE_PATH) : null, // GitHub writes every bare reference through `/issues/`, including pull requests. From 68caba8dbd00c3a1dfe0c1a967cbb041b2191f9e Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Tue, 17 Nov 2026 18:06:40 +0100 Subject: [PATCH 3/6] fix: resolve custom-host issue links through authority bindings Use exact-authority project bindings before hinted issue parsing and apply binding-aware resolution to the issue service used by MCP tools. Co-authored-by: GPT 6.1 Sol --- apps/server/src/issue/IssueService.test.ts | 53 +++++++++++++++++++ apps/server/src/issue/IssueService.ts | 23 ++++++-- .../client-runtime/src/issueLinks.test.ts | 36 +++++++++++++ packages/client-runtime/src/issueLinks.ts | 8 ++- 4 files changed, 114 insertions(+), 6 deletions(-) diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index f42a1aea6f563..72e54aa271b6c 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -284,6 +284,59 @@ describe("IssueService", () => { }), ); + it.effect("resolves custom-host issue URLs using the binding on the exact authority", () => + Effect.gen(function* () { + const forgejo = IssueTrackerKind.make("forgejo"); + const bare = project({ id: "bare", repository: "acme/web", host: "code.acme.test" }); + const ported = project({ + id: "ported", + repository: "acme/web", + host: "code.acme.test:8443", + provider: "forgejo", + }); + for (const projects of [ + [bare, ported], + [ported, bare], + ]) { + const service = yield* makeService({ + projects, + trackers: [fakeTracker(), fakeTracker({ kind: forgejo })], + }); + expect(yield* service.resolveUrl("https://code.acme.test/acme/web/issues/7")).toEqual({ + projectId: "bare", + tracker: "github", + host: "code.acme.test", + scope: "acme/web", + key: "7", + writable: true, + }); + expect(yield* service.resolveUrl("https://code.acme.test:8443/acme/web/issues/7")).toEqual({ + projectId: "ported", + tracker: "forgejo", + host: "code.acme.test:8443", + scope: "acme/web", + key: "7", + writable: true, + }); + expect(yield* service.resolveUrl("https://code.acme.test/other/repo/issues/8")).toEqual({ + projectId: "bare", + tracker: "github", + host: "code.acme.test", + scope: "other/repo", + key: "8", + writable: false, + }); + const unbound = yield* service + .resolveUrl("https://unbound.test/acme/web/issues/7") + .pipe(Effect.result); + expect(unbound).toMatchObject({ + _tag: "Failure", + failure: { _tag: "IssueOperationError", reason: "not-found" }, + }); + } + }), + ); + it.effect("sends writes as interactive requests and reads as background ones", () => Effect.gen(function* () { const interactive: Array = []; diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index 2832ab04d15bb..4161c3a7abc12 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -642,7 +642,25 @@ const make = Effect.gen(function* () { const resolveUrl: IssueService["Service"]["resolveUrl"] = Effect.fn("IssueService.resolveUrl")( function* (url, preferredProjectId) { - const gitHost = sourceControlDefinitions.parseIssueUrl(url); + const urlHost = parseUrl(url); + const authority = urlHost?.host.toLowerCase(); + const { supported } = + urlHost === null + ? { supported: [] } + : yield* listProjects({ host: urlHost.hostname.toLowerCase(), authority }); + const onUrlAuthority = supported.filter((project) => project.host === authority); + const urlBindings = onUrlAuthority.length > 0 ? onUrlAuthority : supported; + const gitHost = + sourceControlDefinitions.parseIssueUrl(url) ?? + urlBindings + .map((project) => { + const definition = sourceControlDefinitions.find(project.tracker); + return definition === undefined + ? null + : sourceControlDefinitions.parseIssueUrl(url, definition.kind); + }) + .find((candidate) => candidate !== null) ?? + null; const standalone = gitHost === null ? findStandaloneIssueUrl(registry.standalone, url) : null; const parsed = gitHost === null @@ -656,9 +674,6 @@ const make = Effect.gen(function* () { }); } const { tracker, link } = parsed; - // A link names its server's port; a binding does only when its remote or web URL did. - const authority = new URL(url).host.toLowerCase(); - const { supported } = yield* listProjects({ host: link.host, authority }); const onHost = supported.filter((project) => project.tracker === tracker); const onAuthority = onHost.filter((project) => project.host === authority); const onTracker = onAuthority.length > 0 ? onAuthority : onHost; diff --git a/packages/client-runtime/src/issueLinks.test.ts b/packages/client-runtime/src/issueLinks.test.ts index b9cf1e9d9b2e5..da0549bc9056e 100644 --- a/packages/client-runtime/src/issueLinks.test.ts +++ b/packages/client-runtime/src/issueLinks.test.ts @@ -58,6 +58,42 @@ describe("resolveIssueLinkTarget", () => { }, ); + it("uses the exact authority's tracker regardless of project order", () => { + const binding = (id: string, host: string, provider: string) => ({ + id: ProjectId.make(id), + environmentId: EnvironmentId.make("env"), + repositoryIdentity: { + canonicalKey: `${host}/acme/web`, + locator: { + source: "git-remote" as const, + remoteName: "origin", + remoteUrl: `https://${host}/acme/web.git`, + }, + provider: SourceControlProviderKind.make(provider), + displayName: "acme/web", + }, + }); + const bare = binding("bare", "code.acme.test", "github"); + const ported = binding("ported", "code.acme.test:8443", "forgejo"); + for (const projects of [ + [bare, ported], + [ported, bare], + ]) { + expect( + resolveIssueLinkTarget({ + url: "https://code.acme.test:8443/acme/web/issues/7", + projects, + })?.ref, + ).toEqual({ + projectId: "ported", + tracker: "forgejo", + host: "code.acme.test:8443", + scope: "acme/web", + key: "7", + }); + } + }); + it.each([ "https://github.com.evil.example/acme/web/issues/7", "https://github.com/acme/web/pull/7", diff --git a/packages/client-runtime/src/issueLinks.ts b/packages/client-runtime/src/issueLinks.ts index 42a8c3cf24eac..3267a0f675543 100644 --- a/packages/client-runtime/src/issueLinks.ts +++ b/packages/client-runtime/src/issueLinks.ts @@ -55,11 +55,15 @@ export function resolveIssueLinkTarget(input: { const url = linkHost(input.url); if (url === null) return null; const { hostname, authority } = url; + const onUrlHost = bindings.filter( + ({ binding }) => binding.host === hostname || binding.host === authority, + ); + const onUrlAuthority = onUrlHost.filter(({ binding }) => binding.host === authority); + const urlBindings = onUrlAuthority.length > 0 ? onUrlAuthority : onUrlHost; // A self-hosted server can have any hostname, so a host a project is bound to names its tracker. const parsed = sourceControlClients.parseIssueUrl(input.url) ?? - bindings - .filter(({ binding }) => binding.host === hostname || binding.host === authority) + urlBindings .map(({ binding }) => sourceControlClients.parseIssueUrl(input.url, binding.tracker)) .find((candidate) => candidate !== null); if (parsed == null) return null; From 63d95f8a86ae78e84c59e89dd006ece816c25196 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Tue, 17 Nov 2026 18:17:55 +0100 Subject: [PATCH 4/6] fix: prefer bound issue trackers over hostname heuristics Co-authored-by: GPT 6.1 Sol --- apps/server/src/issue/IssueService.test.ts | 94 ++++++++++--------- apps/server/src/issue/IssueService.ts | 4 +- .../client-runtime/src/issueLinks.test.ts | 69 +++++++------- packages/client-runtime/src/issueLinks.ts | 3 +- 4 files changed, 86 insertions(+), 84 deletions(-) diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index 72e54aa271b6c..ed2706e7cce60 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -286,53 +286,55 @@ describe("IssueService", () => { it.effect("resolves custom-host issue URLs using the binding on the exact authority", () => Effect.gen(function* () { - const forgejo = IssueTrackerKind.make("forgejo"); - const bare = project({ id: "bare", repository: "acme/web", host: "code.acme.test" }); - const ported = project({ - id: "ported", - repository: "acme/web", - host: "code.acme.test:8443", - provider: "forgejo", - }); - for (const projects of [ - [bare, ported], - [ported, bare], - ]) { - const service = yield* makeService({ - projects, - trackers: [fakeTracker(), fakeTracker({ kind: forgejo })], - }); - expect(yield* service.resolveUrl("https://code.acme.test/acme/web/issues/7")).toEqual({ - projectId: "bare", - tracker: "github", - host: "code.acme.test", - scope: "acme/web", - key: "7", - writable: true, - }); - expect(yield* service.resolveUrl("https://code.acme.test:8443/acme/web/issues/7")).toEqual({ - projectId: "ported", - tracker: "forgejo", - host: "code.acme.test:8443", - scope: "acme/web", - key: "7", - writable: true, - }); - expect(yield* service.resolveUrl("https://code.acme.test/other/repo/issues/8")).toEqual({ - projectId: "bare", - tracker: "github", - host: "code.acme.test", - scope: "other/repo", - key: "8", - writable: false, - }); - const unbound = yield* service - .resolveUrl("https://unbound.test/acme/web/issues/7") - .pipe(Effect.result); - expect(unbound).toMatchObject({ - _tag: "Failure", - failure: { _tag: "IssueOperationError", reason: "not-found" }, + for (const host of ["code.acme.test", "github.acme.test"]) { + const forgejo = IssueTrackerKind.make("forgejo"); + const bare = project({ id: "bare", repository: "acme/web", host }); + const ported = project({ + id: "ported", + repository: "acme/web", + host: `${host}:8443`, + provider: "forgejo", }); + for (const projects of [ + [bare, ported], + [ported, bare], + ]) { + const service = yield* makeService({ + projects, + trackers: [fakeTracker(), fakeTracker({ kind: forgejo })], + }); + expect(yield* service.resolveUrl(`https://${host}/acme/web/issues/7`)).toEqual({ + projectId: "bare", + tracker: "github", + host, + scope: "acme/web", + key: "7", + writable: true, + }); + expect(yield* service.resolveUrl(`https://${host}:8443/acme/web/issues/7`)).toEqual({ + projectId: "ported", + tracker: "forgejo", + host: `${host}:8443`, + scope: "acme/web", + key: "7", + writable: true, + }); + expect(yield* service.resolveUrl(`https://${host}/other/repo/issues/8`)).toEqual({ + projectId: "bare", + tracker: "github", + host, + scope: "other/repo", + key: "8", + writable: false, + }); + const unbound = yield* service + .resolveUrl("https://unbound.test/acme/web/issues/7") + .pipe(Effect.result); + expect(unbound).toMatchObject({ + _tag: "Failure", + failure: { _tag: "IssueOperationError", reason: "not-found" }, + }); + } } }), ); diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index 4161c3a7abc12..b91ff5178b8a3 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -651,7 +651,6 @@ const make = Effect.gen(function* () { const onUrlAuthority = supported.filter((project) => project.host === authority); const urlBindings = onUrlAuthority.length > 0 ? onUrlAuthority : supported; const gitHost = - sourceControlDefinitions.parseIssueUrl(url) ?? urlBindings .map((project) => { const definition = sourceControlDefinitions.find(project.tracker); @@ -659,8 +658,7 @@ const make = Effect.gen(function* () { ? null : sourceControlDefinitions.parseIssueUrl(url, definition.kind); }) - .find((candidate) => candidate !== null) ?? - null; + .find((candidate) => candidate !== null) ?? sourceControlDefinitions.parseIssueUrl(url); const standalone = gitHost === null ? findStandaloneIssueUrl(registry.standalone, url) : null; const parsed = gitHost === null diff --git a/packages/client-runtime/src/issueLinks.test.ts b/packages/client-runtime/src/issueLinks.test.ts index da0549bc9056e..02a8ccee834b4 100644 --- a/packages/client-runtime/src/issueLinks.test.ts +++ b/packages/client-runtime/src/issueLinks.test.ts @@ -58,41 +58,44 @@ describe("resolveIssueLinkTarget", () => { }, ); - it("uses the exact authority's tracker regardless of project order", () => { - const binding = (id: string, host: string, provider: string) => ({ - id: ProjectId.make(id), - environmentId: EnvironmentId.make("env"), - repositoryIdentity: { - canonicalKey: `${host}/acme/web`, - locator: { - source: "git-remote" as const, - remoteName: "origin", - remoteUrl: `https://${host}/acme/web.git`, + it.each(["code.acme.test", "github.acme.test"])( + "uses the exact authority's tracker on %s regardless of project order", + (host) => { + const binding = (id: string, host: string, provider: string) => ({ + id: ProjectId.make(id), + environmentId: EnvironmentId.make("env"), + repositoryIdentity: { + canonicalKey: `${host}/acme/web`, + locator: { + source: "git-remote" as const, + remoteName: "origin", + remoteUrl: `https://${host}/acme/web.git`, + }, + provider: SourceControlProviderKind.make(provider), + displayName: "acme/web", }, - provider: SourceControlProviderKind.make(provider), - displayName: "acme/web", - }, - }); - const bare = binding("bare", "code.acme.test", "github"); - const ported = binding("ported", "code.acme.test:8443", "forgejo"); - for (const projects of [ - [bare, ported], - [ported, bare], - ]) { - expect( - resolveIssueLinkTarget({ - url: "https://code.acme.test:8443/acme/web/issues/7", - projects, - })?.ref, - ).toEqual({ - projectId: "ported", - tracker: "forgejo", - host: "code.acme.test:8443", - scope: "acme/web", - key: "7", }); - } - }); + const bare = binding("bare", host, "github"); + const ported = binding("ported", `${host}:8443`, "forgejo"); + for (const projects of [ + [bare, ported], + [ported, bare], + ]) { + expect( + resolveIssueLinkTarget({ + url: `https://${host}:8443/acme/web/issues/7`, + projects, + })?.ref, + ).toEqual({ + projectId: "ported", + tracker: "forgejo", + host: `${host}:8443`, + scope: "acme/web", + key: "7", + }); + } + }, + ); it.each([ "https://github.com.evil.example/acme/web/issues/7", diff --git a/packages/client-runtime/src/issueLinks.ts b/packages/client-runtime/src/issueLinks.ts index 3267a0f675543..44995d40bb53f 100644 --- a/packages/client-runtime/src/issueLinks.ts +++ b/packages/client-runtime/src/issueLinks.ts @@ -62,10 +62,9 @@ export function resolveIssueLinkTarget(input: { const urlBindings = onUrlAuthority.length > 0 ? onUrlAuthority : onUrlHost; // A self-hosted server can have any hostname, so a host a project is bound to names its tracker. const parsed = - sourceControlClients.parseIssueUrl(input.url) ?? urlBindings .map(({ binding }) => sourceControlClients.parseIssueUrl(input.url, binding.tracker)) - .find((candidate) => candidate !== null); + .find((candidate) => candidate !== null) ?? sourceControlClients.parseIssueUrl(input.url); if (parsed == null) return null; const { definition, link } = parsed; const onHost = bindings.filter( From aefd6a02f5df54c246236dce62e70cd6a498b1e7 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Tue, 17 Nov 2026 18:20:53 +0100 Subject: [PATCH 5/6] chore: credit the models that worked on this change Co-authored-by: Grok 4.7 From 4419749197b069176f1425418ec88836374c01d2 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 17 Nov 2026 17:32:36 +0000 Subject: [PATCH 6/6] refactor(client-runtime): check the issue link URL before collecting bindings Co-Authored-By: Claude Opus 5.5 --- packages/client-runtime/src/issueLinks.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/client-runtime/src/issueLinks.ts b/packages/client-runtime/src/issueLinks.ts index 44995d40bb53f..07f3cffd5b3aa 100644 --- a/packages/client-runtime/src/issueLinks.ts +++ b/packages/client-runtime/src/issueLinks.ts @@ -47,14 +47,14 @@ export function resolveIssueLinkTarget(input: { readonly projects: ReadonlyArray; readonly preferredProjectId?: string | undefined; }): { readonly project: Project; readonly ref: IssueRef } | null { - const bindings = input.projects.flatMap((project) => { - const binding = projectIssueBinding(project); - return binding === null ? [] : [{ project, binding }]; - }); // A link names its server's port; a binding does only when its remote or web URL did. const url = linkHost(input.url); if (url === null) return null; const { hostname, authority } = url; + const bindings = input.projects.flatMap((project) => { + const binding = projectIssueBinding(project); + return binding === null ? [] : [{ project, binding }]; + }); const onUrlHost = bindings.filter( ({ binding }) => binding.host === hostname || binding.host === authority, ); @@ -65,7 +65,7 @@ export function resolveIssueLinkTarget(input: { urlBindings .map(({ binding }) => sourceControlClients.parseIssueUrl(input.url, binding.tracker)) .find((candidate) => candidate !== null) ?? sourceControlClients.parseIssueUrl(input.url); - if (parsed == null) return null; + if (parsed === null) return null; const { definition, link } = parsed; const onHost = bindings.filter( ({ binding }) =>