Skip to content

Commit 4db907d

Browse files
test(desktop): reproduce #8297, WSL runtime install fails without automounted drives
These tests reproduce #8297: in a distro with `[automount] enabled=false`, `wslpath -u` cannot translate the runtime archive's Windows path, and prepareRuntime gives up instead of delivering the archive into the distro. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 354f6c8 commit 4db907d

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

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

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
// @effect-diagnostics nodeBuiltinImport:off - the executed suite runs the generated install script through a real POSIX shell.
2+
import * as NodeServices from "@effect/platform-node/NodeServices";
23
import { describe, it } from "@effect/vitest";
4+
import * as Effect from "effect/Effect";
5+
import * as Layer from "effect/Layer";
6+
import * as Path from "effect/Path";
7+
import { ChildProcess, ChildProcessSpawner } from "effect/process";
38
import { afterAll, expect } from "vite-plus/test";
49
import * as NodeChildProcess from "node:child_process";
510

11+
import * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
612
import {
13+
DesktopWslEnvironment,
14+
layer as layerDesktopWslEnvironment,
715
buildWslRuntimeInstallScript,
816
buildWslRuntimeInvalidateScript,
917
buildWslRuntimePruneScript,
@@ -372,6 +380,90 @@ describe.skipIf(posixShellRunner === null)("WSL runtime install script (executed
372380
expect(selected.status, `${selected.stdout}\n${selected.stderr}`).toBe(0);
373381
});
374382

383+
// Runs the distro side on the local bash, so a Windows dev box using the wsl.exe runner skips it.
384+
describe.skipIf(posixShellRunner?.file !== "bash")("prepareRuntime through wsl.exe", () => {
385+
// Emulates `wsl.exe [-d <distro>] [--cd <dir>] [--|--exec] <argv>` in a distro with automount off.
386+
const layerFakeWslExe = (home: string) =>
387+
Layer.effect(
388+
ChildProcessSpawner.ChildProcessSpawner,
389+
Effect.map(ChildProcessSpawner.ChildProcessSpawner, (local) =>
390+
ChildProcessSpawner.make((command) => {
391+
if (!ChildProcess.isStandardCommand(command) || command.command !== "wsl.exe") {
392+
return local.spawn(command);
393+
}
394+
const args = [...command.args];
395+
while (args.length > 0) {
396+
const flag = args[0];
397+
if (flag === "-d" || flag === "--distribution" || flag === "--cd") {
398+
args.splice(0, 2);
399+
} else if (flag === "--" || flag === "--exec" || flag === "-e") {
400+
args.shift();
401+
break;
402+
} else {
403+
break;
404+
}
405+
}
406+
const [file = "sh", ...rest] =
407+
args[0] === "wslpath"
408+
? [
409+
"sh",
410+
"-c",
411+
'printf "wslpath: %s\\n" "$1" >&2; exit 1',
412+
"wslpath",
413+
args.at(-1) ?? "",
414+
]
415+
: args;
416+
return local.spawn(
417+
ChildProcess.make(file, rest, {
418+
...command.options,
419+
env: { ...command.options.env, HOME: home },
420+
extendEnv: true,
421+
}),
422+
);
423+
}),
424+
),
425+
);
426+
427+
const layerWslEnvironment = (home: string) =>
428+
layerDesktopWslEnvironment.pipe(
429+
Layer.provide(
430+
Layer.mergeAll(
431+
layerFakeWslExe(home),
432+
Layer.effect(
433+
DesktopEnvironment.DesktopEnvironment,
434+
Effect.map(
435+
Path.Path,
436+
(path) =>
437+
({ platform: "win32", path }) as DesktopEnvironment.DesktopEnvironment["Service"],
438+
),
439+
),
440+
),
441+
),
442+
Layer.provide(NodeServices.layer),
443+
);
444+
445+
it.live("installs the runtime when wslpath cannot translate the archive's Windows path", () => {
446+
const fixture = createFixture();
447+
return Effect.gen(function* () {
448+
const wsl = yield* DesktopWslEnvironment;
449+
// The archive's Windows path; with no drives mounted, wslpath cannot map it into the distro.
450+
const translated = yield* wsl.windowsToWslPath("Ubuntu", fixture.archivePath);
451+
expect(translated._tag).toBe("None");
452+
453+
const prepared = yield* wsl.prepareRuntime("Ubuntu", {
454+
windowsPath: fixture.archivePath,
455+
runtimeId: fixture.runtimeId,
456+
sha256: fixture.archiveSha,
457+
});
458+
459+
expect(prepared).toEqual({ ok: true, linuxAppRoot: fixture.runtimeRoot });
460+
const version = runShell(`${sh(fixture.serverEntry)} --version`);
461+
expect(version.status, version.stderr).toBe(0);
462+
expect(version.stdout).toBe("t3code wsl runtime test server 0.0.0\n");
463+
}).pipe(Effect.provide(layerWslEnvironment(`${fixture.work}/home`)));
464+
});
465+
});
466+
375467
it("prunes old and markerless caches without touching retained, active, locked, or unrelated roots", () => {
376468
const result = runShell(
377469
[

0 commit comments

Comments
 (0)