From 0659016aee7217beacd56833109e675ba7707578 Mon Sep 17 00:00:00 2001 From: yanzoro926 <276455829+yanzoro926@users.noreply.github.com> Date: Wed, 28 Oct 2026 07:57:53 +0000 Subject: [PATCH] fix(paths): keep the UNC prefix when folding separators resolveAddressPath() re-spells an address path in the base's separator style. Folding every separator run into one '\' also folded the UNC share marker of a \\wsl.localhost\\... path, turning an absolute network path into a drive-root-relative one. On Windows the host's requireAbsolute() then path.resolve()d it onto the host process drive (C:\wsl.localhost\...), so every file opened from a WSL workspace failed with ENOENT. Keep exactly the two leading separators of a UNC path and fold only the rest. Drive paths, POSIX bases and unknown bases are unchanged. tests/worktree-address.spec.ts pins the UNC absolute, workspace-relative and forward-slash spellings; the case fails on the previous source and passes with the fix. --- CHANGELOG.md | 5 +++++ CHANGELOG_EN.md | 5 +++++ src/client/address-base.ts | 12 +++++++++++- tests/worktree-address.spec.ts | 14 ++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7beabaf3..88f0991c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ > 本文档收录 dsh-better-sidebar 的完整发布历史(最新版摘要见 [README](README_ZH.md);同步发布于 [GitHub Releases](https://github.com/omdsh-dev/DSH-better-sidebar/releases))。 +### Unreleased + +- 🪟 **Windows + WSL 工作区:UNC 路径不再被折叠成盘符相对路径**:`resolveAddressPath` 在 Windows 基址下重排分隔符时把每段连续 `\` 折成一个,`\\wsl.localhost\\...` 的 UNC 前缀也因此被折成 `\wsl.localhost\...`;宿主随后用 `path.resolve()` 把它锚定到自己的当前盘(`C:\wsl.localhost\...`),侧边栏打开 WSL 工作区里任何文件都报 `ENOENT`。现在 UNC 前缀原样保留、只折叠其后的部分(盘符路径行为不变)。 + - 🧪 测试:`tests/worktree-address.spec.ts` 新增 1 例(UNC 绝对路径、工作区相对路径、正斜杠写法都保持双前导分隔符)。 + ### v0.29.0 - **侧边对话接入 GenUI**:通过现有 `ctx.betterSidebar` 服务新增可选的 `registerSidechatSurfaceAdapter`,支持 GenUI 0.15.0 渲染已结算的助手回复;未注册消费方时保持原 Markdown。 diff --git a/CHANGELOG_EN.md b/CHANGELOG_EN.md index 094f26ee..28de0796 100644 --- a/CHANGELOG_EN.md +++ b/CHANGELOG_EN.md @@ -4,6 +4,11 @@ > > 📝 The Chinese [CHANGELOG](./CHANGELOG.md) is the authoritative, item-by-item record; this file carries the English summaries and has historically lagged behind it. Where the two disagree, the Chinese one is current. +### Unreleased + +- 🪟 **Windows + WSL workspaces: a UNC path is no longer folded into a drive-relative one.** Re-spelling paths on a Windows base folded every run of separators into one `\`, which also folded the UNC prefix of `\\wsl.localhost\\...` into `\wsl.localhost\...`; the host's `path.resolve()` then anchored that on its own process drive (`C:\wsl.localhost\...`), so every file opened from a WSL workspace failed with ENOENT. The UNC prefix now survives and only the rest is folded (drive paths are unchanged). + - 🧪 `tests/worktree-address.spec.ts` adds one case: UNC absolute, workspace-relative, and forward-slash spellings all keep the two leading separators. + ### v0.29.0 - **GenUI in side chats**: the existing `ctx.betterSidebar` service exposes the opt-in `registerSidechatSurfaceAdapter` for GenUI 0.15.0 to render settled assistant replies. Without a consumer, Markdown rendering stays unchanged. diff --git a/src/client/address-base.ts b/src/client/address-base.ts index e88d2c0b..8cc6c536 100644 --- a/src/client/address-base.ts +++ b/src/client/address-base.ts @@ -57,11 +57,21 @@ export function addressBaseOf(ctx: Context, sessionId: string | undefined): stri * POSIX keeps the path verbatim: there `\` is a legal file-name character, not * a separator (the same reason `resolveSidebarPath` never folds on POSIX). * + * A UNC prefix is NOT a separator run to fold: `\\server\share` is one path + * root, and folding its two leading separators into one turns an absolute + * network path into a drive-root-relative one. On Windows the host then runs + * `path.resolve()` on it, anchoring `\wsl.localhost\...` on the host process + * drive (`C:\wsl.localhost\...`, ENOENT) — every file opened from a + * `\\wsl.localhost\\...` workspace failed that way. Keep exactly the + * two leading separators and fold only the rest. + * * @param base - the workspace root whose separator style decides the answer. * @param path - an address path (relative to `base`) or an absolute path. * @returns the resolved path in `base`'s separator style. */ export function resolveAddressPath(base: string | undefined, path: string): string { const resolved = resolveSidebarPath(base, path) - return base !== undefined && base.includes('\\') ? resolved.replace(/[/\\]+/g, '\\') : resolved + if (base === undefined || !base.includes('\\')) return resolved + const folded = resolved.replace(/[/\\]+/g, '\\') + return /^[\\/]{2}/.test(resolved) ? `\\\\${folded.replace(/^\\+/, '')}` : folded } diff --git a/tests/worktree-address.spec.ts b/tests/worktree-address.spec.ts index 90501da3..2ee33e49 100644 --- a/tests/worktree-address.spec.ts +++ b/tests/worktree-address.spec.ts @@ -180,6 +180,20 @@ describe('address base (worktree sessions)', () => { expect(resolveAddressPath('/repo', 'a\\b.ts')).toBe('/repo/a\\b.ts') }) + it('keeps a UNC prefix when folding separators (Windows + WSL workspace)', () => { + // A UNC root is ONE path root, not a separator run: folding its `\\` into + // `\` left a drive-root-relative path, which the host then re-anchored on + // its process drive with `path.resolve()` (`C:\wsl.localhost\...`), so + // every file opened from a `\\wsl.localhost\\...` workspace failed + // with ENOENT. The prefix must survive, only the body is re-spelled. + const root = '\\\\wsl.localhost\\Ubuntu\\home\\me\\repo' + const file = '\\\\wsl.localhost\\Ubuntu\\home\\me\\repo\\src\\a.ts' + expect(resolveAddressPath(root, file)).toBe(file) + expect(resolveAddressPath(root, 'src/a.ts')).toBe(file) + // A forward-slash UNC spelling folds to the base style, prefix intact. + expect(resolveAddressPath(root, '//wsl.localhost/Ubuntu/home/me/repo/src/a.ts')).toBe(file) + }) + it('builds every plugin address on the session base, never on the caller root', () => { const fixture = makeFixture() try {