@devries-cameron20 / t3code-1 / commits / b4040d9bf3
Fork 0

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

test(desktop): exercise WSL cache safety through public scripts (#10301)

Julius Marminge committed Sep 5, 2026 at 22:30 UTC b4040d9bf38d57cce715c9e602de8de4b0f4a523
2 files changed +16 -48
apps/desktop/src/wsl/DesktopWslEnvironment.test.ts
+12 -43
@@ -12,21 +12,17 @@ import * as TestClock from "effect/testing/TestClock";
12 import { ChildProcessSpawner } from "effect/unstable/process";
13
14 import {
15 - buildWslNodeEnvPreamble,
15 buildWslRuntimeInstallScript,
16 buildWslRuntimeInvalidateScript,
17 buildWslRuntimePruneScript,
18 DesktopWslDistroListError,
19 formatMissingToolsReason,
21 - formatNodePtyProbeFailureReason,
22 - formatWslShellTransportFailureReason,
20 parseNodePath,
21 parseNodeVersion,
22 parseResolvedPath,
23 parseToolchainReport,
24 parseWslRuntimeRoot,
25 probeWslDistros,
29 - sanitizeWslRuntimeId,
26 } from "./DesktopWslEnvironment.ts";
27
28 const encoder = new TextEncoder();
@@ -144,46 +140,19 @@ describe("probeWslDistros", () => {
140 });
141 });
142
147 -describe("formatNodePtyProbeFailureReason", () => {
148 - it("identifies a packaged build that omitted the Linux node-pty prebuild", () => {
149 - const reason = formatNodePtyProbeFailureReason(4);
150 -
151 - expect(reason).toContain("packaged Linux node-pty binary was not included");
152 - expect(reason).toContain("--wsl-prebuild");
153 - });
154 -
155 - it("leaves other node-pty load failures to the compatibility diagnostic", () => {
156 - expect(formatNodePtyProbeFailureReason(1)).toBeNull();
157 - });
158 -});
159 -
160 -describe("formatWslShellTransportFailureReason", () => {
161 - it("distinguishes timeouts and spawn failures from normal shell exit codes", () => {
162 - expect(formatWslShellTransportFailureReason("timeout")).toContain("timed out");
163 - expect(formatWslShellTransportFailureReason("spawn")).toContain("could not start wsl.exe");
164 - expect(formatWslShellTransportFailureReason("process")).toContain("lost communication");
165 - expect(formatWslShellTransportFailureReason(null)).toBeNull();
166 - });
167 -});
168 -
169 -describe("buildWslNodeEnvPreamble", () => {
170 - it("passes the required Node engine range into the shared resolver", () => {
171 - const preamble = buildWslNodeEnvPreamble("^22.16 || ^23.11 || >=24.10");
172 -
173 - expect(preamble).toContain("T3_NODE_ENGINE_RANGE='^22.16 || ^23.11 || >=24.10'");
174 - expect(preamble.indexOf("T3_NODE_ENGINE_RANGE=")).toBeLessThan(
175 - preamble.lastIndexOf("ensure_remote_node_path || true"),
176 - );
177 - });
178 -
179 - it("keeps the shared resolver permissive when no Node engine range is provided", () => {
180 - expect(buildWslNodeEnvPreamble()).toContain("T3_NODE_ENGINE_RANGE=''");
181 - });
182 -});
183 -
143 describe("WSL runtime cache", () => {
185 - it("sanitizes cache ids before interpolating them into Linux paths", () => {
186 - expect(sanitizeWslRuntimeId("1.2.3/x64; touch /tmp/nope")).toBe("1.2.3_x64__touch__tmp_nope");
144 + it.each([
145 + [
146 + "install",
147 + (id: string) => buildWslRuntimeInstallScript("/runtime.tar.gz", id, "b".repeat(64)),
148 + ],
149 + ["prune", buildWslRuntimePruneScript],
150 + ["invalidate", buildWslRuntimeInvalidateScript],
151 + ] as const)("sanitizes cache ids in the %s script", (_, buildScript) => {
152 + const runtimeId = "1.2.3/x64; touch /tmp/nope";
153 + const script = buildScript(runtimeId);
154 + expect(script).toContain("/1.2.3_x64__touch__tmp_nope");
155 + expect(script).not.toContain(runtimeId);
156 });
157
158 it("installs through a temporary directory and only reuses valid completed caches", () => {
apps/desktop/src/wsl/DesktopWslEnvironment.ts
+4 -5
@@ -147,7 +147,7 @@ const TIMEOUT_RESULT: ShellResult = {
147 transportFailure: "timeout",
148 };
149
150 -export const formatWslShellTransportFailureReason = (
150 +const formatWslShellTransportFailureReason = (
151 failure: ShellResult["transportFailure"],
152 ): string | null => {
153 switch (failure) {
@@ -165,7 +165,7 @@ export const formatWslShellTransportFailureReason = (
165 // Reuse the SSH remote resolver so WSL and SSH discover version-managed Node
166 // the same way. Passing the engine range lets the resolver fall through to
167 // version managers like nvm when a system node exists but is too old.
168 -export const buildWslNodeEnvPreamble = (
168 +const buildWslNodeEnvPreamble = (
169 nodeEngineRange?: string | null,
170 ): string => `${buildRemoteNodeEnvScript({ nodeEngineRange: nodeEngineRange ?? null })}
171 ensure_remote_node_path || true
@@ -263,8 +263,7 @@ const WSL_RUNTIME_READY_MARKER = ".t3code-wsl-runtime-ready";
263 const WSL_RUNTIME_SELECTED_MARKER = ".t3code-wsl-runtime-selected";
264 const WSL_RUNTIME_SELECTION_GRACE_MINUTES = 5;
265
266 -export const sanitizeWslRuntimeId = (value: string): string =>
267 - value.replace(/[^A-Za-z0-9._-]/g, "_");
266 +const sanitizeWslRuntimeId = (value: string): string => value.replace(/[^A-Za-z0-9._-]/g, "_");
267
268 // `archiveSha256` is the digest the build recorded alongside the archive. The
269 // install verifies the bytes before extracting, so an archive can never be
@@ -491,7 +490,7 @@ export const parseWslRuntimeRoot = (stdout: string): string | null => {
490
491 const NODE_PTY_PREBUILD_MISSING_EXIT_CODE = 4;
492
494 -export const formatNodePtyProbeFailureReason = (exitCode: number): string | null =>
493 +const formatNodePtyProbeFailureReason = (exitCode: number): string | null =>
494 exitCode === NODE_PTY_PREBUILD_MISSING_EXIT_CODE
495 ? "WSL support is missing from this T3 Code build: the packaged Linux node-pty binary was not included. Rebuild the Windows artifact with `--wsl-prebuild <path-to-linux-pty.node>` or install a build that includes WSL support."
496 : null;