Skip to content
TypeScript

fix(desktop): preserve WSL runtime installation errors (#21658)

Julius Marminge1a552d16a254
diff --git a/apps/desktop/src/backend/DesktopBackendConfiguration.test.ts b/apps/desktop/src/backend/DesktopBackendConfiguration.test.ts
index c0ef57ae993..ec92473d80a 100644
--- a/apps/desktop/src/backend/DesktopBackendConfiguration.test.ts
+++ b/apps/desktop/src/backend/DesktopBackendConfiguration.test.ts
@@ -551,6 +551,7 @@ describe("DesktopBackendConfiguration", () => {
archiveHash: "b".repeat(64),
wsl: () => ({
prepareRuntime: () => ({ ok: false, reason: "archive is corrupt" }),
+ invalidateRuntime: () => Effect.die("failed staging must not invalidate a runtime"),
ensureNodePty: (_distro, root) => {
observedNodePtyRoots.push(root);
return { ok: true, nodePath: "/usr/bin/node", resolvedPath: "/usr/bin:/bin" };
@@ -615,6 +616,35 @@ describe("DesktopBackendConfiguration", () => {
);
});
+ it.effect("resolveWsl preserves the staging error when the mounted fallback is fatal", () =>
+ withPackagedWslHarness(
+ {
+ archiveHash: "b".repeat(64),
+ wsl: () => ({
+ prepareRuntime: () => ({
+ ok: false,
+ reason:
+ "t3: error while loading shared libraries: libatomic.so.1: cannot open shared object file",
+ }),
+ ensureNodePty: () => ({
+ ok: false,
+ reason: "the packaged Linux node-pty binary was not included",
+ fatal: true,
+ }),
+ }),
+ },
+ () =>
+ Effect.gen(function* () {
+ const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
+ const config = yield* configuration.resolveWsl({ port: 5000, distro: "Ubuntu" });
+ const failure = Option.getOrThrow(config.preflightFailure);
+
+ assert.isTrue(failure.fatal);
+ assert.include(failure.reason, "libatomic.so.1");
+ }),
+ ),
+ );
+
it.effect("resolveWsl keeps the staged runtime when the mounted tree fails too", () => {
const stagedAppRoot = "/home/test/.t3/wsl-runtime/cache";
const invalidatedRuntimeIds: string[] = [];
diff --git a/apps/desktop/src/backend/DesktopBackendConfiguration.ts b/apps/desktop/src/backend/DesktopBackendConfiguration.ts
index d9ff9827971..77a90e0512a 100644
--- a/apps/desktop/src/backend/DesktopBackendConfiguration.ts
+++ b/apps/desktop/src/backend/DesktopBackendConfiguration.ts
@@ -386,7 +386,7 @@ const runWslPreflight = Effect.fn("desktop.backendConfiguration.wslPreflight")(f
: ({ ok: true, windowsEntryPath, linuxAppRoot: mountedAppRoot.value } as const);
});
- let stagedFailure: { readonly runtimeId: string; readonly reason: string } | undefined;
+ let stagedFailure: { readonly runtimeId?: string; readonly reason: string } | undefined;
const failedStaged = (failure: { readonly reason: string }) =>
({
_tag: "Failed",
@@ -417,6 +417,7 @@ const runWslPreflight = Effect.fn("desktop.backendConfiguration.wslPreflight")(f
);
stagedFailure = { runtimeId: input.runtimeArchive.runtimeId, reason: stagedProbe.reason };
} else {
+ stagedFailure = { reason: runtime.reason };
yield* Effect.logWarning(
"Could not stage the WSL runtime; launching from the mounted server tree instead.",
{ reason: runtime.reason },
@@ -446,7 +447,7 @@ const runWslPreflight = Effect.fn("desktop.backendConfiguration.wslPreflight")(f
: failedNodePty(nodePtyResult);
}
- if (stagedFailure) {
+ if (stagedFailure?.runtimeId) {
yield* wslEnv.invalidateRuntime(runningDistro, stagedFailure.runtimeId);
}
diff --git a/apps/desktop/src/wsl/DesktopWslEnvironment.test.ts b/apps/desktop/src/wsl/DesktopWslEnvironment.test.ts
index ab4a73c544a..b3f695daf2d 100644
--- a/apps/desktop/src/wsl/DesktopWslEnvironment.test.ts
+++ b/apps/desktop/src/wsl/DesktopWslEnvironment.test.ts
@@ -286,7 +286,7 @@ describe("WSL runtime cache", () => {
expect(script).toContain('runtime_parent="$HOME/.t3/wsl-runtime"');
expect(script).toContain(' [ -f "$ready_marker" ] &&');
- expect(script).toContain(' runtime_entry_runs "$runtime_root" &&');
+ expect(script).toContain(' runtime_entry_runs "$runtime_root" 2>/dev/null &&');
expect(script).toContain("if runtime_is_ready; then");
expect(script).not.toContain("bin.mjs");
expect(script).not.toContain("node-pty");
@@ -366,7 +366,7 @@ describe("WSL runtime cache", () => {
"b".repeat(64),
);
- expect(script).toContain(' [ -x "$1/t3" ] && "$1/t3" --version >/dev/null 2>&1');
+ expect(script).toContain(' [ -x "$1/t3" ] && "$1/t3" --version >/dev/null');
const entryCheckDefined = script.indexOf("runtime_entry_runs() {");
const readinessDefined = script.indexOf("runtime_is_ready() {");
@@ -478,14 +478,14 @@ describe.skipIf(posixShellRunner === null)("WSL runtime install script (executed
fixtures.length = 0;
});
- const createFixture = () => {
+ const createFixture = (serverEntry = SERVER_ENTRY_SOURCE) => {
const result = runShell(
[
"set -eu",
"work=$(mktemp -d)",
'stage="$work/stage/t3-0.0.0-linux-x64"',
'mkdir -p "$stage/node_modules/node-pty/build/Release" "$work/home"',
- `printf '%s' ${sh(SERVER_ENTRY_SOURCE)} > "$stage/t3"`,
+ `printf '%s' ${sh(serverEntry)} > "$stage/t3"`,
'chmod +x "$stage/t3"',
`printf '%s' 'pty-native-payload' > "$stage/node_modules/node-pty/build/Release/pty.node"`,
`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
expect(parseWslRuntimeRoot(warm.stdout)).toBe(fixture.runtimeRoot);
});
+ it("retains the loader error when a bundled executable needs a missing system library", () => {
+ const fixture = createFixture(
+ '#!/bin/sh\nprintf "error while loading shared libraries: libatomic.so.1: cannot open shared object file\\n" >&2\nexit 127\n',
+ );
+
+ const result = fixture.install();
+
+ expect(result.status).not.toBe(0);
+ expect(result.stderr).toContain("libatomic.so.1");
+ expect(parseWslRuntimeRoot(result.stdout)).toBeNull();
+ });
+
it("reinstalls a cache whose executable was truncated", () => {
const fixture = createFixture();
expect(fixture.install().status).toBe(0);
diff --git a/apps/desktop/src/wsl/DesktopWslEnvironment.ts b/apps/desktop/src/wsl/DesktopWslEnvironment.ts
index 2fb4a0aa37d..d3d5b9877be 100644
--- a/apps/desktop/src/wsl/DesktopWslEnvironment.ts
+++ b/apps/desktop/src/wsl/DesktopWslEnvironment.ts
@@ -275,7 +275,7 @@ export const buildWslRuntimeInstallScript = (
`runtime_root="$runtime_parent/${safeRuntimeId}"`,
`ready_marker="$runtime_root/${WSL_RUNTIME_READY_MARKER}"`,
"runtime_entry_runs() {",
- ' [ -x "$1/t3" ] && "$1/t3" --version >/dev/null 2>&1',
+ ' [ -x "$1/t3" ] && "$1/t3" --version >/dev/null',
"}",
// Hashing the entry is what tells a working cache from one whose `t3` was
// swapped or half-written after install: the file is still there and may
@@ -286,7 +286,7 @@ export const buildWslRuntimeInstallScript = (
"}",
"runtime_is_ready() {",
' [ -f "$ready_marker" ] &&',
- ' runtime_entry_runs "$runtime_root" &&',
+ ' runtime_entry_runs "$runtime_root" 2>/dev/null &&',
` recorded_entry_digest=$(tr -d '[:space:]' < "$ready_marker" 2>/dev/null) &&`,
' [ -n "$recorded_entry_digest" ] &&',
' [ "$recorded_entry_digest" = "$(runtime_server_entry_digest "$runtime_root")" ]',