From ee7c0f80bd5f870eab6cd060750dc580cbce942c Mon Sep 17 00:00:00 2001 From: Josh Gratton Date: Thu, 28 May 2026 17:43:56 -0400 Subject: [PATCH] refactor(desktop): single source of truth for the wsl: instance-id prefix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `WSL_INSTANCE_ID_PREFIX = "wsl:"` was defined twice — once in DesktopWslBackend (which produces the ids) and once in ipc/methods/window.ts (which parses them in pickFolder). A rename of one would silently break the other: pickFolder would stop recognizing WSL targets and fall through to the Windows picker without error. Export the constant from DesktopWslBackend (the producer) and import it in window.ts. Same value, one declaration. --- apps/desktop/src/ipc/methods/window.ts | 11 +++++------ apps/desktop/src/wsl/DesktopWslBackend.ts | 6 +++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/apps/desktop/src/ipc/methods/window.ts b/apps/desktop/src/ipc/methods/window.ts index fc9b377292..b50c7f673e 100644 --- a/apps/desktop/src/ipc/methods/window.ts +++ b/apps/desktop/src/ipc/methods/window.ts @@ -14,6 +14,7 @@ import * as Schema from "effect/Schema"; import * as DesktopBackendPool from "../../backend/DesktopBackendPool.ts"; import * as DesktopEnvironment from "../../app/DesktopEnvironment.ts"; import * as DesktopAppSettings from "../../settings/DesktopAppSettings.ts"; +import * as DesktopWslBackend from "../../wsl/DesktopWslBackend.ts"; import * as DesktopWslEnvironment from "../../wsl/DesktopWslEnvironment.ts"; import * as ElectronDialog from "../../electron/ElectronDialog.ts"; import * as ElectronMenu from "../../electron/ElectronMenu.ts"; @@ -84,17 +85,15 @@ export const getLocalEnvironmentBootstraps = makeSyncIpcMethod({ }), }); -const WSL_INSTANCE_ID_PREFIX = "wsl:"; - // Pull the distro selection out of a backend instance id like // "wsl:ubuntu". Returns null for "wsl:default", which is the sentinel // for "track the user's WSL default distro" and maps to the // wslEnv-derived default at picker time. function extractWslDistroFromEnvironmentId(envId: string): string | null { - if (!envId.startsWith(WSL_INSTANCE_ID_PREFIX)) { + if (!envId.startsWith(DesktopWslBackend.WSL_INSTANCE_ID_PREFIX)) { return null; } - const suffix = envId.slice(WSL_INSTANCE_ID_PREFIX.length); + const suffix = envId.slice(DesktopWslBackend.WSL_INSTANCE_ID_PREFIX.length); return suffix === "default" || suffix.length === 0 ? null : suffix; } @@ -119,13 +118,13 @@ export const pickFolder = makeIpcMethod({ // - anything else (incl. PRIMARY_LOCAL_ENVIRONMENT_ID): primary picker. const targetId = options?.targetEnvironmentId; const wslDistroFromTarget = - targetId !== undefined && targetId.startsWith(WSL_INSTANCE_ID_PREFIX) + targetId !== undefined && targetId.startsWith(DesktopWslBackend.WSL_INSTANCE_ID_PREFIX) ? extractWslDistroFromEnvironmentId(targetId) : null; const useWsl = targetId !== undefined && targetId !== PRIMARY_LOCAL_ENVIRONMENT_ID && - targetId.startsWith(WSL_INSTANCE_ID_PREFIX); + targetId.startsWith(DesktopWslBackend.WSL_INSTANCE_ID_PREFIX); const settings = yield* appSettings.get; // Fall back to the persisted wslDistro when the id is the // "wsl:default" sentinel; the orchestrator uses the same fallback diff --git a/apps/desktop/src/wsl/DesktopWslBackend.ts b/apps/desktop/src/wsl/DesktopWslBackend.ts index bd0972f83b..585cab6cb0 100644 --- a/apps/desktop/src/wsl/DesktopWslBackend.ts +++ b/apps/desktop/src/wsl/DesktopWslBackend.ts @@ -35,7 +35,11 @@ import * as DesktopServerExposure from "../backend/DesktopServerExposure.ts"; import * as DesktopAppSettings from "../settings/DesktopAppSettings.ts"; import * as DesktopWslEnvironment from "./DesktopWslEnvironment.ts"; -const WSL_INSTANCE_ID_PREFIX = "wsl:"; +// Exported so callers that parse pool ids (e.g. the pickFolder IPC +// handler in ipc/methods/window.ts) reference the same prefix this +// module produces. Keeping it inline in two places risks silent +// divergence if one ever gets renamed. +export const WSL_INSTANCE_ID_PREFIX = "wsl:"; const WSL_DEFAULT_DISTRO_ID = `${WSL_INSTANCE_ID_PREFIX}default`; const MAX_TCP_PORT = 65_535;