Skip to content

Commit aa7d601

Browse files
committed
fix(desktop): preserve WSL runtime installation errors
1 parent bf3be75 commit aa7d601

4 files changed

Lines changed: 63 additions & 14 deletions

File tree

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,11 +485,16 @@ describe("DesktopBackendConfiguration", () => {
485485

486486
it.effect("resolveWsl falls back to the mounted runtime when archive staging fails", () => {
487487
const observedNodePtyRoots: string[] = [];
488+
const invalidatedRuntimeIds: string[] = [];
488489
return withPackagedWslHarness(
489490
{
490491
archiveHash: "b".repeat(64),
491492
wsl: () => ({
492493
prepareRuntime: () => ({ ok: false, reason: "archive is corrupt" }),
494+
invalidateRuntime: (_distro, runtimeId) =>
495+
Effect.sync(() => {
496+
invalidatedRuntimeIds.push(runtimeId);
497+
}),
493498
ensureNodePty: (_distro, root) => {
494499
observedNodePtyRoots.push(root);
495500
return { ok: true, nodePath: "/usr/bin/node", resolvedPath: "/usr/bin:/bin" };
@@ -502,6 +507,7 @@ describe("DesktopBackendConfiguration", () => {
502507
const config = yield* configuration.resolveWsl({ port: 5000, distro: "Ubuntu" });
503508

504509
assert.deepEqual(observedNodePtyRoots, [mountedAppRoot]);
510+
assert.deepEqual(invalidatedRuntimeIds, []);
505511
assert.equal(config.entryPath, mountedEntryPath);
506512
assert.include(config.args, "/usr/bin/node");
507513
assert.include(config.args, `${mountedAppRoot}/apps/server/dist/bin.mjs`);
@@ -554,6 +560,39 @@ describe("DesktopBackendConfiguration", () => {
554560
);
555561
});
556562

563+
it.effect(
564+
"resolveWsl preserves the installation error when the fallback lacks Linux binaries",
565+
() => {
566+
return withPackagedWslHarness(
567+
{
568+
archiveHash: "b".repeat(64),
569+
wsl: () => ({
570+
prepareRuntime: () => ({
571+
ok: false,
572+
reason:
573+
"t3: error while loading shared libraries: libatomic.so.1: cannot open shared object file",
574+
}),
575+
ensureNodePty: () => ({
576+
ok: false,
577+
reason: "the packaged Linux node-pty binary was not included",
578+
fatal: true,
579+
}),
580+
}),
581+
},
582+
() =>
583+
Effect.gen(function* () {
584+
const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
585+
const config = yield* configuration.resolveWsl({ port: 5000, distro: "Ubuntu" });
586+
const failure = Option.getOrThrow(config.preflightFailure);
587+
588+
assert.isTrue(failure.fatal);
589+
assert.include(failure.reason, "libatomic.so.1");
590+
assert.notInclude(failure.reason, "node-pty");
591+
}),
592+
);
593+
},
594+
);
595+
557596
it.effect("resolveWsl keeps the staged runtime when the mounted tree fails too", () => {
558597
const stagedAppRoot = "/home/test/.t3/wsl-runtime/cache";
559598
const invalidatedRuntimeIds: string[] = [];

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,10 @@ const runWslPreflight = Effect.fn("desktop.backendConfiguration.wslPreflight")(f
372372
: ({ ok: true, windowsEntryPath, linuxAppRoot: mountedAppRoot.value } as const);
373373
});
374374

375-
// Set once a staged runtime has been ruled out by the probe, and carried
376-
// through the mounted attempt: if the mounted tree works the cache is the
377-
// broken part and gets invalidated, and if the mounted tree returns its own
378-
// fatal verdict the cached reason is the more actionable one to report.
379-
// A transient mounted failure is neither — it rules nothing out, so it stays
380-
// retryable and the staged verdict waits for an attempt that can answer.
381-
let stagedFailure: { readonly runtimeId: string; readonly reason: string } | undefined;
375+
// Preserve the archive's failure if the mounted fallback also fails. Only
376+
// a runtime that was installed and then failed its probe can be invalidated
377+
// after a successful fallback; installation failures carry no cache id.
378+
let stagedFailure: { readonly runtimeId?: string; readonly reason: string } | undefined;
382379
const failedStaged = (failure: { readonly reason: string }) =>
383380
({
384381
_tag: "Failed",
@@ -409,6 +406,7 @@ const runWslPreflight = Effect.fn("desktop.backendConfiguration.wslPreflight")(f
409406
);
410407
stagedFailure = { runtimeId: input.runtimeArchive.runtimeId, reason: stagedProbe.reason };
411408
} else {
409+
stagedFailure = { reason: runtime.reason };
412410
yield* Effect.logWarning(
413411
"Could not stage the WSL runtime; launching from the mounted server tree instead.",
414412
{ reason: runtime.reason },
@@ -441,7 +439,7 @@ const runWslPreflight = Effect.fn("desktop.backendConfiguration.wslPreflight")(f
441439
// The mounted tree runs what the cache could not, so the cache is the broken
442440
// copy: revoke its ready marker so the next launch reinstalls it instead of
443441
// reusing a tree that has already been proven unloadable.
444-
if (stagedFailure) {
442+
if (stagedFailure?.runtimeId) {
445443
yield* wslEnv.invalidateRuntime(runningDistro, stagedFailure.runtimeId);
446444
}
447445

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

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

168168
expect(script).toContain('runtime_parent="$HOME/.t3/wsl-runtime"');
169169
expect(script).toContain(' [ -f "$ready_marker" ] &&');
170-
expect(script).toContain(' runtime_entry_runs "$runtime_root" &&');
170+
expect(script).toContain(' runtime_entry_runs "$runtime_root" 2>/dev/null &&');
171171
expect(script).toContain("if runtime_is_ready; then");
172172
expect(script).not.toContain("bin.mjs");
173173
expect(script).not.toContain("node-pty");
@@ -262,7 +262,7 @@ describe("WSL runtime cache", () => {
262262
// The same proof the SSH runner and CLI installers use: executable, and
263263
// `--version` exits 0. That is what decides arch and loadability, so no
264264
// separate native probe is needed.
265-
expect(script).toContain(' [ -x "$1/t3" ] && "$1/t3" --version >/dev/null 2>&1');
265+
expect(script).toContain(' [ -x "$1/t3" ] && "$1/t3" --version >/dev/null');
266266

267267
// Readiness gates the short-circuit, so a cache whose executable broke
268268
// reinstalls from the archive instead of being reused forever.
@@ -402,7 +402,7 @@ describe.skipIf(posixShellRunner === null)("WSL runtime install script (executed
402402
fixtures.length = 0;
403403
});
404404

405-
const createFixture = () => {
405+
const createFixture = (serverEntry = SERVER_ENTRY_SOURCE) => {
406406
const result = runShell(
407407
[
408408
"set -eu",
@@ -411,7 +411,7 @@ describe.skipIf(posixShellRunner === null)("WSL runtime install script (executed
411411
// holds the executable and its native addons.
412412
'stage="$work/stage/t3-0.0.0-linux-x64"',
413413
'mkdir -p "$stage/node_modules/node-pty/build/Release" "$work/home"',
414-
`printf '%s' ${sh(SERVER_ENTRY_SOURCE)} > "$stage/t3"`,
414+
`printf '%s' ${sh(serverEntry)} > "$stage/t3"`,
415415
'chmod +x "$stage/t3"',
416416
`printf '%s' 'pty-native-payload' > "$stage/node_modules/node-pty/build/Release/pty.node"`,
417417
`tar -czf "$work/wsl-runtime.tar.gz" -C "$work/stage" t3-0.0.0-linux-x64`,
@@ -529,6 +529,18 @@ describe.skipIf(posixShellRunner === null)("WSL runtime install script (executed
529529
expect(parseWslRuntimeRoot(warm.stdout)).toBe(fixture.runtimeRoot);
530530
});
531531

532+
it("retains the loader error when a bundled executable needs a missing system library", () => {
533+
const fixture = createFixture(
534+
'#!/bin/sh\nprintf "error while loading shared libraries: libatomic.so.1: cannot open shared object file\\n" >&2\nexit 127\n',
535+
);
536+
537+
const result = fixture.install();
538+
539+
expect(result.status).not.toBe(0);
540+
expect(result.stderr).toContain("libatomic.so.1");
541+
expect(parseWslRuntimeRoot(result.stdout)).toBeNull();
542+
});
543+
532544
it("reinstalls a cache whose executable was truncated", () => {
533545
const fixture = createFixture();
534546
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
@@ -305,7 +305,7 @@ export const buildWslRuntimeInstallScript = (
305305
// use: the file is executable and `t3 --version` exits 0. That covers the
306306
// truncated-binary and wrong-arch cases without a separate native probe.
307307
"runtime_entry_runs() {",
308-
' [ -x "$1/t3" ] && "$1/t3" --version >/dev/null 2>&1',
308+
' [ -x "$1/t3" ] && "$1/t3" --version >/dev/null',
309309
"}",
310310
// Hashing the entry is what tells a working cache from one whose `t3` was
311311
// swapped or half-written after install: the file is still there and may
@@ -318,7 +318,7 @@ export const buildWslRuntimeInstallScript = (
318318
"}",
319319
"runtime_is_ready() {",
320320
' [ -f "$ready_marker" ] &&',
321-
' runtime_entry_runs "$runtime_root" &&',
321+
' runtime_entry_runs "$runtime_root" 2>/dev/null &&',
322322
// An empty or unreadable marker is a miss, not a pass: that is what a
323323
// runtime installed before the marker carried a digest looks like, and one
324324
// reinstall is the cheapest way to make it verifiable from then on.

0 commit comments

Comments
 (0)