Self-hosted, plugin-based server management.
TypeScript dockerhomelabpluginsrdpremote-desktopself-hostedserver-managementsftpsshterminaltermixvnc
import path from "node:path";
import { describe, expect, it } from "vitest";
import {
repairSpawnHelpers,
resolveLocalShell,
} from "../../plugins/desktop-local/local-pty.js";
describe("resolveLocalShell", () => {
it("starts the default WSL distribution without PowerShell arguments", () => {
expect(resolveLocalShell("win32", "wsl", {})).toEqual({
file: "wsl.exe",
args: [],
});
});
it("keeps PowerShell as the default Windows shell", () => {
expect(resolveLocalShell("win32", "default", {})).toEqual({
file: "powershell.exe",
args: ["-NoLogo"],
});
});
it("preserves the configured shell on non-Windows platforms", () => {
expect(
resolveLocalShell("linux", "wsl", { SHELL: "/bin/fish" }, () => true),
).toEqual({
file: "/bin/fish",
args: ["-l"],
});
});
it("skips a configured shell that is not installed", () => {
const installed = new Set(["/bin/bash", "/bin/zsh"]);
expect(
resolveLocalShell(
"darwin",
undefined,
{ SHELL: "/opt/homebrew/bin/fish" },
(file) => installed.has(file),
).file,
).toBe("/bin/zsh");
});
});
describe("repairSpawnHelpers", () => {
it("restores the execute bit in the unpacked copy only when it is missing", () => {
const modes = new Map<string, number>();
const chmods: Array<[string, number]> = [];
const fsImpl = {
statSync: (file: string) => {
const mode = modes.get(file);
if (mode === undefined) throw new Error("ENOENT");
return { mode };
},
chmodSync: (file: string, mode: number) => {
chmods.push([file, mode]);
},
};
const dir =
"/Applications/Termix.app/Contents/Resources/app.asar/node_modules/node-pty";
const unpacked = dir.replace("app.asar", "app.asar.unpacked");
const release = `${unpacked}/build/Release/spawn-helper`;
modes.set(release.split("/").join(path.sep), 0o644);
modes.set(release, 0o644);
expect(repairSpawnHelpers(dir, fsImpl as never)).toBe(1);
expect(chmods[0][1] & 0o111).not.toBe(0);
expect(chmods[0][0]).toContain("app.asar.unpacked");
});
it.each(["app-arm64.asar", "app-x64.asar"])(
"repairs the helper in the unpacked copy of a universal build's %s",
(asar) => {
const chmods: string[] = [];
const fsImpl = {
statSync: () => ({ mode: 0o644 }),
chmodSync: (file: string) => {
chmods.push(file.split(path.sep).join("/"));
},
};
const dir = `/Applications/Termix.app/Contents/Resources/${asar}/node_modules/node-pty`;
repairSpawnHelpers(dir, fsImpl as never);
expect(chmods[0]).toContain(`/${asar}.unpacked/node_modules/node-pty/`);
},
);
});