Files
Netcatty/lib/localShell.test.ts
T
Netcatty-Bot 6c2bf43ee5 fix(vault): let local shell (CMD) sessions be saved into groups (#3616)
Related to #3615 (stays open: hiding/restoring running sessions is separate work).

Merged by judgment after ~49 Codex findings; remaining P2 (Copy Tab name/icon snapshot when host shell is edited after launch) is a cosmetic edge case for a follow-up.
2026-10-15 14:13:46 +08:00

47 lines
2.0 KiB
TypeScript

import { createRequire } from "node:module";
import assert from "node:assert/strict";
import test from "node:test";
import { classifyLocalShellType, detectLocalOs } from "./localShell";
const require = createRequire(import.meta.url);
const cjsLocalShell = require("./localShell.cjs") as {
classifyLocalShellType: typeof classifyLocalShellType;
detectLocalOs: typeof detectLocalOs;
};
test("local shell classification is shared between renderer and CommonJS bridge", () => {
const cases: Array<[string | undefined, string | undefined, ReturnType<typeof classifyLocalShellType>]> = [
["/bin/zsh", "MacIntel", "posix"],
["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "Win32", "powershell"],
["C:\\Windows\\System32\\cmd.exe", "Win32", "cmd"],
["C:\\Windows\\System32\\wsl.exe", "Win32", "posix"],
["C:\\msys64\\usr\\bin\\bash.exe", "Win32", "posix"],
["wsl-ubuntu", "Win32", "posix"],
["git-bash", "Win32", "posix"],
["cygwin", "Win32", "posix"],
["fish", "linux", "fish"],
// Disambiguated Unix discovery IDs are path slugs (shell path with
// separators replaced by "-"); classification resolves their basename.
["bin-bash", "Darwin", "posix"],
["opt-homebrew-bin-bash", "Darwin", "posix"],
["usr-local-bin-zsh", "Darwin", "posix"],
["opt-homebrew-bin-fish", "Darwin", "fish"],
["", "Win32", "powershell"],
[undefined, "MacIntel", "posix"],
["custom-shell", "linux", "unknown"],
];
for (const [shellPath, platform, expected] of cases) {
assert.equal(classifyLocalShellType(shellPath, platform), expected);
assert.equal(cjsLocalShell.classifyLocalShellType(shellPath, platform), expected);
}
});
test("local OS detection is shared between renderer and CommonJS bridge", () => {
assert.equal(detectLocalOs("MacIntel"), "macos");
assert.equal(cjsLocalShell.detectLocalOs("MacIntel"), "macos");
assert.equal(detectLocalOs("Win32"), "windows");
assert.equal(cjsLocalShell.detectLocalOs("Win32"), "windows");
});