merge: keep the UNC prefix when folding separators (#1079)

This commit is contained in:
Menghuan1918 committed 2026-10-29 23:36:41 +08:00
commit e17ab5c52e
4 files changed
+35 -1

No files matched your search

+5
View File
@@ -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\<distro>\...` 的 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。
+5
View File
@@ -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\<distro>\...` 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.
+11 -1
View File
@@ -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\<distro>\...` 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
}
+14
View File
@@ -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\<distro>\...` 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 {