mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-23 16:36:23 +00:00
When the desktop UI runs on Windows and the gateway runs in WSL, a WSL/POSIX cwd isn't openable/readable from the Windows host. Add wsl-path-bridge.ts to translate the Windows-side direction only: - native folder dialog defaultPath: `/home/...` → `\\wsl.localhost\<distro>\...` - fs read path: WSL cwd → its UNC / `C:\` drive form Distro detection reads `wsl.exe -l -q` with `WSL_UTF8=1` and strips stray NUL bytes, since older wsl.exe emits UTF-16LE (microsoft/WSL#4607) — the original utf8 read returned a garbled distro name. UNC uses `\\wsl.localhost\` with a `\\wsl$\` fallback for older Windows. The reverse (any path → POSIX) is handled once gateway-side, so the picker result needs no desktop translation. Co-authored-by: Rage Lopez <VrtxOmega@pm.me>
40 lines
2 KiB
TypeScript
40 lines
2 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
|
|
import { parseDefaultDistro, resolvePickerDefaultPath, wslPosixToWindowsAccessible } from './wsl-path-bridge'
|
|
|
|
test('parseDefaultDistro reads the first distro from clean utf-8 output', () => {
|
|
assert.equal(parseDefaultDistro('Ubuntu\nDebian\n'), 'Ubuntu')
|
|
})
|
|
|
|
test('parseDefaultDistro survives UTF-16LE NUL bytes older wsl.exe leaves in (WSL#4607)', () => {
|
|
// `wsl.exe -l -q` emits UTF-16LE without a BOM on builds that ignore
|
|
// WSL_UTF8; decoded as utf8 that reads as NUL-interleaved text.
|
|
const utf16ish = '\0U\0b\0u\0n\0t\0u\0\r\0\n\0D\0e\0b\0i\0a\0n\0'
|
|
assert.equal(parseDefaultDistro(utf16ish), 'Ubuntu')
|
|
})
|
|
|
|
test('parseDefaultDistro strips the default-marker and blank lines', () => {
|
|
assert.equal(parseDefaultDistro('\n* Ubuntu\nDebian\n'), 'Ubuntu')
|
|
assert.equal(parseDefaultDistro(' \n\n'), null)
|
|
})
|
|
|
|
test('wslPosixToWindowsAccessible maps a drvfs mount to its Windows drive', () => {
|
|
assert.equal(wslPosixToWindowsAccessible('/mnt/c/Users/alex', 'Ubuntu'), 'C:\\Users\\alex')
|
|
assert.equal(wslPosixToWindowsAccessible('/mnt/d', 'Ubuntu'), 'D:\\')
|
|
})
|
|
|
|
test('wslPosixToWindowsAccessible maps an in-distro POSIX path to a UNC share', () => {
|
|
assert.equal(wslPosixToWindowsAccessible('/home/alex/proj', 'Ubuntu'), '\\\\wsl.localhost\\Ubuntu\\home\\alex\\proj')
|
|
})
|
|
|
|
test('wslPosixToWindowsAccessible leaves non-absolute / already-Windows paths alone', () => {
|
|
assert.equal(wslPosixToWindowsAccessible('C:\\Users\\alex', 'Ubuntu'), 'C:\\Users\\alex')
|
|
assert.equal(wslPosixToWindowsAccessible('relative/dir', 'Ubuntu'), 'relative/dir')
|
|
})
|
|
|
|
test('resolvePickerDefaultPath bridges a WSL cwd but passes Windows paths and empties through', () => {
|
|
assert.equal(resolvePickerDefaultPath('/home/alex', 'Ubuntu'), '\\\\wsl.localhost\\Ubuntu\\home\\alex')
|
|
assert.equal(resolvePickerDefaultPath('C:\\proj', 'Ubuntu'), 'C:\\proj')
|
|
assert.equal(resolvePickerDefaultPath(undefined, 'Ubuntu'), undefined)
|
|
})
|