fix: fix misc windows issues (#323)
Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
81
src/tests/tools/shell-launchers.test.ts
Normal file
81
src/tests/tools/shell-launchers.test.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { buildShellLaunchers } from "../../tools/impl/shellLaunchers";
|
||||
|
||||
describe("Shell Launchers", () => {
|
||||
test("builds launchers for a command", () => {
|
||||
const launchers = buildShellLaunchers("echo hello");
|
||||
expect(launchers.length).toBeGreaterThan(0);
|
||||
expect(launchers[0]).toBeDefined();
|
||||
});
|
||||
|
||||
test("returns empty array for empty command", () => {
|
||||
const launchers = buildShellLaunchers("");
|
||||
expect(launchers).toEqual([]);
|
||||
});
|
||||
|
||||
test("returns empty array for whitespace-only command", () => {
|
||||
const launchers = buildShellLaunchers(" ");
|
||||
expect(launchers).toEqual([]);
|
||||
});
|
||||
|
||||
if (process.platform === "win32") {
|
||||
describe("Windows-specific", () => {
|
||||
test("PowerShell is tried before cmd.exe", () => {
|
||||
const launchers = buildShellLaunchers("echo test");
|
||||
|
||||
// Find indices of PowerShell and cmd.exe
|
||||
const powershellIndex = launchers.findIndex(
|
||||
(l) =>
|
||||
l[0]?.toLowerCase().includes("powershell") ||
|
||||
l[0]?.toLowerCase() === "pwsh",
|
||||
);
|
||||
const cmdIndex = launchers.findIndex(
|
||||
(l) =>
|
||||
l[0]?.toLowerCase().includes("cmd") ||
|
||||
l[0]?.toLowerCase() === process.env.ComSpec?.toLowerCase(),
|
||||
);
|
||||
|
||||
expect(powershellIndex).toBeGreaterThanOrEqual(0);
|
||||
expect(cmdIndex).toBeGreaterThanOrEqual(0);
|
||||
// PowerShell should come before cmd.exe
|
||||
expect(powershellIndex).toBeLessThan(cmdIndex);
|
||||
});
|
||||
|
||||
test("includes PowerShell with -NoProfile flag", () => {
|
||||
const launchers = buildShellLaunchers("echo test");
|
||||
const powershellLauncher = launchers.find((l) =>
|
||||
l[0]?.toLowerCase().includes("powershell"),
|
||||
);
|
||||
|
||||
expect(powershellLauncher).toBeDefined();
|
||||
expect(powershellLauncher).toContain("-NoProfile");
|
||||
expect(powershellLauncher).toContain("-Command");
|
||||
});
|
||||
});
|
||||
} else {
|
||||
describe("Unix-specific", () => {
|
||||
test("includes bash with -lc flag", () => {
|
||||
const launchers = buildShellLaunchers("echo test");
|
||||
const bashLauncher = launchers.find(
|
||||
(l) => l[0]?.includes("bash") && l[1] === "-lc",
|
||||
);
|
||||
|
||||
expect(bashLauncher).toBeDefined();
|
||||
});
|
||||
|
||||
test("prefers user SHELL environment", () => {
|
||||
const originalShell = process.env.SHELL;
|
||||
process.env.SHELL = "/bin/zsh";
|
||||
|
||||
try {
|
||||
const launchers = buildShellLaunchers("echo test");
|
||||
// User's shell should be first
|
||||
expect(launchers[0]?.[0]).toBe("/bin/zsh");
|
||||
} finally {
|
||||
if (originalShell === undefined) delete process.env.SHELL;
|
||||
else process.env.SHELL = originalShell;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user