@devries-cameron20 / t3code Mirror · read-only / commits / 0c200c5f83
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 24, 09:00 UTC

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

Julius Marminge committed Sep 5, 2026 at 22:13 UTC 0c200c5f83c039f85da0cb1b8d1611db3e708c92
2 files changed +5 -34
apps/desktop/src/wsl/wslPathParsing.test.ts
+3 -29
@@ -1,11 +1,9 @@
1 import { describe, it, expect } from "vite-plus/test";
2
3 import {
4 - DISTRO_NAME_PATTERN,
4 extractDistroFromUncPath,
5 isValidDistroName,
6 parseWslDistroList,
8 - resolveWslHomeUncPath,
7 resolveWslPickFolderDefaultPath,
8 wslUncPathToLinuxPath,
9 } from "./wslPathParsing.ts";
@@ -116,29 +114,6 @@ describe("wslUncPathToLinuxPath", () => {
114 });
115 });
116
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 -
117 describe("resolveWslPickFolderDefaultPath", () => {
118 const config = { distro: null };
119 const distros = [{ name: "Debian", isDefault: true, version: 2 as const }];
@@ -184,23 +159,22 @@ describe("resolveWslPickFolderDefaultPath", () => {
159 });
160 });
161
187 -describe("DISTRO_NAME_PATTERN / isValidDistroName", () => {
162 +describe("isValidDistroName", () => {
163 it("accepts common distro names", () => {
164 for (const name of ["Ubuntu", "Ubuntu-22.04", "kali-linux", "Debian", "Ubuntu 22.04"]) {
190 - expect(DISTRO_NAME_PATTERN.test(name)).toBe(true);
165 expect(isValidDistroName(name)).toBe(true);
166 }
167 });
168
169 it("rejects names with trailing whitespace, hyphen, or dot", () => {
170 for (const name of ["Ubuntu ", "Ubuntu-", "Ubuntu."]) {
197 - expect(DISTRO_NAME_PATTERN.test(name)).toBe(false);
171 + expect(isValidDistroName(name)).toBe(false);
172 }
173 });
174
175 it("rejects names containing control or shell-meta characters", () => {
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);
178 }
179 });
180 });
apps/desktop/src/wsl/wslPathParsing.ts
+2 -5
@@ -10,7 +10,7 @@ export interface WslConfig {
10
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.
13 -export const DISTRO_NAME_PATTERN = /^\w(?:[\w \-.]*\w)?$/;
13 +const DISTRO_NAME_PATTERN = /^\w(?:[\w \-.]*\w)?$/;
14
15 export function parseWslDistroList(stdout: Buffer): readonly WslDistro[] {
16 const hasUtf16Bom = stdout.length >= 2 && stdout[0] === 0xff && stdout[1] === 0xfe;
@@ -61,10 +61,7 @@ export function wslUncPathToLinuxPath(windowsPath: string): string | null {
61 return `/${rest.split("\\").filter(Boolean).join("/")}`;
62 }
63
64 -export function resolveWslHomeUncPath(
65 - config: WslConfig,
66 - distros: readonly WslDistro[],
67 -): string | null {
64 +function resolveWslHomeUncPath(config: WslConfig, distros: readonly WslDistro[]): string | null {
65 const distroName = config.distro ?? distros.find((distro) => distro.isDefault)?.name ?? null;
66 return distroName ? `\\\\wsl.localhost\\${distroName}\\home` : null;
67 }