Skip to content

Commit 2e7cd38

Browse files
test(desktop): cover WSL paths through public behavior
1 parent ab67795 commit 2e7cd38

2 files changed

Lines changed: 5 additions & 34 deletions

File tree

‎apps/desktop/src/wsl/wslPathParsing.test.ts‎

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { describe, it, expect } from "vite-plus/test";
22

33
import {
4-
DISTRO_NAME_PATTERN,
54
extractDistroFromUncPath,
65
isValidDistroName,
76
parseWslDistroList,
8-
resolveWslHomeUncPath,
97
resolveWslPickFolderDefaultPath,
108
wslUncPathToLinuxPath,
119
} from "./wslPathParsing.ts";
@@ -116,29 +114,6 @@ describe("wslUncPathToLinuxPath", () => {
116114
});
117115
});
118116

119-
describe("resolveWslHomeUncPath", () => {
120-
const distros = [
121-
{ name: "Debian", isDefault: true, version: 2 as const },
122-
{ name: "Ubuntu", isDefault: false, version: 2 as const },
123-
];
124-
125-
it("uses the configured distro when one is selected", () => {
126-
expect(resolveWslHomeUncPath({ distro: "Ubuntu" }, distros)).toBe(
127-
"\\\\wsl.localhost\\Ubuntu\\home",
128-
);
129-
});
130-
131-
it("uses the actual default distro when config uses the WSL default", () => {
132-
expect(resolveWslHomeUncPath({ distro: null }, distros)).toBe(
133-
"\\\\wsl.localhost\\Debian\\home",
134-
);
135-
});
136-
137-
it("omits the default path when no default distro is known", () => {
138-
expect(resolveWslHomeUncPath({ distro: null }, [])).toBeNull();
139-
});
140-
});
141-
142117
describe("resolveWslPickFolderDefaultPath", () => {
143118
const config = { distro: null };
144119
const distros = [{ name: "Debian", isDefault: true, version: 2 as const }];
@@ -184,23 +159,22 @@ describe("resolveWslPickFolderDefaultPath", () => {
184159
});
185160
});
186161

187-
describe("DISTRO_NAME_PATTERN / isValidDistroName", () => {
162+
describe("isValidDistroName", () => {
188163
it("accepts common distro names", () => {
189164
for (const name of ["Ubuntu", "Ubuntu-22.04", "kali-linux", "Debian", "Ubuntu 22.04"]) {
190-
expect(DISTRO_NAME_PATTERN.test(name)).toBe(true);
191165
expect(isValidDistroName(name)).toBe(true);
192166
}
193167
});
194168

195169
it("rejects names with trailing whitespace, hyphen, or dot", () => {
196170
for (const name of ["Ubuntu ", "Ubuntu-", "Ubuntu."]) {
197-
expect(DISTRO_NAME_PATTERN.test(name)).toBe(false);
171+
expect(isValidDistroName(name)).toBe(false);
198172
}
199173
});
200174

201175
it("rejects names containing control or shell-meta characters", () => {
202176
for (const name of ["bad\nname", "bad\tname", "bad/name", "bad!name", "bad;name"]) {
203-
expect(DISTRO_NAME_PATTERN.test(name)).toBe(false);
177+
expect(isValidDistroName(name)).toBe(false);
204178
}
205179
});
206180
});

‎apps/desktop/src/wsl/wslPathParsing.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface WslConfig {
1010

1111
// Literal space — \s would also match \n/\t/\r and corrupt UNC paths like \\wsl.localhost\<distro>\...
1212
// Trailing char must also be \w so hand-edited config like "Ubuntu " / "Ubuntu-" / "Ubuntu." rejects.
13-
export const DISTRO_NAME_PATTERN = /^\w(?:[\w \-.]*\w)?$/;
13+
const DISTRO_NAME_PATTERN = /^\w(?:[\w \-.]*\w)?$/;
1414

1515
export function parseWslDistroList(stdout: Buffer): readonly WslDistro[] {
1616
const hasUtf16Bom = stdout.length >= 2 && stdout[0] === 0xff && stdout[1] === 0xfe;
@@ -61,10 +61,7 @@ export function wslUncPathToLinuxPath(windowsPath: string): string | null {
6161
return `/${rest.split("\\").filter(Boolean).join("/")}`;
6262
}
6363

64-
export function resolveWslHomeUncPath(
65-
config: WslConfig,
66-
distros: readonly WslDistro[],
67-
): string | null {
64+
function resolveWslHomeUncPath(config: WslConfig, distros: readonly WslDistro[]): string | null {
6865
const distroName = config.distro ?? distros.find((distro) => distro.isDefault)?.name ?? null;
6966
return distroName ? `\\\\wsl.localhost\\${distroName}\\home` : null;
7067
}

0 commit comments

Comments
 (0)