Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions apps/desktop/src/ipc/methods/window.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ vi.mock("electron", () => ({
BrowserWindow: { fromWebContents: ownerWindow },
}));

import * as DesktopConfig from "../../app/DesktopConfig.ts";
import * as DesktopEnvironment from "../../app/DesktopEnvironment.ts";
import * as DesktopWslEnvironment from "../../wsl/DesktopWslEnvironment.ts";
import * as DesktopBackendConfiguration from "../../backend/DesktopBackendConfiguration.ts";
import * as DesktopBackendManager from "../../backend/DesktopBackendManager.ts";
import * as DesktopBackendPool from "../../backend/DesktopBackendPool.ts";
Expand All @@ -27,6 +30,7 @@ import {
getLocalEnvironmentBootstraps,
getRelayTelemetryEnabled,
pickProjectFavicon,
pickFolder,
probeRemoteEditors,
} from "./window.ts";

Expand Down Expand Up @@ -82,6 +86,87 @@ const backendConfigurationLayer = Layer.succeed(
const bootstrapsLayer = (instances: ReadonlyArray<DesktopBackendManager.DesktopBackendInstance>) =>
Layer.merge(DesktopBackendPool.layerTest([...instances]), backendConfigurationLayer);

describe("pickFolder", () => {
const distrosWithDefault = (defaultDistro: string) =>
["Ubuntu", "Debian"].map((name) => ({
name,
isDefault: name === defaultDistro,
version: 2 as const,
}));

it.effect.each([
{
name: "converts a folder in the default distro to its Linux path",
targetEnvironmentId: "wsl:default",
picked: "\\\\wsl.localhost\\Ubuntu\\home\\demo\\repo",
expected: "/home/demo/repo",
},
Comment thread
only21mil marked this conversation as resolved.
Resolved
{
name: "keeps another distro's folder as UNC so the renderer routes it",
targetEnvironmentId: "wsl:Ubuntu",
picked: "\\\\wsl.localhost\\Debian\\home\\demo\\repo",
expected: "\\\\wsl.localhost\\Debian\\home\\demo\\repo",
},
{
name: "keeps another distro's folder when the target tracks the default distro",
targetEnvironmentId: "wsl:default",
picked: "\\\\wsl$\\debian\\home\\demo\\repo",
expected: "\\\\wsl$\\debian\\home\\demo\\repo",
},
{
name: "compares against the distro a default-tracking backend runs, not the current default",
targetEnvironmentId: "wsl:default",
windowsDefault: "Debian",
picked: "\\\\wsl.localhost\\Debian\\home\\demo\\repo",
expected: "\\\\wsl.localhost\\Debian\\home\\demo\\repo",
},
{
name: "compares against the distro a WSL-only primary runs",
targetEnvironmentId: "wsl:default",
backendId: DesktopBackendPool.PRIMARY_INSTANCE_ID,
windowsDefault: "Debian",
picked: "\\\\wsl.localhost\\Debian\\home\\demo\\repo",
expected: "\\\\wsl.localhost\\Debian\\home\\demo\\repo",
},
])(
"$name",
({
targetEnvironmentId,
backendId = defaultWslInstance.id,
windowsDefault = "Ubuntu",
picked,
expected,
}) =>
Effect.gen(function* () {
const result = yield* pickFolder.handler({ targetEnvironmentId });
assert.strictEqual(result, expected);
}).pipe(
Effect.provide(
Layer.mergeAll(
Layer.mock(ElectronDialog.ElectronDialog)({
pickFolder: () => Effect.succeedSome(picked),
}),
Layer.mock(ElectronWindow.ElectronWindow)({ focusedMainOrFirst: Effect.succeedNone }),
DesktopEnvironment.layer({
dirname: "/app",
homeDirectory: "C:\\Users\\demo",
platform: "win32",
processArch: "x64",
appVersion: "0.0.0",
appPath: "/app",
isPackaged: false,
resourcesPath: "/app/resources",
runningUnderArm64Translation: false,
}).pipe(Layer.provide(Layer.merge(NodeServices.layer, DesktopConfig.layerTest({})))),
DesktopAppSettings.layerTest(),
DesktopWslEnvironment.layerTest({ distros: distrosWithDefault(windowsDefault) }),
DesktopBackendPool.layerTest([{ ...defaultWslInstance, id: backendId }]),
),
),
),
);
});

describe("getLocalEnvironmentBootstraps", () => {
it.effect("hands out the current window's token to a backend launched with the secret", () =>
Effect.gen(function* () {
Expand Down
22 changes: 21 additions & 1 deletion apps/desktop/src/ipc/methods/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export const pickFolder = DesktopIpc.makeIpcMethod({
const environment = yield* DesktopEnvironment.DesktopEnvironment;
const appSettings = yield* DesktopAppSettings.DesktopAppSettings;
const wslEnvironment = yield* DesktopWslEnvironment.DesktopWslEnvironment;
const pool = yield* DesktopBackendPool.DesktopBackendPool;
const settings = yield* appSettings.get;
// A picked path only means something to a backend on this machine.
if (!settings.localEnvironmentEnabled) {
Expand All @@ -194,12 +195,13 @@ export const pickFolder = DesktopIpc.makeIpcMethod({
targetId.startsWith(DesktopWslBackend.WSL_INSTANCE_ID_PREFIX);
// Match the orchestrator's persisted distro fallback for wsl:default.
const wslDistro = useWsl ? (wslDistroFromTarget ?? settings.wslDistro) : null;
const distros = useWsl ? yield* wslEnvironment.listDistros : [];
const defaultPath = useWsl
? Option.fromNullishOr(
resolveWslPickFolderDefaultPath(
options,
{ distro: wslDistro },
yield* wslEnvironment.listDistros,
distros,
Option.getOrNull(yield* wslEnvironment.getUserHome(wslDistro)),
),
)
Expand All @@ -215,6 +217,24 @@ export const pickFolder = DesktopIpc.makeIpcMethod({
return selectedPath.value;
}

// Another distro's folder stays UNC so the renderer routes it to that distro or refuses it.
const selectedDistro = extractDistroFromUncPath(selectedPath.value);
const targetInstance = yield* pool.get(DesktopBackendPool.BackendInstanceId(targetId));
// WSL-only mode runs the WSL backend as the primary, under no wsl:* id.
const targetBackend = Option.isSome(targetInstance)
? targetInstance.value
: yield* pool.primary;
const runningDistro = Option.getOrUndefined(yield* targetBackend.currentConfig)?.runningDistro;
const targetDistro =
runningDistro ?? wslDistro ?? distros.find((distro) => distro.isDefault)?.name ?? null;
if (
selectedDistro !== null &&
targetDistro !== null &&
selectedDistro.toLowerCase() !== targetDistro.toLowerCase()
) {
return selectedPath.value;
}

const linuxUncPath = wslUncPathToLinuxPath(selectedPath.value);
if (linuxUncPath !== null) {
return linuxUncPath;
Expand Down
Loading