From 0c681933189aff4b9edc7fb2161ed07667dbcbb4 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Tue, 17 Nov 2026 08:33:11 +0100 Subject: [PATCH 1/9] test(server): an issue URL on an unconfigured port resolves to no project Co-authored-by: Claude Opus 5.5 --- apps/server/src/issue/IssueService.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index fd6f7b2f0a0c1..a1577d6e1bffa 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -258,6 +258,21 @@ describe("IssueService", () => { host: "gitea.test", }); + const defaultPortOnly = yield* makeService({ + projects: [ + project({ id: "plain", repository: "acme/web", provider: "forgejo", host: "gitea.test" }), + ], + trackers: [fakeTracker({ kind: IssueTrackerKind.make("forgejo") })], + }); + expect( + yield* defaultPortOnly + .resolveUrl("https://gitea.test:8443/acme/web/issues/3") + .pipe(Effect.result), + ).toMatchObject({ + _tag: "Failure", + failure: { _tag: "IssueUnavailableError", reason: "tracker-unsupported" }, + }); + // Another host is not reachable through this project's credentials at all. const elsewhere = yield* Effect.flip(service.detail({ ...own, host: "ghe.example.test" })); expect(elsewhere).toMatchObject({ From 5308c1613a53b934ca0ed471f1ebb628b7d45803 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Tue, 17 Nov 2026 08:33:51 +0100 Subject: [PATCH 2/9] fix(server): issue URLs with an unconfigured port no longer resolve to the default-port server Co-authored-by: Claude Opus 5.5 --- apps/server/src/issue/IssueService.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index a53aeb698ce89..93e6fa29fdd8b 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -218,8 +218,6 @@ const make = Effect.gen(function* () { const listProjects = (filter: { readonly projectId?: IssueListInput["projectId"]; readonly host?: string | undefined; - /** The link's `host:port`, for a host whose binding keeps its port. */ - readonly authority?: string | undefined; }) => (filter.projectId === undefined ? projects.listShells() @@ -251,8 +249,7 @@ const make = Effect.gen(function* () { { tracker: IssueTrackerKind; projectCount: number } >(); for (const candidate of bound.flat()) { - if (host !== undefined && candidate.host !== host && candidate.host !== filter.authority) - continue; + if (host !== undefined && candidate.host !== host) continue; const api = registry.get(candidate.tracker); if (api === null) { const counted = unimplemented.get(candidate.host); @@ -630,14 +627,11 @@ const make = Effect.gen(function* () { }); } const { definition, 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( + // Servers on different ports are different servers: a link's port must match its binding's. + const { supported } = yield* listProjects({ host: new URL(url).host }); + const onTracker = supported.filter( (project) => project.tracker === IssueTrackerKind.make(definition.kind), ); - const onAuthority = onHost.filter((project) => project.host === authority); - const onTracker = onAuthority.length > 0 ? onAuthority : onHost; const preferFirst = (projects: ReadonlyArray) => projects.find((project) => project.project.id === preferredProjectId) ?? projects[0]; const own = preferFirst( From 0d9bbd4213bc752b5b4e891aa30a5e2f8cf8ade7 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Tue, 17 Nov 2026 08:45:43 +0100 Subject: [PATCH 3/9] fix(issues): match URL ports against repository identity Co-authored-by: GPT 6.1 Sol --- apps/server/src/issue/IssueService.test.ts | 59 ++++++++++++++++++- apps/server/src/issue/IssueService.ts | 12 ++-- .../src/shared/definition.ts | 29 ++++++++- 3 files changed, 93 insertions(+), 7 deletions(-) diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index a1577d6e1bffa..67331bbe02fbb 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -57,6 +57,8 @@ function project(input: { readonly repository?: string; readonly provider?: string; readonly host?: string; + readonly remoteUrl?: string; + readonly webUrl?: string; }): OrchestrationProjectShell { const host = input.host ?? "github.com"; return { @@ -66,14 +68,17 @@ function project(input: { ...(input.repository ? { repositoryIdentity: { - canonicalKey: normalizeGitRemoteUrl(`https://${host}/${input.repository}.git`), + canonicalKey: normalizeGitRemoteUrl( + input.remoteUrl ?? `https://${host}/${input.repository}.git`, + ), locator: { source: "git-remote" as const, remoteName: "origin", - remoteUrl: `https://${host}/${input.repository}.git`, + remoteUrl: input.remoteUrl ?? `https://${host}/${input.repository}.git`, }, provider: SourceControlProviderKind.make(input.provider ?? "github"), displayName: input.repository, + ...(input.webUrl ? { webUrl: input.webUrl } : {}), }, } : {}), @@ -273,6 +278,56 @@ describe("IssueService", () => { failure: { _tag: "IssueUnavailableError", reason: "tracker-unsupported" }, }); + for (const { provider, host, path } of [ + { provider: "forgejo", host: "gitea.test", path: "issues" }, + { provider: "gitlab", host: "gitlab.test", path: "-/issues" }, + ]) { + for (const transport of ["ssh", "https", "web"] as const) { + const configured = yield* makeService({ + projects: [ + project({ + id: "configured", + repository: "acme/web", + provider, + host, + remoteUrl: + transport === "https" + ? `https://${host}:8443/acme/web.git` + : `git@${host}:acme/web.git`, + ...(transport === "web" ? { webUrl: `https://${host}:8443/acme/web` } : {}), + }), + ], + trackers: [fakeTracker({ kind: IssueTrackerKind.make(provider) })], + }); + expect( + yield* configured.resolveUrl(`https://${host}:8443/acme/web/${path}/3`), + ).toMatchObject({ + projectId: "configured", + key: "3", + writable: true, + host: transport === "ssh" ? host : `${host}:8443`, + }); + if (transport !== "ssh") { + expect( + yield* configured + .resolveUrl(`https://${host}:9443/acme/web/${path}/3`) + .pipe(Effect.result), + ).toMatchObject({ + _tag: "Failure", + failure: { reason: "tracker-unsupported" }, + }); + expect( + yield* configured + .resolveUrl(`https://${host}/acme/web/${path}/3`) + .pipe(Effect.result), + ).toMatchObject({ + _tag: "Failure", + failure: { reason: "tracker-unsupported" }, + }); + } + } + } + // Another host is not reachable through this project's credentials at all. const elsewhere = yield* Effect.flip(service.detail({ ...own, host: "ghe.example.test" })); expect(elsewhere).toMatchObject({ diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index 93e6fa29fdd8b..56d8d8292f0d8 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -31,6 +31,7 @@ import { type OrchestrationProjectShell, type ProjectId, } from "@t3tools/contracts"; +import { isIssueOnProjectHost } from "@t3tools/source-control-core/shared/definition"; import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit"; import { IssueTrackerError, @@ -64,6 +65,7 @@ export function trackerDetail(error: IssueTrackerError): string { /** One project's resolved tracker: which driver, where it is served from, and its container. */ interface ProjectTrackerBinding { + readonly repositoryIdentity?: OrchestrationProjectShell["repositoryIdentity"]; readonly tracker: IssueTrackerKind; readonly host: string; readonly scope: string; @@ -86,7 +88,8 @@ function resolveGitHostBinding(project: OrchestrationProjectShell): ProjectTrack if (!identity || kind === undefined || kind === "unknown" || scope === null) return null; return { tracker: IssueTrackerKind.make(kind), - host: sourceControlDefinitions.changeRequestHost(identity, kind), + host: sourceControlDefinitions.issueHost(identity, kind), + repositoryIdentity: identity, scope, }; } @@ -627,10 +630,11 @@ const make = Effect.gen(function* () { }); } const { definition, link } = parsed; - // Servers on different ports are different servers: a link's port must match its binding's. - const { supported } = yield* listProjects({ host: new URL(url).host }); + const { supported } = yield* listProjects({}); const onTracker = supported.filter( - (project) => project.tracker === IssueTrackerKind.make(definition.kind), + (project) => + project.tracker === IssueTrackerKind.make(definition.kind) && + isIssueOnProjectHost(project.host, project.repositoryIdentity, link), ); const preferFirst = (projects: ReadonlyArray) => projects.find((project) => project.project.id === preferredProjectId) ?? projects[0]; diff --git a/packages/source-control-core/src/shared/definition.ts b/packages/source-control-core/src/shared/definition.ts index d8e22b811fc96..afcd2d52a508a 100644 --- a/packages/source-control-core/src/shared/definition.ts +++ b/packages/source-control-core/src/shared/definition.ts @@ -38,6 +38,7 @@ export interface ChangeRequestLink { */ export interface IssueLink { readonly host: string; + readonly authority?: string; readonly scope: string; readonly key: string; } @@ -454,7 +455,12 @@ export function parseIssuePath(url: URL, route: RegExp): IssueLink | null { const scope = match?.[1]; const number = Number(match?.[2]); return scope && Number.isSafeInteger(number) && number > 0 - ? { host: url.hostname.toLowerCase(), scope: scope.toLowerCase(), key: String(number) } + ? { + host: url.hostname.toLowerCase(), + ...(url.port ? { authority: url.host.toLowerCase() } : {}), + scope: scope.toLowerCase(), + key: String(number), + } : null; } @@ -497,6 +503,22 @@ export function defineSourceControl string | null; /** Where the project's issues live: the host's `issueScope`, else its repository. */ readonly issueScope: (identity: RepositorySelectorIdentity | null | undefined) => string | null; + readonly issueHost: (identity: ChangeRequestHostIdentity, kind: string) => string; readonly changeRequestHost: ( identity: ChangeRequestHostIdentity, kind: Kind, @@ -882,6 +905,10 @@ export function makeSourceControlDefinitionRegistry( ? repositorySelector(identity) : issueScope(identity); }, + issueHost: (identity, kind) => + issueWebUrl(identity)?.host.toLowerCase() ?? + byKind.get(kind)?.changeRequestHost?.(identity) ?? + projectChangeRequestHost(identity, kind), changeRequestHost: (identity, kind) => (kind === undefined ? undefined : byKind.get(kind)?.changeRequestHost?.(identity)) ?? projectChangeRequestHost(identity, kind), From 2057664444e7e42ad5a5c0f1ee3e02325208c06e Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Tue, 17 Nov 2026 08:53:25 +0100 Subject: [PATCH 4/9] fix(client): match issue links against configured web authority Co-authored-by: GPT 6.1 Sol --- packages/client-runtime/src/issueLinks.test.ts | 2 ++ packages/client-runtime/src/issueLinks.ts | 17 +++-------------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/packages/client-runtime/src/issueLinks.test.ts b/packages/client-runtime/src/issueLinks.test.ts index 004b526d99cfd..3d592396c2a79 100644 --- a/packages/client-runtime/src/issueLinks.test.ts +++ b/packages/client-runtime/src/issueLinks.test.ts @@ -10,6 +10,7 @@ const project = (id: string, repository: string) => repositoryIdentity: { canonicalKey: `github.com/${repository}`, provider: SourceControlProviderKind.make("github"), + webUrl: `https://github.com/${repository}`, displayName: repository, owner: repository.split("/")[0], name: repository.split("/")[1], @@ -59,6 +60,7 @@ describe("resolveIssueLinkTarget", () => { }); it.each([ + "https://github.com:8443/acme/web/issues/7", "https://github.com.evil.example/acme/web/issues/7", "https://github.com/acme/web/pull/7", ])("leaves %s an ordinary link", (url) => { diff --git a/packages/client-runtime/src/issueLinks.ts b/packages/client-runtime/src/issueLinks.ts index 528ea16f12d35..9d85c5663d671 100644 --- a/packages/client-runtime/src/issueLinks.ts +++ b/packages/client-runtime/src/issueLinks.ts @@ -1,4 +1,5 @@ import type { IssueRef } from "@t3tools/contracts"; +import { isIssueOnProjectHost } from "@t3tools/source-control-core/shared/definition"; import { sourceControlClients } from "./sourceControlClients.ts"; import type { EnvironmentProject } from "./state/shell.ts"; @@ -22,14 +23,6 @@ function projectIssueBinding(project: LinkProject): { }; } -function linkAuthority(url: string): string | null { - try { - return new URL(url).host.toLowerCase(); - } catch { - return null; - } -} - /** * The reference an issue link resolves to, and the project it is read through: the project whose * tracker binding is that host and scope, else any project on the same tracker and host lending @@ -45,18 +38,14 @@ export function resolveIssueLinkTarget(input: { 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 bound = input.projects.flatMap((project) => { const binding = projectIssueBinding(project); return binding === null || binding.tracker !== definition.kind || - (binding.host !== link.host && binding.host !== authority) + !isIssueOnProjectHost(binding.host, project.repositoryIdentity, link) ? [] : [{ project, binding }]; }); - const onAuthority = onHost.filter((candidate) => candidate.binding.host === authority); - const bound = onAuthority.length > 0 ? onAuthority : onHost; const preferFirst = (candidates: typeof bound) => candidates.find((candidate) => candidate.project.id === input.preferredProjectId) ?? candidates[0]; From fa94e7c934d068ba0f80fbe3702672c80c62c219 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Tue, 17 Nov 2026 08:54:18 +0100 Subject: [PATCH 5/9] fix(server): preserve issue binding hosts across authority matching Co-authored-by: GPT 6.1 Sol --- apps/server/src/issue/IssueService.test.ts | 15 ++++++++++++++- apps/server/src/issue/IssueService.ts | 2 +- .../source-control-core/src/shared/definition.ts | 5 ----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index 67331bbe02fbb..e00e5146bee31 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -305,8 +305,21 @@ describe("IssueService", () => { projectId: "configured", key: "3", writable: true, - host: transport === "ssh" ? host : `${host}:8443`, + host: provider === "forgejo" && transport !== "ssh" ? `${host}:8443` : host, }); + const bindingHost = provider === "forgejo" && transport !== "ssh" ? `${host}:8443` : host; + expect(yield* configured.projectScope("configured" as ProjectId)).toMatchObject({ + host: bindingHost, + }); + expect( + yield* configured.detail({ + projectId: "configured" as ProjectId, + tracker: IssueTrackerKind.make(provider), + host: bindingHost, + scope: "acme/web", + key: "3", + }), + ).toMatchObject({ writable: true }); if (transport !== "ssh") { expect( yield* configured diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index 56d8d8292f0d8..826be0a0a5022 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -88,7 +88,7 @@ function resolveGitHostBinding(project: OrchestrationProjectShell): ProjectTrack if (!identity || kind === undefined || kind === "unknown" || scope === null) return null; return { tracker: IssueTrackerKind.make(kind), - host: sourceControlDefinitions.issueHost(identity, kind), + host: sourceControlDefinitions.changeRequestHost(identity, kind), repositoryIdentity: identity, scope, }; diff --git a/packages/source-control-core/src/shared/definition.ts b/packages/source-control-core/src/shared/definition.ts index afcd2d52a508a..32b7bc320f0ff 100644 --- a/packages/source-control-core/src/shared/definition.ts +++ b/packages/source-control-core/src/shared/definition.ts @@ -718,7 +718,6 @@ export interface SourceControlDefinitionRegistry { ) => string | null; /** Where the project's issues live: the host's `issueScope`, else its repository. */ readonly issueScope: (identity: RepositorySelectorIdentity | null | undefined) => string | null; - readonly issueHost: (identity: ChangeRequestHostIdentity, kind: string) => string; readonly changeRequestHost: ( identity: ChangeRequestHostIdentity, kind: Kind, @@ -905,10 +904,6 @@ export function makeSourceControlDefinitionRegistry( ? repositorySelector(identity) : issueScope(identity); }, - issueHost: (identity, kind) => - issueWebUrl(identity)?.host.toLowerCase() ?? - byKind.get(kind)?.changeRequestHost?.(identity) ?? - projectChangeRequestHost(identity, kind), changeRequestHost: (identity, kind) => (kind === undefined ? undefined : byKind.get(kind)?.changeRequestHost?.(identity)) ?? projectChangeRequestHost(identity, kind), From d1bb526db0d4544a74f89f2b7ec4e6d62b6936d6 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Tue, 17 Nov 2026 08:56:46 +0100 Subject: [PATCH 6/9] fix(issues): prefer configured authorities over SSH host fallbacks Co-authored-by: GPT 6.1 Sol --- apps/server/src/issue/IssueService.test.ts | 10 ++++ apps/server/src/issue/IssueService.ts | 9 ++-- .../client-runtime/src/issueLinks.test.ts | 49 ++++++++++--------- packages/client-runtime/src/issueLinks.ts | 29 ++++++----- .../src/shared/definition.ts | 28 +++++++---- 5 files changed, 76 insertions(+), 49 deletions(-) diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index e00e5146bee31..7dbc7d3849c17 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -242,6 +242,13 @@ describe("IssueService", () => { // A link's port picks the server: the project bound with it, not a default-port namesake. const ported = yield* makeService({ projects: [ + project({ + id: "ssh", + repository: "acme/web", + provider: "forgejo", + host: "gitea.test", + remoteUrl: "git@gitea.test:acme/web.git", + }), project({ id: "plain", repository: "acme/web", provider: "forgejo", host: "gitea.test" }), project({ id: "ported", @@ -258,6 +265,9 @@ describe("IssueService", () => { key: "3", writable: true, }); + expect( + yield* ported.resolveUrl("https://gitea.test:8443/acme/web/issues/3", "ssh" as ProjectId), + ).toMatchObject({ projectId: "ported", host: "gitea.test:8443", writable: true }); expect(yield* ported.resolveUrl("https://gitea.test/acme/web/issues/3")).toMatchObject({ projectId: "plain", host: "gitea.test", diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index 826be0a0a5022..8e6d5ce3d4e49 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -31,7 +31,7 @@ import { type OrchestrationProjectShell, type ProjectId, } from "@t3tools/contracts"; -import { isIssueOnProjectHost } from "@t3tools/source-control-core/shared/definition"; +import { projectsOnIssueHost } from "@t3tools/source-control-core/shared/definition"; import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit"; import { IssueTrackerError, @@ -631,10 +631,9 @@ const make = Effect.gen(function* () { } const { definition, link } = parsed; const { supported } = yield* listProjects({}); - const onTracker = supported.filter( - (project) => - project.tracker === IssueTrackerKind.make(definition.kind) && - isIssueOnProjectHost(project.host, project.repositoryIdentity, link), + const onTracker = projectsOnIssueHost( + supported.filter((project) => project.tracker === IssueTrackerKind.make(definition.kind)), + link, ); const preferFirst = (projects: ReadonlyArray) => projects.find((project) => project.project.id === preferredProjectId) ?? projects[0]; diff --git a/packages/client-runtime/src/issueLinks.test.ts b/packages/client-runtime/src/issueLinks.test.ts index 3d592396c2a79..a2c07e429a8d1 100644 --- a/packages/client-runtime/src/issueLinks.test.ts +++ b/packages/client-runtime/src/issueLinks.test.ts @@ -36,28 +36,33 @@ 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", "github.example.com:8443"])( + "prefers the configured authority with binding host %s over a preferred SSH project", + (portedHost) => { + const enterprise = (id: string, host: string, remoteUrl = `git@${host}:acme/web.git`) => + ({ + id: ProjectId.make(id), + environmentId: EnvironmentId.make("env"), + repositoryIdentity: { + canonicalKey: `${host}/acme/web`, + locator: { source: "git-remote" as const, remoteName: "origin", remoteUrl }, + 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", + preferredProjectId: "bare", + projects: [ + enterprise("bare", "github.example.com"), + enterprise("ported", portedHost, "https://github.example.com:8443/acme/web.git"), + ], + }); + expect(target?.ref).toMatchObject({ projectId: "ported", host: portedHost }); + }, + ); it.each([ "https://github.com:8443/acme/web/issues/7", diff --git a/packages/client-runtime/src/issueLinks.ts b/packages/client-runtime/src/issueLinks.ts index 9d85c5663d671..108dd96fcf572 100644 --- a/packages/client-runtime/src/issueLinks.ts +++ b/packages/client-runtime/src/issueLinks.ts @@ -1,5 +1,5 @@ import type { IssueRef } from "@t3tools/contracts"; -import { isIssueOnProjectHost } from "@t3tools/source-control-core/shared/definition"; +import { projectsOnIssueHost } from "@t3tools/source-control-core/shared/definition"; import { sourceControlClients } from "./sourceControlClients.ts"; import type { EnvironmentProject } from "./state/shell.ts"; @@ -11,12 +11,14 @@ function projectIssueBinding(project: LinkProject): { readonly tracker: string; readonly host: string; readonly scope: string; + readonly repositoryIdentity: NonNullable; } | null { const identity = project.repositoryIdentity; const scope = sourceControlClients.issueScope(identity); const kind = identity?.provider; if (!identity || kind === undefined || kind === "unknown" || scope === null) return null; return { + repositoryIdentity: identity, tracker: kind, host: sourceControlClients.changeRequestHost(identity, kind), scope: scope.toLowerCase(), @@ -38,27 +40,28 @@ export function resolveIssueLinkTarget(input: { const parsed = sourceControlClients.parseIssueUrl(input.url); if (parsed === null) return null; const { definition, link } = parsed; - const bound = input.projects.flatMap((project) => { - const binding = projectIssueBinding(project); - return binding === null || - binding.tracker !== definition.kind || - !isIssueOnProjectHost(binding.host, project.repositoryIdentity, link) - ? [] - : [{ project, binding }]; - }); + const bound = projectsOnIssueHost( + input.projects.flatMap((project) => { + const binding = projectIssueBinding(project); + return binding === null || binding.tracker !== definition.kind + ? [] + : [{ project, ...binding }]; + }), + link, + ); const preferFirst = (candidates: typeof bound) => candidates.find((candidate) => candidate.project.id === input.preferredProjectId) ?? candidates[0]; - const own = preferFirst(bound.filter((candidate) => candidate.binding.scope === link.scope)); + const own = preferFirst(bound.filter((candidate) => candidate.scope === link.scope)); const lender = own ?? preferFirst(bound); if (lender === undefined) return null; return { project: lender.project, ref: { projectId: lender.project.id, - tracker: lender.binding.tracker as IssueRef["tracker"], - host: lender.binding.host, - scope: own === undefined ? link.scope : lender.binding.scope, + tracker: lender.tracker as IssueRef["tracker"], + host: lender.host, + scope: own === undefined ? link.scope : lender.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 32b7bc320f0ff..359ed684dbb95 100644 --- a/packages/source-control-core/src/shared/definition.ts +++ b/packages/source-control-core/src/shared/definition.ts @@ -508,15 +508,25 @@ function issueWebUrl(identity: ChangeRequestHostIdentity): URL | null { return httpUrl(identity?.webUrl ?? "") ?? httpUrl(identity?.locator?.remoteUrl ?? ""); } -export function isIssueOnProjectHost( - projectHost: string, - identity: ChangeRequestHostIdentity, - link: IssueLink, -): boolean { - const web = issueWebUrl(identity); - return web === null - ? projectHost === link.host || projectHost === link.authority - : web.host.toLowerCase() === (link.authority ?? link.host); +/** A configured web authority wins over an SSH-only host, before repository or project preference. */ +export function projectsOnIssueHost< + Project extends { + readonly host: string; + readonly repositoryIdentity?: ChangeRequestHostIdentity; + }, +>(projects: ReadonlyArray, link: IssueLink): ReadonlyArray { + const matches = projects.flatMap((project) => { + const web = issueWebUrl(project.repositoryIdentity); + if (web !== null) { + return web.host.toLowerCase() === (link.authority ?? link.host) + ? [{ project, authority: true }] + : []; + } + if (project.host === link.authority) return [{ project, authority: true }]; + return project.host === link.host ? [{ project, authority: false }] : []; + }); + const configured = matches.filter((match) => match.authority); + return (configured.length > 0 ? configured : matches).map((match) => match.project); } export function isChangeRequestAuthorityOfProject( From 7f89b343c290e2b86081fbbfd28fcfbf1401d746 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Tue, 17 Nov 2026 09:10:21 +0100 Subject: [PATCH 7/9] fix(issues): preserve SSH candidates for default-port links Co-authored-by: GPT 6.1 Sol --- apps/server/src/issue/IssueService.test.ts | 19 ++++++++++++++++++- .../src/shared/definition.ts | 4 ++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index 7dbc7d3849c17..c31d1c8a43586 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -239,6 +239,23 @@ describe("IssueService", () => { }); expect(writes).toEqual(["acme/web#1"]); + for (const repository of ["acme/api", "acme/web"]) { + const mixed = yield* makeService({ + projects: [ + project({ id: "https", repository }), + project({ + id: "ssh", + repository: "acme/web", + remoteUrl: "git@github.com:acme/web.git", + }), + ], + trackers: [fakeTracker()], + }); + expect( + yield* mixed.resolveUrl("https://github.com/acme/web/issues/7", "ssh" as ProjectId), + ).toMatchObject({ projectId: "ssh", scope: "acme/web", key: "7", writable: true }); + } + // A link's port picks the server: the project bound with it, not a default-port namesake. const ported = yield* makeService({ projects: [ @@ -269,7 +286,7 @@ describe("IssueService", () => { yield* ported.resolveUrl("https://gitea.test:8443/acme/web/issues/3", "ssh" as ProjectId), ).toMatchObject({ projectId: "ported", host: "gitea.test:8443", writable: true }); expect(yield* ported.resolveUrl("https://gitea.test/acme/web/issues/3")).toMatchObject({ - projectId: "plain", + projectId: "ssh", host: "gitea.test", }); diff --git a/packages/source-control-core/src/shared/definition.ts b/packages/source-control-core/src/shared/definition.ts index 359ed684dbb95..bfaf7ec02dba8 100644 --- a/packages/source-control-core/src/shared/definition.ts +++ b/packages/source-control-core/src/shared/definition.ts @@ -508,7 +508,7 @@ function issueWebUrl(identity: ChangeRequestHostIdentity): URL | null { return httpUrl(identity?.webUrl ?? "") ?? httpUrl(identity?.locator?.remoteUrl ?? ""); } -/** A configured web authority wins over an SSH-only host, before repository or project preference. */ +/** For links with a port, a configured web authority wins over an SSH-only host. */ export function projectsOnIssueHost< Project extends { readonly host: string; @@ -525,7 +525,7 @@ export function projectsOnIssueHost< if (project.host === link.authority) return [{ project, authority: true }]; return project.host === link.host ? [{ project, authority: false }] : []; }); - const configured = matches.filter((match) => match.authority); + const configured = link.authority === undefined ? [] : matches.filter((match) => match.authority); return (configured.length > 0 ? configured : matches).map((match) => match.project); } From 75f2424d57a960f4537506ae938650766ea61e53 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Tue, 17 Nov 2026 09:17:19 +0100 Subject: [PATCH 8/9] chore: credit the models that worked on this change Co-authored-by: Grok 4.7 From b9d53b11151fc1a3aff511a69e9130e685bf9c64 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 17 Nov 2026 08:27:55 +0000 Subject: [PATCH 9/9] test(server): trim issue URL authority cases to the matching behavior Co-Authored-By: Claude Opus 5.5 --- apps/server/src/issue/IssueService.test.ts | 62 ++++++---------------- 1 file changed, 17 insertions(+), 45 deletions(-) diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index c31d1c8a43586..ad6d43644dbb4 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -239,22 +239,17 @@ describe("IssueService", () => { }); expect(writes).toEqual(["acme/web#1"]); - for (const repository of ["acme/api", "acme/web"]) { - const mixed = yield* makeService({ - projects: [ - project({ id: "https", repository }), - project({ - id: "ssh", - repository: "acme/web", - remoteUrl: "git@github.com:acme/web.git", - }), - ], - trackers: [fakeTracker()], - }); - expect( - yield* mixed.resolveUrl("https://github.com/acme/web/issues/7", "ssh" as ProjectId), - ).toMatchObject({ projectId: "ssh", scope: "acme/web", key: "7", writable: true }); - } + // A portless link keeps SSH and HTTPS remotes on the same host as candidates. + const mixed = yield* makeService({ + projects: [ + project({ id: "https", repository: "acme/web" }), + project({ id: "ssh", repository: "acme/web", remoteUrl: "git@github.com:acme/web.git" }), + ], + trackers: [fakeTracker()], + }); + expect( + yield* mixed.resolveUrl("https://github.com/acme/web/issues/7", "ssh" as ProjectId), + ).toMatchObject({ projectId: "ssh", writable: true }); // A link's port picks the server: the project bound with it, not a default-port namesake. const ported = yield* makeService({ @@ -305,6 +300,7 @@ describe("IssueService", () => { failure: { _tag: "IssueUnavailableError", reason: "tracker-unsupported" }, }); + // A configured web or HTTPS authority admits only its own port; SSH names no port. for (const { provider, host, path } of [ { provider: "forgejo", host: "gitea.test", path: "issues" }, { provider: "gitlab", host: "gitlab.test", path: "-/issues" }, @@ -330,40 +326,16 @@ describe("IssueService", () => { yield* configured.resolveUrl(`https://${host}:8443/acme/web/${path}/3`), ).toMatchObject({ projectId: "configured", - key: "3", - writable: true, host: provider === "forgejo" && transport !== "ssh" ? `${host}:8443` : host, + writable: true, }); - const bindingHost = provider === "forgejo" && transport !== "ssh" ? `${host}:8443` : host; - expect(yield* configured.projectScope("configured" as ProjectId)).toMatchObject({ - host: bindingHost, - }); - expect( - yield* configured.detail({ - projectId: "configured" as ProjectId, - tracker: IssueTrackerKind.make(provider), - host: bindingHost, - scope: "acme/web", - key: "3", - }), - ).toMatchObject({ writable: true }); - if (transport !== "ssh") { - expect( - yield* configured - .resolveUrl(`https://${host}:9443/acme/web/${path}/3`) - .pipe(Effect.result), - ).toMatchObject({ - _tag: "Failure", - failure: { reason: "tracker-unsupported" }, - }); + if (transport === "ssh") continue; + for (const elsewhere of [`${host}:9443`, host]) { expect( yield* configured - .resolveUrl(`https://${host}/acme/web/${path}/3`) + .resolveUrl(`https://${elsewhere}/acme/web/${path}/3`) .pipe(Effect.result), - ).toMatchObject({ - _tag: "Failure", - failure: { reason: "tracker-unsupported" }, - }); + ).toMatchObject({ _tag: "Failure", failure: { reason: "tracker-unsupported" } }); } } }