From 3fef9ffc4eda629b5502344fae89d406d13371b8 Mon Sep 17 00:00:00 2001 From: Bil0000 <62337003+Bil0000@users.noreply.github.com> Date: Tue, 17 Nov 2026 18:57:28 +0100 Subject: [PATCH 1/3] fix(azure-devops): legacy and project-less remotes list their work items The Issues page showed Azure DevOps projects cloned from a legacy {org}.visualstudio.com remote, or from dev.azure.com/{org}/_git/{repo}, as unsupported: issueScope only placed org/project/_git/repo paths. It now reads the host from the repository key to place those shapes. Co-Authored-By: Claude Opus 5.5 --- .../client-runtime/src/issueLinks.test.ts | 25 +++++++++++++++++++ .../src/shared/definition.test.ts | 19 +++++++++++++- .../src/shared/definition.ts | 22 ++++++++++++---- .../src/shared/definition.ts | 7 ++++-- 4 files changed, 65 insertions(+), 8 deletions(-) diff --git a/packages/client-runtime/src/issueLinks.test.ts b/packages/client-runtime/src/issueLinks.test.ts index 004b526d99cfd..6293f81462354 100644 --- a/packages/client-runtime/src/issueLinks.test.ts +++ b/packages/client-runtime/src/issueLinks.test.ts @@ -58,6 +58,31 @@ describe("resolveIssueLinkTarget", () => { expect(target?.ref.projectId).toBe("ported"); }); + it("reads a legacy Azure DevOps work item through the project bound to its Azure project", () => { + const azure = (id: string, canonicalKey: string, displayName: string) => + ({ + id: ProjectId.make(id), + environmentId: EnvironmentId.make("env"), + repositoryIdentity: { + canonicalKey, + provider: SourceControlProviderKind.make("azure-devops"), + displayName, + }, + }) as never; + const target = resolveIssueLinkTarget({ + url: "https://acme.visualstudio.com/Web/_workitems/edit/9", + projects: [ + azure("api", "acme.visualstudio.com/api/_git/api", "Api/_git/api"), + azure( + "web", + "acme.visualstudio.com/defaultcollection/_git/web", + "DefaultCollection/_git/Web", + ), + ], + }); + expect(target?.ref).toMatchObject({ projectId: "web", scope: "web", key: "9" }); + }); + it.each([ "https://github.com.evil.example/acme/web/issues/7", "https://github.com/acme/web/pull/7", diff --git a/packages/source-control-azure-devops/src/shared/definition.test.ts b/packages/source-control-azure-devops/src/shared/definition.test.ts index 8a10c457f66c3..e2471c6795d55 100644 --- a/packages/source-control-azure-devops/src/shared/definition.test.ts +++ b/packages/source-control-azure-devops/src/shared/definition.test.ts @@ -260,8 +260,25 @@ describe("Azure DevOps issue scope", () => { definition.issueScope?.({ provider: kind, displayName: "acme/Web%20App/_git/web" }), ).toBe("acme/Web App"); expect(definition.issueScope?.({ provider: kind, displayName: "web" })).toBeNull(); - // One segment before `_git` is a different thing on each kind of host, so it is not placed. + // One segment before `_git` is a different thing on each kind of host, so it needs the host. expect(definition.issueScope?.({ provider: kind, displayName: "acme/_git/web" })).toBeNull(); + const scopeOn = (canonicalKey: string, displayName: string) => + definition.issueScope?.({ provider: kind, canonicalKey, displayName }); + expect(scopeOn("dev.azure.com/acme/_git/web", "acme/_git/Web")).toBe("acme/Web"); + expect(scopeOn("acme.visualstudio.com/web/_git/web", "Web%20App/_git/web")).toBe("Web App"); + expect(scopeOn("acme.visualstudio.com/_git/web", "_git/Web")).toBe("Web"); + // Its work items are at `acme.visualstudio.com/Web/_workitems/...`, without the collection. + expect( + scopeOn("acme.visualstudio.com/defaultcollection/_git/web", "DefaultCollection/_git/Web"), + ).toBe("Web"); + expect( + scopeOn( + "acme.visualstudio.com/defaultcollection/web/_git/web", + "DefaultCollection/Web/_git/web", + ), + ).toBe("DefaultCollection/Web"); + expect(scopeOn("dev.azure.com/acme/web/_git/web", "acme/Web/_git/web")).toBe("acme/Web"); + expect(scopeOn("dev.azure.com/_git/web", "_git/web")).toBeNull(); // A legacy host keeps the organization in its name, and so does its work item URL. expect( definition.parseIssueUrl?.( diff --git a/packages/source-control-azure-devops/src/shared/definition.ts b/packages/source-control-azure-devops/src/shared/definition.ts index 38490a062c76b..744b9628c6917 100644 --- a/packages/source-control-azure-devops/src/shared/definition.ts +++ b/packages/source-control-azure-devops/src/shared/definition.ts @@ -170,13 +170,25 @@ export const definition = defineSourceControl({ return name ? decodeUrlPathSegment(name) : null; }, // Work items belong to the project: `organization/project` out of the remote's - // `organization/project/_git/repository`. A shorter path is not placed: `acme/_git/web` is a - // project named after its repository on dev.azure.com and a bare project on a legacy host, and - // nothing here says which host the remote is on. + // `organization/project/_git/repository`. A shorter path depends on the host: `acme/_git/web` + // is a project named after its repository on dev.azure.com and a bare project on a legacy host. issueScope: (identity) => { - const segments = (identity.displayName ?? "").split("/").filter((part) => part !== ""); + const segments = (identity.displayName ?? "") + .split("/") + .filter((part) => part !== "") + .map(decodeUrlPathSegment); const at = segments.indexOf("_git"); - return at === 2 ? segments.slice(0, at).map(decodeUrlPathSegment).join("/") : null; + const repository = segments[at + 1]; + if (at === 2) return segments.slice(0, at).join("/"); + if (repository === undefined || (at !== 0 && at !== 1)) return null; + const host = identity.canonicalKey?.split("/", 1)[0]?.toLowerCase() ?? ""; + const legacy = host.endsWith(".visualstudio.com"); + const [first = ""] = segments; + if (at === 0) return legacy ? repository : null; + if (host === "dev.azure.com") return `${first}/${repository}`; + if (!legacy) return null; + // Work item URLs on a legacy host leave the collection out. + return first.toLowerCase() === "defaultcollection" ? repository : first; }, repositoryKeyFromRemote, canonicalRepositoryKey, diff --git a/packages/source-control-core/src/shared/definition.ts b/packages/source-control-core/src/shared/definition.ts index d8e22b811fc96..f2e55ca5d975a 100644 --- a/packages/source-control-core/src/shared/definition.ts +++ b/packages/source-control-core/src/shared/definition.ts @@ -94,6 +94,9 @@ export type RepositorySelectorIdentity = Pick< "provider" | "displayName" | "owner" | "name" >; +export type IssueScopeIdentity = RepositorySelectorIdentity & + Partial>; + /** A git remote's host, as `recognizeRemote` reads it. */ export interface GitRemoteHost { /** Trimmed. */ @@ -359,7 +362,7 @@ export interface SourceControlDefinition { * The container the project's issues live in, where that is not its repository: Azure DevOps * keeps work items per project. Null when the repository cannot be placed. */ - readonly issueScope?: (identity: RepositorySelectorIdentity) => string | null; + readonly issueScope?: (identity: IssueScopeIdentity) => string | null; /** * The key of a remote's lower case `host/path`, `.git` suffix kept, for a host that spells it * apart from `normalizeGitRemoteUrl`: over SSH and the web, or with `.git` as part of the name. @@ -695,7 +698,7 @@ export interface SourceControlDefinitionRegistry { identity: RepositorySelectorIdentity | null | undefined, ) => string | null; /** Where the project's issues live: the host's `issueScope`, else its repository. */ - readonly issueScope: (identity: RepositorySelectorIdentity | null | undefined) => string | null; + readonly issueScope: (identity: IssueScopeIdentity | null | undefined) => string | null; readonly changeRequestHost: ( identity: ChangeRequestHostIdentity, kind: Kind, From 1e9b3af36fe8ffea6c49089eab809b618a188cce Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 17 Nov 2026 18:15:21 +0000 Subject: [PATCH 2/3] refactor(azure-devops): tighten issue scope resolution and its tests Check the `_git` position before reading the repository segment, drop cases that repeat the existing three-segment behavior, and drop the client-runtime link test that repeats the definition-level coverage. Co-Authored-By: Claude Opus 5.5 --- .../client-runtime/src/issueLinks.test.ts | 25 ------------------- .../src/shared/definition.test.ts | 7 ------ .../src/shared/definition.ts | 4 +-- 3 files changed, 2 insertions(+), 34 deletions(-) diff --git a/packages/client-runtime/src/issueLinks.test.ts b/packages/client-runtime/src/issueLinks.test.ts index 6293f81462354..004b526d99cfd 100644 --- a/packages/client-runtime/src/issueLinks.test.ts +++ b/packages/client-runtime/src/issueLinks.test.ts @@ -58,31 +58,6 @@ describe("resolveIssueLinkTarget", () => { expect(target?.ref.projectId).toBe("ported"); }); - it("reads a legacy Azure DevOps work item through the project bound to its Azure project", () => { - const azure = (id: string, canonicalKey: string, displayName: string) => - ({ - id: ProjectId.make(id), - environmentId: EnvironmentId.make("env"), - repositoryIdentity: { - canonicalKey, - provider: SourceControlProviderKind.make("azure-devops"), - displayName, - }, - }) as never; - const target = resolveIssueLinkTarget({ - url: "https://acme.visualstudio.com/Web/_workitems/edit/9", - projects: [ - azure("api", "acme.visualstudio.com/api/_git/api", "Api/_git/api"), - azure( - "web", - "acme.visualstudio.com/defaultcollection/_git/web", - "DefaultCollection/_git/Web", - ), - ], - }); - expect(target?.ref).toMatchObject({ projectId: "web", scope: "web", key: "9" }); - }); - it.each([ "https://github.com.evil.example/acme/web/issues/7", "https://github.com/acme/web/pull/7", diff --git a/packages/source-control-azure-devops/src/shared/definition.test.ts b/packages/source-control-azure-devops/src/shared/definition.test.ts index e2471c6795d55..03388a076a42f 100644 --- a/packages/source-control-azure-devops/src/shared/definition.test.ts +++ b/packages/source-control-azure-devops/src/shared/definition.test.ts @@ -271,13 +271,6 @@ describe("Azure DevOps issue scope", () => { expect( scopeOn("acme.visualstudio.com/defaultcollection/_git/web", "DefaultCollection/_git/Web"), ).toBe("Web"); - expect( - scopeOn( - "acme.visualstudio.com/defaultcollection/web/_git/web", - "DefaultCollection/Web/_git/web", - ), - ).toBe("DefaultCollection/Web"); - expect(scopeOn("dev.azure.com/acme/web/_git/web", "acme/Web/_git/web")).toBe("acme/Web"); expect(scopeOn("dev.azure.com/_git/web", "_git/web")).toBeNull(); // A legacy host keeps the organization in its name, and so does its work item URL. expect( diff --git a/packages/source-control-azure-devops/src/shared/definition.ts b/packages/source-control-azure-devops/src/shared/definition.ts index 744b9628c6917..0a10201da8e3c 100644 --- a/packages/source-control-azure-devops/src/shared/definition.ts +++ b/packages/source-control-azure-devops/src/shared/definition.ts @@ -178,9 +178,9 @@ export const definition = defineSourceControl({ .filter((part) => part !== "") .map(decodeUrlPathSegment); const at = segments.indexOf("_git"); - const repository = segments[at + 1]; if (at === 2) return segments.slice(0, at).join("/"); - if (repository === undefined || (at !== 0 && at !== 1)) return null; + const repository = segments[at + 1]; + if ((at !== 0 && at !== 1) || repository === undefined) return null; const host = identity.canonicalKey?.split("/", 1)[0]?.toLowerCase() ?? ""; const legacy = host.endsWith(".visualstudio.com"); const [first = ""] = segments; From 4323042788e8981187dc1a9b476295e8a3520c49 Mon Sep 17 00:00:00 2001 From: shivam <91240327+shivamhwp@users.noreply.github.com> Date: Wed, 18 Nov 2026 11:32:16 +0000 Subject: [PATCH 3/3] fix(azure-devops): resolve legacy work item links through their project --- apps/server/src/issue/IssueService.test.ts | 33 +++++++++++++++++++ apps/server/src/issue/IssueService.ts | 9 +++-- packages/client-runtime/src/issueLinks.ts | 4 ++- .../src/shared/definition.test.ts | 17 +++++++++- .../src/shared/definition.ts | 16 +++++---- .../src/shared/definition.ts | 2 ++ 6 files changed, 70 insertions(+), 11 deletions(-) diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index 2e260451de2d7..e4f61ff49b82b 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -293,6 +293,39 @@ describe("IssueService", () => { }), ); + it.effect("resolves both legacy Azure work item URLs through the bound project", () => + Effect.gen(function* () { + const tracker = IssueTrackerKind.make("azure-devops"); + const host = "acme.visualstudio.com"; + const service = yield* makeService({ + projects: [ + project({ id: "api", repository: "Api/_git/api", provider: tracker, host }), + project({ + id: "web", + repository: "DefaultCollection/Web/_git/web", + provider: tracker, + host, + }), + ], + trackers: [fakeTracker({ kind: tracker })], + }); + for (const path of ["Web", "DefaultCollection/Web"]) { + const ref = yield* service.resolveUrl( + `https://${host}/${path}/_workitems/edit/9`, + "api" as ProjectId, + ); + expect(ref).toEqual({ + projectId: "web", + tracker, + host, + scope: "DefaultCollection/Web", + key: "9", + writable: true, + }); + } + }), + ); + 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 bf3d301f73708..fbf869e562001 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -704,9 +704,12 @@ const make = Effect.gen(function* () { const onTracker = onAuthority.length > 0 ? onAuthority : onHost; const preferFirst = (projects: ReadonlyArray) => projects.find((project) => project.project.id === preferredProjectId) ?? projects[0]; - const own = preferFirst( - onTracker.filter((project) => project.scope.toLowerCase() === link.scope.toLowerCase()), - ); + const scope = link.scope.toLowerCase(); + const own = + preferFirst(onTracker.filter((project) => project.scope.toLowerCase() === scope)) ?? + preferFirst( + onTracker.filter((project) => project.scope.toLowerCase() === gitHost?.link.scopeAlias), + ); const lender = own ?? preferFirst(onTracker); if (lender === undefined) { return yield* new IssueUnavailableError({ reason: "tracker-unsupported" }); diff --git a/packages/client-runtime/src/issueLinks.ts b/packages/client-runtime/src/issueLinks.ts index 3509bbbf33ed5..44da23d9d85bf 100644 --- a/packages/client-runtime/src/issueLinks.ts +++ b/packages/client-runtime/src/issueLinks.ts @@ -78,7 +78,9 @@ export function resolveIssueLinkTarget(input: { 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.binding.scope === link.scope)) ?? + preferFirst(bound.filter((candidate) => candidate.binding.scope === link.scopeAlias)); const lender = own ?? preferFirst(bound); if (lender === undefined) return null; return { diff --git a/packages/source-control-azure-devops/src/shared/definition.test.ts b/packages/source-control-azure-devops/src/shared/definition.test.ts index 03388a076a42f..f18b627a874be 100644 --- a/packages/source-control-azure-devops/src/shared/definition.test.ts +++ b/packages/source-control-azure-devops/src/shared/definition.test.ts @@ -277,7 +277,22 @@ describe("Azure DevOps issue scope", () => { definition.parseIssueUrl?.( new URL("https://acme.visualstudio.com/Web%20App/_workitems/edit/9"), ), - ).toEqual({ host: "acme.visualstudio.com", scope: "web app", key: "9" }); + ).toEqual({ + host: "acme.visualstudio.com", + scope: "web app", + scopeAlias: "defaultcollection/web app", + key: "9", + }); + expect( + definition.parseIssueUrl?.( + new URL("https://acme.visualstudio.com/DefaultCollection/Web%20App/_workitems/edit/9"), + ), + ).toEqual({ + host: "acme.visualstudio.com", + scope: "defaultcollection/web app", + scopeAlias: "web app", + key: "9", + }); expect( definition.parseIssueUrl?.(new URL("https://dev.azure.com/acme/_workitems/edit/9")), ).toBeNull(); diff --git a/packages/source-control-azure-devops/src/shared/definition.ts b/packages/source-control-azure-devops/src/shared/definition.ts index 0a10201da8e3c..78f1a4df45a8d 100644 --- a/packages/source-control-azure-devops/src/shared/definition.ts +++ b/packages/source-control-azure-devops/src/shared/definition.ts @@ -124,14 +124,18 @@ export const definition = defineSourceControl({ }, // A project named with spaces arrives percent-encoded; the binding it is matched against is not. parseIssueUrl: (url) => { + const legacy = url.hostname.toLowerCase().endsWith(".visualstudio.com"); const link = parseIssuePath(url, WORK_ITEM_PATH) ?? - (url.hostname.toLowerCase().endsWith(".visualstudio.com") - ? parseIssuePath(url, LEGACY_WORK_ITEM_PATH) - : null); - return link === null - ? null - : { ...link, scope: link.scope.split("/").map(decodeUrlPathSegment).join("/").toLowerCase() }; + (legacy ? parseIssuePath(url, LEGACY_WORK_ITEM_PATH) : null); + if (link === null) return null; + const scope = link.scope.split("/").map(decodeUrlPathSegment).join("/").toLowerCase(); + if (!legacy) return { ...link, scope }; + // On legacy hosts the default collection is optional in a work item URL. + const scopeAlias = + /^defaultcollection\/([^/]+)$/u.exec(scope)?.[1] ?? + (scope.includes("/") ? undefined : `defaultcollection/${scope}`); + return { ...link, scope, ...(scopeAlias === undefined ? {} : { scopeAlias }) }; }, changeRequestUrlFromReferenceAutolink: () => null, changeRequestActions: new Set([ diff --git a/packages/source-control-core/src/shared/definition.ts b/packages/source-control-core/src/shared/definition.ts index 85bc1fa18400e..d9fe29114a96c 100644 --- a/packages/source-control-core/src/shared/definition.ts +++ b/packages/source-control-core/src/shared/definition.ts @@ -39,6 +39,8 @@ export interface ChangeRequestLink { export interface IssueLink { readonly host: string; readonly scope: string; + /** An equivalent binding scope when the provider allows another spelling in URLs. */ + readonly scopeAlias?: string; readonly key: string; }