authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-09-05 22:13:24-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-09-05 22:13:24-07:00
log0c200c5f83c039f85da0cb1b8d1611db3e708c92
treef3c14d9e24618cbc723ce8d1222f7733c080fb5b
parent181e45110f2d14950a5c1ec415faf3a049cb9b2e
signature Signed by PGP key B5690EEEBB952194

test(desktop): cover WSL paths through public behavior (#10289)


2 files changed, 5 insertions(+), 34 deletions(-)

apps/desktop/src/wsl/wslPathParsing.test.ts+3-29
...@@ -1,11 +1,9 @@...@@ -1,11 +1,9 @@
1import { describe, it, expect } from "vite-plus/test";1import { describe, it, expect } from "vite-plus/test";
22
3import {3import {
4 DISTRO_NAME_PATTERN,
5 extractDistroFromUncPath,4 extractDistroFromUncPath,
6 isValidDistroName,5 isValidDistroName,
7 parseWslDistroList,6 parseWslDistroList,
8 resolveWslHomeUncPath,
9 resolveWslPickFolderDefaultPath,7 resolveWslPickFolderDefaultPath,
10 wslUncPathToLinuxPath,8 wslUncPathToLinuxPath,
11} from "./wslPathParsing.ts";9} from "./wslPathParsing.ts";
...@@ -116,29 +114,6 @@ describe("wslUncPathToLinuxPath", () => {...@@ -116,29 +114,6 @@ describe("wslUncPathToLinuxPath", () => {
116 });114 });
117});115});
118116
119describe("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
142describe("resolveWslPickFolderDefaultPath", () => {117describe("resolveWslPickFolderDefaultPath", () => {
143 const config = { distro: null };118 const config = { distro: null };
144 const distros = [{ name: "Debian", isDefault: true, version: 2 as const }];119 const distros = [{ name: "Debian", isDefault: true, version: 2 as const }];
...@@ -184,23 +159,22 @@ describe("resolveWslPickFolderDefaultPath", () => {...@@ -184,23 +159,22 @@ describe("resolveWslPickFolderDefaultPath", () => {
184 });159 });
185});160});
186161
187describe("DISTRO_NAME_PATTERN / isValidDistroName", () => {162describe("isValidDistroName", () => {
188 it("accepts common distro names", () => {163 it("accepts common distro names", () => {
189 for (const name of ["Ubuntu", "Ubuntu-22.04", "kali-linux", "Debian", "Ubuntu 22.04"]) {164 for (const name of ["Ubuntu", "Ubuntu-22.04", "kali-linux", "Debian", "Ubuntu 22.04"]) {
190 expect(DISTRO_NAME_PATTERN.test(name)).toBe(true);
191 expect(isValidDistroName(name)).toBe(true);165 expect(isValidDistroName(name)).toBe(true);
192 }166 }
193 });167 });
194168
195 it("rejects names with trailing whitespace, hyphen, or dot", () => {169 it("rejects names with trailing whitespace, hyphen, or dot", () => {
196 for (const name of ["Ubuntu ", "Ubuntu-", "Ubuntu."]) {170 for (const name of ["Ubuntu ", "Ubuntu-", "Ubuntu."]) {
197 expect(DISTRO_NAME_PATTERN.test(name)).toBe(false);171 expect(isValidDistroName(name)).toBe(false);
198 }172 }
199 });173 });
200174
201 it("rejects names containing control or shell-meta characters", () => {175 it("rejects names containing control or shell-meta characters", () => {
202 for (const name of ["bad\nname", "bad\tname", "bad/name", "bad!name", "bad;name"]) {176 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);
204 }178 }
205 });179 });
206});180});
apps/desktop/src/wsl/wslPathParsing.ts+2-5
...@@ -10,7 +10,7 @@ export interface WslConfig {...@@ -10,7 +10,7 @@ export interface WslConfig {
1010
11// Literal space — \s would also match \n/\t/\r and corrupt UNC paths like \\wsl.localhost\<distro>\...11// Literal space — \s would also match \n/\t/\r and corrupt UNC paths like \\wsl.localhost\<distro>\...
12// Trailing char must also be \w so hand-edited config like "Ubuntu " / "Ubuntu-" / "Ubuntu." rejects.12// Trailing char must also be \w so hand-edited config like "Ubuntu " / "Ubuntu-" / "Ubuntu." rejects.
13export const DISTRO_NAME_PATTERN = /^\w(?:[\w \-.]*\w)?$/;13const DISTRO_NAME_PATTERN = /^\w(?:[\w \-.]*\w)?$/;
1414
15export function parseWslDistroList(stdout: Buffer): readonly WslDistro[] {15export function parseWslDistroList(stdout: Buffer): readonly WslDistro[] {
16 const hasUtf16Bom = stdout.length >= 2 && stdout[0] === 0xff && stdout[1] === 0xfe;16 const hasUtf16Bom = stdout.length >= 2 && stdout[0] === 0xff && stdout[1] === 0xfe;
...@@ -61,10 +61,7 @@ export function wslUncPathToLinuxPath(windowsPath: string): string | null {...@@ -61,10 +61,7 @@ export function wslUncPathToLinuxPath(windowsPath: string): string | null {
61 return `/${rest.split("\\").filter(Boolean).join("/")}`;61 return `/${rest.split("\\").filter(Boolean).join("/")}`;
62}62}
6363
64export function resolveWslHomeUncPath(64function resolveWslHomeUncPath(config: WslConfig, distros: readonly WslDistro[]): string | null {
65 config: WslConfig,
66 distros: readonly WslDistro[],
67): string | null {
68 const distroName = config.distro ?? distros.find((distro) => distro.isDefault)?.name ?? null;65 const distroName = config.distro ?? distros.find((distro) => distro.isDefault)?.name ?? null;
69 return distroName ? `\\\\wsl.localhost\\${distroName}\\home` : null;66 return distroName ? `\\\\wsl.localhost\\${distroName}\\home` : null;
70}67}