From 00c20fdff9de583ef8449983858caef9c2eb6f3a Mon Sep 17 00:00:00 2001 From: OrcaWin <293788423+OrcaWin@users.noreply.github.com> Date: Tue, 18 Aug 2026 16:20:51 -0700 Subject: [PATCH 1/5] fix(worktrees): honor absolute Linux worktree base paths for WSL repos (STA-4772) Project setup accepted /home/... worktree base paths for WSL-backed repos and reported them ready, but the WSL workspace-mirroring heuristic read them as desktop-absolute roots (win32.isAbsolute) and silently replaced them with ~/orca/workspaces at create time. Resolve repo-scoped POSIX-absolute base paths into the repo's own distro UNC form at the resolution boundary, for both creation-path settings and ownership layouts. UNC, drive, relative, native Windows, macOS/Linux, and SSH base paths pass through unchanged. --- src/main/ipc/worktree-logic-wsl.test.ts | 64 ++++++++++++++++++- src/main/ipc/worktree-logic.ts | 8 ++- .../ownership-worktree-base-path.test.ts | 24 +++++++ src/shared/worktree/ownership.ts | 11 +++- src/shared/wsl-paths.test.ts | 37 +++++++++++ src/shared/wsl-paths.ts | 20 ++++++ 6 files changed, 158 insertions(+), 6 deletions(-) diff --git a/src/main/ipc/worktree-logic-wsl.test.ts b/src/main/ipc/worktree-logic-wsl.test.ts index 1b5d3c011d34..3bbafceae145 100644 --- a/src/main/ipc/worktree-logic-wsl.test.ts +++ b/src/main/ipc/worktree-logic-wsl.test.ts @@ -11,7 +11,7 @@ vi.mock('../wsl', () => ({ parseWslPath: parseWslPathMock })) -import { computeWorktreePath } from './worktree-logic' +import { computeWorktreePath, getWorktreePathSettings } from './worktree-logic' describe('computeWorktreePath WSL layout', () => { beforeEach(() => { @@ -49,6 +49,68 @@ describe('computeWorktreePath WSL layout', () => { ).toBe(win32.join('C:\\workspaces', 'feature')) }) + it('honors an absolute Linux repo worktree base path inside the repo distro (STA-4772)', () => { + parseWslPathMock.mockReturnValue({ + distro: 'Ubuntu', + linuxPath: '/home/jin/src/repo' + }) + getWslHomeMock.mockReturnValue('\\\\wsl.localhost\\Ubuntu\\home\\jin') + const repo = { + path: '\\\\wsl.localhost\\Ubuntu\\home\\jin\\src\\repo', + worktreeBasePath: '/home/jin/src/.orca-worktrees' + } + const settings = { nestWorkspaces: false, workspaceDir: 'C:\\workspaces' } + + expect(computeWorktreePath('feature', repo.path, getWorktreePathSettings(repo, settings))).toBe( + '\\\\wsl.localhost\\Ubuntu\\home\\jin\\src\\.orca-worktrees\\feature' + ) + // Why repeat: cached follow-up calls must resolve identically to the first. + expect(computeWorktreePath('feature', repo.path, getWorktreePathSettings(repo, settings))).toBe( + '\\\\wsl.localhost\\Ubuntu\\home\\jin\\src\\.orca-worktrees\\feature' + ) + expect(getWslHomeMock).not.toHaveBeenCalled() + }) + + it('honors a Linux repo base path even when the distro home lookup fails', () => { + parseWslPathMock.mockReturnValue({ + distro: 'Ubuntu', + linuxPath: '/home/jin/src/repo' + }) + getWslHomeMock.mockReturnValue(null) + const repo = { + path: '\\\\wsl.localhost\\Ubuntu\\home\\jin\\src\\repo', + worktreeBasePath: '/home/jin/trees' + } + + expect( + computeWorktreePath( + 'feature', + repo.path, + getWorktreePathSettings(repo, { nestWorkspaces: false, workspaceDir: 'C:\\workspaces' }) + ) + ).toBe('\\\\wsl.localhost\\Ubuntu\\home\\jin\\trees\\feature') + }) + + it('keeps relative repo base paths anchored to the WSL repo', () => { + parseWslPathMock.mockReturnValue({ + distro: 'Ubuntu', + linuxPath: '/home/jin/src/repo' + }) + getWslHomeMock.mockReturnValue('\\\\wsl.localhost\\Ubuntu\\home\\jin') + const repo = { + path: '\\\\wsl.localhost\\Ubuntu\\home\\jin\\src\\repo', + worktreeBasePath: '../worktrees' + } + + expect( + computeWorktreePath( + 'feature', + repo.path, + getWorktreePathSettings(repo, { nestWorkspaces: false, workspaceDir: 'C:\\workspaces' }) + ) + ).toBe('\\\\wsl.localhost\\Ubuntu\\home\\jin\\src\\worktrees\\feature') + }) + it('uses an explicit WSL UNC workspace root without remapping it', () => { parseWslPathMock.mockReturnValue({ distro: 'Ubuntu', diff --git a/src/main/ipc/worktree-logic.ts b/src/main/ipc/worktree-logic.ts index a98133428a2e..d5ccb345742a 100644 --- a/src/main/ipc/worktree-logic.ts +++ b/src/main/ipc/worktree-logic.ts @@ -2,7 +2,7 @@ import { resolve, relative, isAbsolute, posix, sep, win32 } from 'node:path' import type { GlobalSettings, OrcaWorkspaceLayout } from '../../shared/global-settings-types' import type { Repo } from '../../shared/repo-types' import { isWindowsAbsolutePathLike, resolveRuntimePath } from '../../shared/cross-platform-path' -import { isWslUncPath } from '../../shared/wsl-paths' +import { isWslUncPath, resolveWslRepoWorktreeBasePath } from '../../shared/wsl-paths' import { splitWorktreeId } from '../../shared/worktree/id' import { replaceKnownEmojiWithShortcodes } from '../../shared/emoji-shortcode-catalog' import { getWslHome, getWslHomeAsync, parseWslPath } from '../wsl' @@ -226,7 +226,11 @@ function getEffectiveWorktreeBasePath( repo: WorktreeBasePathRepo, settings: WorktreePathSettings ): string { - return getRepoWorktreeBasePath(repo) ?? settings.workspaceDir + const basePath = getRepoWorktreeBasePath(repo) + if (basePath === undefined) { + return settings.workspaceDir + } + return resolveWslRepoWorktreeBasePath(repo.path, basePath) } function getRepoWorktreeBasePath(repo: Pick): string | undefined { diff --git a/src/shared/worktree/ownership-worktree-base-path.test.ts b/src/shared/worktree/ownership-worktree-base-path.test.ts index 549a3d467630..bc6ba74fc4bd 100644 --- a/src/shared/worktree/ownership-worktree-base-path.test.ts +++ b/src/shared/worktree/ownership-worktree-base-path.test.ts @@ -78,6 +78,30 @@ describe('repo-specific worktree ownership layouts', () => { ).toBe('external') }) + it('resolves an absolute Linux base path of a WSL repo into its distro layout (STA-4772)', () => { + const repo = makeRepo({ + path: '\\\\wsl.localhost\\Ubuntu-24.04\\home\\jin\\src\\repo', + worktreeBasePath: '/home/jin/src/.orca-worktrees' + }) + const settings = makeSettings({ workspaceDir: 'C:\\global' }) + const layouts = buildKnownOrcaWorkspaceLayouts(settings, repo) + + expect(layouts[0]).toEqual({ + path: '//wsl.localhost/Ubuntu-24.04/home/jin/src/.orca-worktrees', + nestWorkspaces: true + }) + expect( + classifyWorktreeOwnership({ + repo, + settings, + worktree: makeWorktree( + '\\\\wsl.localhost\\Ubuntu-24.04\\home\\jin\\src\\.orca-worktrees\\repo\\feature' + ), + knownOrcaLayouts: layouts + }) + ).toBe('external') + }) + it('includes relative global layouts for SSH repos without applying absolute desktop paths', () => { const repo = makeRepo({ path: '/remote/repo', connectionId: 'ssh-1' }) const relativeSettings = makeSettings({ workspaceDir: '../worktrees' }) diff --git a/src/shared/worktree/ownership.ts b/src/shared/worktree/ownership.ts index d6d1bc7aea37..14777577fd36 100644 --- a/src/shared/worktree/ownership.ts +++ b/src/shared/worktree/ownership.ts @@ -6,7 +6,7 @@ import { relativePathInsideRoot, resolveRuntimePath } from '../cross-platform-path' -import { parseWslUncPath } from '../wsl-paths' +import { parseWslUncPath, resolveWslRepoWorktreeBasePath } from '../wsl-paths' import { isAgentScratchWorktreePath, type AgentScratchWorktreePathMatcher @@ -87,10 +87,15 @@ function appendWorkspaceLayouts( } function getRepoWorktreeBasePath( - repo: Pick | undefined + repo: Pick | undefined ): string | undefined { const trimmed = repo?.worktreeBasePath?.trim() - return trimmed || undefined + if (!repo || !trimmed) { + return undefined + } + // Why: creation resolves Linux base paths of WSL repos to their UNC form, + // so ownership layouts must match or those worktrees would never classify. + return resolveWslRepoWorktreeBasePath(repo.path, trimmed) } function resolveWorkspaceLayoutPath(repoPath: string, layoutPath: string): string { diff --git a/src/shared/wsl-paths.test.ts b/src/shared/wsl-paths.test.ts index 6a9641d41acb..adffed15597f 100644 --- a/src/shared/wsl-paths.test.ts +++ b/src/shared/wsl-paths.test.ts @@ -3,6 +3,7 @@ import { foldWslUncPathCaseInsensitiveParts, isWslUncPath, parseWslUncPath, + resolveWslRepoWorktreeBasePath, toWindowsWslPath } from './wsl-paths' @@ -34,6 +35,42 @@ describe('wsl path helpers', () => { }) }) +describe('resolveWslRepoWorktreeBasePath', () => { + const WSL_REPO = '\\\\wsl.localhost\\Ubuntu-24.04\\home\\jin\\src\\repo' + + it('resolves an absolute Linux base path into the repo distro (STA-4772)', () => { + expect(resolveWslRepoWorktreeBasePath(WSL_REPO, '/home/jin/project/.orca-worktrees')).toBe( + '\\\\wsl.localhost\\Ubuntu-24.04\\home\\jin\\project\\.orca-worktrees' + ) + expect(resolveWslRepoWorktreeBasePath('\\\\wsl$\\Debian\\srv\\repo', '/srv/trees')).toBe( + '\\\\wsl.localhost\\Debian\\srv\\trees' + ) + }) + + it('maps drvfs base paths to their drive form', () => { + expect(resolveWslRepoWorktreeBasePath(WSL_REPO, '/mnt/d/trees')).toBe('D:\\trees') + }) + + it('keeps UNC, drive, and relative base paths untouched for WSL repos', () => { + expect( + resolveWslRepoWorktreeBasePath(WSL_REPO, '\\\\wsl.localhost\\Ubuntu-24.04\\home\\jin\\trees') + ).toBe('\\\\wsl.localhost\\Ubuntu-24.04\\home\\jin\\trees') + expect(resolveWslRepoWorktreeBasePath(WSL_REPO, '//wsl.localhost/Ubuntu-24.04/trees')).toBe( + '//wsl.localhost/Ubuntu-24.04/trees' + ) + expect(resolveWslRepoWorktreeBasePath(WSL_REPO, 'D:\\trees')).toBe('D:\\trees') + expect(resolveWslRepoWorktreeBasePath(WSL_REPO, '../worktrees')).toBe('../worktrees') + }) + + it('never rewrites base paths of non-WSL repos', () => { + expect(resolveWslRepoWorktreeBasePath('C:\\src\\repo', '/home/jin/trees')).toBe( + '/home/jin/trees' + ) + expect(resolveWslRepoWorktreeBasePath('/srv/repo', '/srv/trees')).toBe('/srv/trees') + expect(resolveWslRepoWorktreeBasePath('//server/share/repo', '/srv/trees')).toBe('/srv/trees') + }) +}) + describe('foldWslUncPathCaseInsensitiveParts', () => { it('folds share spelling, distro casing, and separators but not the Linux tail', () => { expect(foldWslUncPathCaseInsensitiveParts('\\\\WSL$\\Ubuntu\\home\\jin\\Repo')).toBe( diff --git a/src/shared/wsl-paths.ts b/src/shared/wsl-paths.ts index f779bc2d2ff4..b79bf2d9936e 100644 --- a/src/shared/wsl-paths.ts +++ b/src/shared/wsl-paths.ts @@ -58,6 +58,26 @@ export function toWindowsWslPath(linuxPath: string, distro: string): string { return `\\\\wsl.localhost\\${distro}${linuxPath.replace(/\//g, '\\')}` } +/** + * Resolve a repo-scoped worktree base path against the repo's own WSL distro. + * + * Why: project setup stores the value verbatim, and for a WSL-backed repo an + * absolute Linux path like /home/user/trees is the natural spelling of a + * location inside that distro. Windows path code reads it as drive-relative, + * so the WSL workspace-mirroring heuristic silently replaced it with + * ~/orca/workspaces (STA-4772). The repo path pins the distro, making the + * value unambiguous — translate it to its UNC form. Non-WSL repos and + * non-POSIX values (UNC, drive, relative) pass through untouched, so native + * Windows, macOS/Linux, and SSH base paths keep their meaning. + */ +export function resolveWslRepoWorktreeBasePath(repoPath: string, basePath: string): string { + const repoWsl = parseWslUncPath(repoPath) + if (!repoWsl || !/^\/(?!\/)/.test(basePath)) { + return basePath + } + return toWindowsWslPath(basePath, repoWsl.distro) +} + // Why: Windows folds the share (\\wsl$ aliases \\wsl.localhost), the distro, and // drvfs /mnt/ tails case-insensitively; the rest of the Linux path is not. export function foldWslUncPathCaseInsensitiveParts(path: string): string | null { From 346139d3da18406104ab0301189d2732f0843a54 Mon Sep 17 00:00:00 2001 From: OrcaWin <293788423+OrcaWin@users.noreply.github.com> Date: Tue, 18 Aug 2026 16:35:55 -0700 Subject: [PATCH 2/5] fix(worktrees): keep drvfs and dotted WSL base paths honored after review Review findings from three independent passes: mapping /mnt/ bases to drive letters re-triggered the desktop-mirroring heuristic that discards the configured base, and uncollapsed dot segments made ownership layouts disagree with creation. Resolve every POSIX base of a WSL repo onto the distro UNC view and collapse dot segments in the resolver so both consumers see one spelling. --- src/main/ipc/worktree-logic-wsl.test.ts | 52 ++++++++++++++++++++++++- src/shared/wsl-paths.test.ts | 18 ++++++++- src/shared/wsl-paths.ts | 24 +++++++++++- 3 files changed, 89 insertions(+), 5 deletions(-) diff --git a/src/main/ipc/worktree-logic-wsl.test.ts b/src/main/ipc/worktree-logic-wsl.test.ts index 3bbafceae145..abd36532e8d3 100644 --- a/src/main/ipc/worktree-logic-wsl.test.ts +++ b/src/main/ipc/worktree-logic-wsl.test.ts @@ -1,21 +1,28 @@ import { win32 } from 'node:path' import { beforeEach, describe, expect, it, vi } from 'vitest' -const { getWslHomeMock, parseWslPathMock } = vi.hoisted(() => ({ +const { getWslHomeMock, getWslHomeAsyncMock, parseWslPathMock } = vi.hoisted(() => ({ getWslHomeMock: vi.fn(), + getWslHomeAsyncMock: vi.fn(), parseWslPathMock: vi.fn() })) vi.mock('../wsl', () => ({ getWslHome: getWslHomeMock, + getWslHomeAsync: getWslHomeAsyncMock, parseWslPath: parseWslPathMock })) -import { computeWorktreePath, getWorktreePathSettings } from './worktree-logic' +import { + computeWorktreePath, + computeWorktreePathAsync, + getWorktreePathSettings +} from './worktree-logic' describe('computeWorktreePath WSL layout', () => { beforeEach(() => { getWslHomeMock.mockReset() + getWslHomeAsyncMock.mockReset() parseWslPathMock.mockReset() }) @@ -71,6 +78,47 @@ describe('computeWorktreePath WSL layout', () => { expect(getWslHomeMock).not.toHaveBeenCalled() }) + it('honors a drvfs /mnt repo base path instead of mirroring it away', () => { + parseWslPathMock.mockReturnValue({ + distro: 'Ubuntu', + linuxPath: '/home/jin/src/repo' + }) + getWslHomeMock.mockReturnValue('\\\\wsl.localhost\\Ubuntu\\home\\jin') + const repo = { + path: '\\\\wsl.localhost\\Ubuntu\\home\\jin\\src\\repo', + worktreeBasePath: '/mnt/d/trees' + } + + expect( + computeWorktreePath( + 'feature', + repo.path, + getWorktreePathSettings(repo, { nestWorkspaces: false, workspaceDir: 'C:\\workspaces' }) + ) + ).toBe('\\\\wsl.localhost\\Ubuntu\\mnt\\d\\trees\\feature') + }) + + it('resolves the Linux repo base path identically through the async twin', async () => { + parseWslPathMock.mockReturnValue({ + distro: 'Ubuntu', + linuxPath: '/home/jin/src/repo' + }) + getWslHomeMock.mockReturnValue('\\\\wsl.localhost\\Ubuntu\\home\\jin') + getWslHomeAsyncMock.mockResolvedValue('\\\\wsl.localhost\\Ubuntu\\home\\jin') + const repo = { + path: '\\\\wsl.localhost\\Ubuntu\\home\\jin\\src\\repo', + worktreeBasePath: '/home/jin/src/.orca-worktrees' + } + const pathSettings = getWorktreePathSettings(repo, { + nestWorkspaces: false, + workspaceDir: 'C:\\workspaces' + }) + + await expect(computeWorktreePathAsync('feature', repo.path, pathSettings)).resolves.toBe( + computeWorktreePath('feature', repo.path, pathSettings) + ) + }) + it('honors a Linux repo base path even when the distro home lookup fails', () => { parseWslPathMock.mockReturnValue({ distro: 'Ubuntu', diff --git a/src/shared/wsl-paths.test.ts b/src/shared/wsl-paths.test.ts index adffed15597f..90fe0890c18d 100644 --- a/src/shared/wsl-paths.test.ts +++ b/src/shared/wsl-paths.test.ts @@ -47,8 +47,22 @@ describe('resolveWslRepoWorktreeBasePath', () => { ) }) - it('maps drvfs base paths to their drive form', () => { - expect(resolveWslRepoWorktreeBasePath(WSL_REPO, '/mnt/d/trees')).toBe('D:\\trees') + it('keeps drvfs base paths on the distro UNC view so mirroring cannot discard them', () => { + expect(resolveWslRepoWorktreeBasePath(WSL_REPO, '/mnt/d/trees')).toBe( + '\\\\wsl.localhost\\Ubuntu-24.04\\mnt\\d\\trees' + ) + }) + + it('collapses dot segments and trailing slashes so ownership layouts match creation', () => { + expect(resolveWslRepoWorktreeBasePath(WSL_REPO, '/home/jin/src/../trees')).toBe( + '\\\\wsl.localhost\\Ubuntu-24.04\\home\\jin\\trees' + ) + expect(resolveWslRepoWorktreeBasePath(WSL_REPO, '/home/jin/./trees/')).toBe( + '\\\\wsl.localhost\\Ubuntu-24.04\\home\\jin\\trees' + ) + expect(resolveWslRepoWorktreeBasePath(WSL_REPO, '/../..')).toBe( + '\\\\wsl.localhost\\Ubuntu-24.04\\' + ) }) it('keeps UNC, drive, and relative base paths untouched for WSL repos', () => { diff --git a/src/shared/wsl-paths.ts b/src/shared/wsl-paths.ts index b79bf2d9936e..506bb6a45b1a 100644 --- a/src/shared/wsl-paths.ts +++ b/src/shared/wsl-paths.ts @@ -69,13 +69,35 @@ export function toWindowsWslPath(linuxPath: string, distro: string): string { * value unambiguous — translate it to its UNC form. Non-WSL repos and * non-POSIX values (UNC, drive, relative) pass through untouched, so native * Windows, macOS/Linux, and SSH base paths keep their meaning. + * + * Why not toWindowsWslPath: its /mnt/ branch emits a drive-letter path, + * which the workspace-mirroring heuristic reads as desktop-local and discards — + * the very bug this resolves. drvfs bases stay on the distro UNC view instead. + * Dot segments collapse here because ownership layouts compare paths without + * resolving them, so creation and classification must see the same spelling. */ export function resolveWslRepoWorktreeBasePath(repoPath: string, basePath: string): string { const repoWsl = parseWslUncPath(repoPath) if (!repoWsl || !/^\/(?!\/)/.test(basePath)) { return basePath } - return toWindowsWslPath(basePath, repoWsl.distro) + const collapsed = collapsePosixDotSegments(basePath) + return `\\\\wsl.localhost\\${repoWsl.distro}${collapsed === '/' ? '\\' : collapsed.replace(/\//g, '\\')}` +} + +function collapsePosixDotSegments(absolutePosixPath: string): string { + const segments: string[] = [] + for (const segment of absolutePosixPath.split('/')) { + if (!segment || segment === '.') { + continue + } + if (segment === '..') { + segments.pop() + continue + } + segments.push(segment) + } + return `/${segments.join('/')}` } // Why: Windows folds the share (\\wsl$ aliases \\wsl.localhost), the distro, and From 07fe9d2ccef86b62ecf6d6564e3068f37adcd56b Mon Sep 17 00:00:00 2001 From: OrcaWin <293788423+OrcaWin@users.noreply.github.com> Date: Thu, 20 Aug 2026 16:03:23 -0700 Subject: [PATCH 3/5] test(worktrees): pin dotted and drive-letter WSL base paths end to end Round-two review (3x gpt-5.6-luna + Opus): pin the dotted-base collapse on both the creation and ownership sides so a one-sided normalization change cannot silently break classification, and pin the deliberate drive-letter-base mirror into the distro home. --- src/main/ipc/worktree-logic-wsl.test.ts | 41 +++++++++++++++++++ .../ownership-worktree-base-path.test.ts | 24 +++++++++++ 2 files changed, 65 insertions(+) diff --git a/src/main/ipc/worktree-logic-wsl.test.ts b/src/main/ipc/worktree-logic-wsl.test.ts index abd36532e8d3..330519d3b966 100644 --- a/src/main/ipc/worktree-logic-wsl.test.ts +++ b/src/main/ipc/worktree-logic-wsl.test.ts @@ -98,6 +98,47 @@ describe('computeWorktreePath WSL layout', () => { ).toBe('\\\\wsl.localhost\\Ubuntu\\mnt\\d\\trees\\feature') }) + it('collapses dotted Linux repo base paths end to end', () => { + parseWslPathMock.mockReturnValue({ + distro: 'Ubuntu', + linuxPath: '/home/jin/src/repo' + }) + getWslHomeMock.mockReturnValue('\\\\wsl.localhost\\Ubuntu\\home\\jin') + const repo = { + path: '\\\\wsl.localhost\\Ubuntu\\home\\jin\\src\\repo', + worktreeBasePath: '/home/jin/src/../trees' + } + + expect( + computeWorktreePath( + 'feature', + repo.path, + getWorktreePathSettings(repo, { nestWorkspaces: false, workspaceDir: 'C:\\workspaces' }) + ) + ).toBe('\\\\wsl.localhost\\Ubuntu\\home\\jin\\trees\\feature') + }) + + it('still mirrors drive-letter repo base paths into the distro home', () => { + parseWslPathMock.mockReturnValue({ + distro: 'Ubuntu', + linuxPath: '/home/jin/src/repo' + }) + getWslHomeMock.mockReturnValue('\\\\wsl.localhost\\Ubuntu\\home\\jin') + const repo = { + path: '\\\\wsl.localhost\\Ubuntu\\home\\jin\\src\\repo', + worktreeBasePath: 'D:\\trees' + } + + // Why: desktop drive roots keep WSL worktrees on the WSL filesystem by design. + expect( + computeWorktreePath( + 'feature', + repo.path, + getWorktreePathSettings(repo, { nestWorkspaces: false, workspaceDir: 'C:\\workspaces' }) + ) + ).toBe('\\\\wsl.localhost\\Ubuntu\\home\\jin\\orca\\workspaces\\feature') + }) + it('resolves the Linux repo base path identically through the async twin', async () => { parseWslPathMock.mockReturnValue({ distro: 'Ubuntu', diff --git a/src/shared/worktree/ownership-worktree-base-path.test.ts b/src/shared/worktree/ownership-worktree-base-path.test.ts index bc6ba74fc4bd..18953a4fd920 100644 --- a/src/shared/worktree/ownership-worktree-base-path.test.ts +++ b/src/shared/worktree/ownership-worktree-base-path.test.ts @@ -102,6 +102,30 @@ describe('repo-specific worktree ownership layouts', () => { ).toBe('external') }) + it('classifies worktrees under a dotted Linux base exactly where creation collapses it', () => { + const repo = makeRepo({ + path: '\\\\wsl.localhost\\Ubuntu-24.04\\home\\jin\\src\\repo', + worktreeBasePath: '/home/jin/src/../.orca-worktrees' + }) + const settings = makeSettings({ workspaceDir: 'C:\\global' }) + const layouts = buildKnownOrcaWorkspaceLayouts(settings, repo) + + expect(layouts[0]).toEqual({ + path: '//wsl.localhost/Ubuntu-24.04/home/jin/.orca-worktrees', + nestWorkspaces: true + }) + expect( + classifyWorktreeOwnership({ + repo, + settings, + worktree: makeWorktree( + '\\\\wsl.localhost\\Ubuntu-24.04\\home\\jin\\.orca-worktrees\\repo\\feature' + ), + knownOrcaLayouts: layouts + }) + ).toBe('external') + }) + it('includes relative global layouts for SSH repos without applying absolute desktop paths', () => { const repo = makeRepo({ path: '/remote/repo', connectionId: 'ssh-1' }) const relativeSettings = makeSettings({ workspaceDir: '../worktrees' }) From 654d3cb0d8dcfcdc01a4c8eb5e94ce497c6fc5a8 Mon Sep 17 00:00:00 2001 From: OrcaWin <293788423+OrcaWin@users.noreply.github.com> Date: Thu, 20 Aug 2026 16:10:59 -0700 Subject: [PATCH 4/5] test(worktrees): assert creation/ownership agreement; document deliberate WSL base-path trade-offs Opus review round: pin the real invariant (creation output classifies) instead of paired hardcoded strings, and record that the /mnt UNC route and the single-leading-slash guard are deliberate so neither gets 'optimized' back into the mirror-discard bug. --- src/main/ipc/worktree-logic-wsl.test.ts | 43 +++++++++++++++++++++++++ src/shared/wsl-paths.ts | 6 +++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/main/ipc/worktree-logic-wsl.test.ts b/src/main/ipc/worktree-logic-wsl.test.ts index 330519d3b966..d8c486f15a83 100644 --- a/src/main/ipc/worktree-logic-wsl.test.ts +++ b/src/main/ipc/worktree-logic-wsl.test.ts @@ -18,6 +18,11 @@ import { computeWorktreePathAsync, getWorktreePathSettings } from './worktree-logic' +import { + buildKnownOrcaWorkspaceLayouts, + classifyWorktreeOwnership +} from '../../shared/worktree/ownership' +import type { Repo } from '../../shared/repo-types' describe('computeWorktreePath WSL layout', () => { beforeEach(() => { @@ -139,6 +144,44 @@ describe('computeWorktreePath WSL layout', () => { ).toBe('\\\\wsl.localhost\\Ubuntu\\home\\jin\\orca\\workspaces\\feature') }) + it('classifies whatever creation produces for Linux bases, dotted or not', () => { + parseWslPathMock.mockReturnValue({ + distro: 'Ubuntu', + linuxPath: '/home/jin/src/repo' + }) + getWslHomeMock.mockReturnValue('\\\\wsl.localhost\\Ubuntu\\home\\jin') + const settings = { nestWorkspaces: true, workspaceDir: 'C:\\workspaces' } + for (const worktreeBasePath of ['/home/jin/trees', '/home/jin/src/../trees', '/mnt/d/trees']) { + const repo = { + id: 'r1', + path: '\\\\wsl.localhost\\Ubuntu\\home\\jin\\src\\repo', + displayName: 'repo', + badgeColor: '#000', + addedAt: 0, + kind: 'git', + worktreeBasePath + } as Repo + // Why: the resolver exists so these two layers agree; assert the + // invariant directly instead of two hardcoded strings that happen to match. + const createdPath = computeWorktreePath( + 'feature', + repo.path, + getWorktreePathSettings(repo, settings) + ) + expect( + classifyWorktreeOwnership({ + repo, + settings: { ...settings, workspaceDirHistory: [] }, + worktree: { path: createdPath, isMainWorktree: false }, + knownOrcaLayouts: buildKnownOrcaWorkspaceLayouts( + { ...settings, workspaceDirHistory: [] }, + repo + ) + }) + ).toBe('external') + } + }) + it('resolves the Linux repo base path identically through the async twin', async () => { parseWslPathMock.mockReturnValue({ distro: 'Ubuntu', diff --git a/src/shared/wsl-paths.ts b/src/shared/wsl-paths.ts index 506bb6a45b1a..2835bcb11d2e 100644 --- a/src/shared/wsl-paths.ts +++ b/src/shared/wsl-paths.ts @@ -72,7 +72,11 @@ export function toWindowsWslPath(linuxPath: string, distro: string): string { * * Why not toWindowsWslPath: its /mnt/ branch emits a drive-letter path, * which the workspace-mirroring heuristic reads as desktop-local and discards — - * the very bug this resolves. drvfs bases stay on the distro UNC view instead. + * the very bug this resolves. drvfs bases stay on the distro UNC view instead, + * deliberately trading Windows-side throughput for a distro-addressable path + * that keeps terminals inside WSL. The single-leading-slash guard is also + * deliberate: multi-slash (//x) and backslash-rooted spellings are ambiguous + * with Windows UNC and drive-relative forms and keep their old behavior. * Dot segments collapse here because ownership layouts compare paths without * resolving them, so creation and classification must see the same spelling. */ From 3b1235289e087ee611387992b46a6b2b157b3e51 Mon Sep 17 00:00:00 2001 From: OrcaWin <293788423+OrcaWin@users.noreply.github.com> Date: Thu, 20 Aug 2026 16:13:35 -0700 Subject: [PATCH 5/5] test(worktrees): make the creation/ownership agreement test discriminate Opus follow-up: a regressed resolver lands in the ~/orca/workspaces mirror layout, which also classifies 'external', so the ownership assertion alone passed either way. Assert containment in the repo-base layout, which goes red under both one-sided and full reverts. --- src/main/ipc/worktree-logic-wsl.test.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/ipc/worktree-logic-wsl.test.ts b/src/main/ipc/worktree-logic-wsl.test.ts index d8c486f15a83..7921fdd1f931 100644 --- a/src/main/ipc/worktree-logic-wsl.test.ts +++ b/src/main/ipc/worktree-logic-wsl.test.ts @@ -22,6 +22,7 @@ import { buildKnownOrcaWorkspaceLayouts, classifyWorktreeOwnership } from '../../shared/worktree/ownership' +import { relativePathInsideRoot } from '../../shared/cross-platform-path' import type { Repo } from '../../shared/repo-types' describe('computeWorktreePath WSL layout', () => { @@ -168,15 +169,17 @@ describe('computeWorktreePath WSL layout', () => { repo.path, getWorktreePathSettings(repo, settings) ) + const layouts = buildKnownOrcaWorkspaceLayouts({ ...settings, workspaceDirHistory: [] }, repo) + // Why containment, not just ownership: a regressed resolver lands in the + // ~/orca/workspaces mirror layout, which also classifies 'external'. + // layouts[0] is the repo-base layout — it is always pushed first. + expect(relativePathInsideRoot(layouts[0].path, createdPath)).not.toBeNull() expect( classifyWorktreeOwnership({ repo, settings: { ...settings, workspaceDirHistory: [] }, worktree: { path: createdPath, isMainWorktree: false }, - knownOrcaLayouts: buildKnownOrcaWorkspaceLayouts( - { ...settings, workspaceDirHistory: [] }, - repo - ) + knownOrcaLayouts: layouts }) ).toBe('external') }