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 @@
11import { describe, it, expect } from "vite-plus/test";
22
33import {
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
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
142117describe("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
187describe("DISTRO_NAME_PATTERN / isValidDistroName", () => {
162describe("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+2-5
......@@ -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.
13export const DISTRO_NAME_PATTERN = /^\w(?:[\w \-.]*\w)?$/;
13const DISTRO_NAME_PATTERN = /^\w(?:[\w \-.]*\w)?$/;
1414
1515export 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
64export function resolveWslHomeUncPath(
65 config: WslConfig,
66 distros: readonly WslDistro[],
67): string | null {
64function 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}