Skip to content

Commit 1a552d1

Browse files
fix(desktop): preserve WSL runtime installation errors (pingdotgg#21658)
Co-authored-by: Kalven Schraut <[email protected]>
1 parent d6cd7b3 commit 1a552d1

4 files changed

Lines changed: 51 additions & 8 deletions

File tree

‎apps/desktop/src/backend/DesktopBackendConfiguration.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ describe("DesktopBackendConfiguration", () => {
551551
archiveHash: "b".repeat(64),
552552
wsl: () => ({
553553
prepareRuntime: () => ({ ok: false, reason: "archive is corrupt" }),
554+
invalidateRuntime: () => Effect.die("failed staging must not invalidate a runtime"),
554555
ensureNodePty: (_distro, root) => {
555556
observedNodePtyRoots.push(root);
556557
return { ok: true, nodePath: "/usr/bin/node", resolvedPath: "/usr/bin:/bin" };
@@ -615,6 +616,35 @@ describe("DesktopBackendConfiguration", () => {
615616
);
616617
});
617618

619+
it.effect("resolveWsl preserves the staging error when the mounted fallback is fatal", () =>
620+
withPackagedWslHarness(
621+
{
622+
archiveHash: "b".repeat(64),
623+
wsl: () => ({
624+
prepareRuntime: () => ({
625+
ok: false,
626+
reason:
627+
"t3: error while loading shared libraries: libatomic.so.1: cannot open shared object file",
628+
}),
629+
ensureNodePty: () => ({
630+
ok: false,
631+
reason: "the packaged Linux node-pty binary was not included",
632+
fatal: true,
633+
}),
634+
}),
635+
},
636+
() =>
637+
Effect.gen(function* () {
638+
const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
639+
const config = yield* configuration.resolveWsl({ port: 5000, distro: "Ubuntu" });
640+
const failure = Option.getOrThrow(config.preflightFailure);
641+
642+
assert.isTrue(failure.fatal);
643+
assert.include(failure.reason, "libatomic.so.1");
644+
}),
645+
),
646+
);
647+
618648
it.effect("resolveWsl keeps the staged runtime when the mounted tree fails too", () => {
619649
const stagedAppRoot = "/home/test/.t3/wsl-runtime/cache";
620650
const invalidatedRuntimeIds: string[] = [];

‎apps/desktop/src/backend/DesktopBackendConfiguration.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ const runWslPreflight = Effect.fn("desktop.backendConfiguration.wslPreflight")(f
386386
: ({ ok: true, windowsEntryPath, linuxAppRoot: mountedAppRoot.value } as const);
387387
});
388388

389-
let stagedFailure: { readonly runtimeId: string; readonly reason: string } | undefined;
389+
let stagedFailure: { readonly runtimeId?: string; readonly reason: string } | undefined;
390390
const failedStaged = (failure: { readonly reason: string }) =>
391391
({
392392
_tag: "Failed",
@@ -417,6 +417,7 @@ const runWslPreflight = Effect.fn("desktop.backendConfiguration.wslPreflight")(f
417417
);
418418
stagedFailure = { runtimeId: input.runtimeArchive.runtimeId, reason: stagedProbe.reason };
419419
} else {
420+
stagedFailure = { reason: runtime.reason };
420421
yield* Effect.logWarning(
421422
"Could not stage the WSL runtime; launching from the mounted server tree instead.",
422423
{ reason: runtime.reason },
@@ -446,7 +447,7 @@ const runWslPreflight = Effect.fn("desktop.backendConfiguration.wslPreflight")(f
446447
: failedNodePty(nodePtyResult);
447448
}
448449

449-
if (stagedFailure) {
450+
if (stagedFailure?.runtimeId) {
450451
yield* wslEnv.invalidateRuntime(runningDistro, stagedFailure.runtimeId);
451452
}
452453

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ describe("WSL runtime cache", () => {
286286

287287
expect(script).toContain('runtime_parent="$HOME/.t3/wsl-runtime"');
288288
expect(script).toContain(' [ -f "$ready_marker" ] &&');
289-
expect(script).toContain(' runtime_entry_runs "$runtime_root" &&');
289+
expect(script).toContain(' runtime_entry_runs "$runtime_root" 2>/dev/null &&');
290290
expect(script).toContain("if runtime_is_ready; then");
291291
expect(script).not.toContain("bin.mjs");
292292
expect(script).not.toContain("node-pty");
@@ -366,7 +366,7 @@ describe("WSL runtime cache", () => {
366366
"b".repeat(64),
367367
);
368368

369-
expect(script).toContain(' [ -x "$1/t3" ] && "$1/t3" --version >/dev/null 2>&1');
369+
expect(script).toContain(' [ -x "$1/t3" ] && "$1/t3" --version >/dev/null');
370370

371371
const entryCheckDefined = script.indexOf("runtime_entry_runs() {");
372372
const readinessDefined = script.indexOf("runtime_is_ready() {");
@@ -478,14 +478,14 @@ describe.skipIf(posixShellRunner === null)("WSL runtime install script (executed
478478
fixtures.length = 0;
479479
});
480480

481-
const createFixture = () => {
481+
const createFixture = (serverEntry = SERVER_ENTRY_SOURCE) => {
482482
const result = runShell(
483483
[
484484
"set -eu",
485485
"work=$(mktemp -d)",
486486
'stage="$work/stage/t3-0.0.0-linux-x64"',
487487
'mkdir -p "$stage/node_modules/node-pty/build/Release" "$work/home"',
488-
`printf '%s' ${sh(SERVER_ENTRY_SOURCE)} > "$stage/t3"`,
488+
`printf '%s' ${sh(serverEntry)} > "$stage/t3"`,
489489
'chmod +x "$stage/t3"',
490490
`printf '%s' 'pty-native-payload' > "$stage/node_modules/node-pty/build/Release/pty.node"`,
491491
`tar -czf "$work/wsl-runtime.tar.gz" -C "$work/stage" t3-0.0.0-linux-x64`,
@@ -599,6 +599,18 @@ describe.skipIf(posixShellRunner === null)("WSL runtime install script (executed
599599
expect(parseWslRuntimeRoot(warm.stdout)).toBe(fixture.runtimeRoot);
600600
});
601601

602+
it("retains the loader error when a bundled executable needs a missing system library", () => {
603+
const fixture = createFixture(
604+
'#!/bin/sh\nprintf "error while loading shared libraries: libatomic.so.1: cannot open shared object file\\n" >&2\nexit 127\n',
605+
);
606+
607+
const result = fixture.install();
608+
609+
expect(result.status).not.toBe(0);
610+
expect(result.stderr).toContain("libatomic.so.1");
611+
expect(parseWslRuntimeRoot(result.stdout)).toBeNull();
612+
});
613+
602614
it("reinstalls a cache whose executable was truncated", () => {
603615
const fixture = createFixture();
604616
expect(fixture.install().status).toBe(0);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ export const buildWslRuntimeInstallScript = (
275275
`runtime_root="$runtime_parent/${safeRuntimeId}"`,
276276
`ready_marker="$runtime_root/${WSL_RUNTIME_READY_MARKER}"`,
277277
"runtime_entry_runs() {",
278-
' [ -x "$1/t3" ] && "$1/t3" --version >/dev/null 2>&1',
278+
' [ -x "$1/t3" ] && "$1/t3" --version >/dev/null',
279279
"}",
280280
// Hashing the entry is what tells a working cache from one whose `t3` was
281281
// swapped or half-written after install: the file is still there and may
@@ -286,7 +286,7 @@ export const buildWslRuntimeInstallScript = (
286286
"}",
287287
"runtime_is_ready() {",
288288
' [ -f "$ready_marker" ] &&',
289-
' runtime_entry_runs "$runtime_root" &&',
289+
' runtime_entry_runs "$runtime_root" 2>/dev/null &&',
290290
` recorded_entry_digest=$(tr -d '[:space:]' < "$ready_marker" 2>/dev/null) &&`,
291291
' [ -n "$recorded_entry_digest" ] &&',
292292
' [ "$recorded_entry_digest" = "$(runtime_server_entry_digest "$runtime_root")" ]',

0 commit comments

Comments
 (0)