|
1 | 1 | // @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"; |
2 | 3 | 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"; |
3 | 8 | import { afterAll, expect } from "vite-plus/test"; |
4 | 9 | import * as NodeChildProcess from "node:child_process"; |
5 | 10 |
|
| 11 | +import * as DesktopEnvironment from "../app/DesktopEnvironment.ts"; |
6 | 12 | import { |
| 13 | + DesktopWslEnvironment, |
| 14 | + layer as layerDesktopWslEnvironment, |
7 | 15 | buildWslRuntimeInstallScript, |
8 | 16 | buildWslRuntimeInvalidateScript, |
9 | 17 | buildWslRuntimePruneScript, |
@@ -372,6 +380,90 @@ describe.skipIf(posixShellRunner === null)("WSL runtime install script (executed |
372 | 380 | expect(selected.status, `${selected.stdout}\n${selected.stderr}`).toBe(0); |
373 | 381 | }); |
374 | 382 |
|
| 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 | + |
375 | 467 | it("prunes old and markerless caches without touching retained, active, locked, or unrelated roots", () => { |
376 | 468 | const result = runShell( |
377 | 469 | [ |
|
0 commit comments