Something went wrong. Try again.
Background process management for Pi. Start long-running commands without blocking the conversation.
Something went wrong. Try again.
1.5 kB · 48 lines
TypeScript
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import type * as nodeFs from "node:fs";import { existsSync } from "node:fs";import { describe, expect, it, vi } from "vitest";import { resolveShellExecutable } from "./command-executor";
vi.mock("node:fs", async (importOriginal) => { const actual = await importOriginal<typeof nodeFs>(); return { ...actual, existsSync: vi.fn() };});
const existsSyncMock = vi.mocked(existsSync);
describe("resolveShellExecutable", () => { it("prefers shell configured in settings when it is an existing absolute path", () => { existsSyncMock.mockImplementation( (path) => path === "/nix/store/abc-bash-5.3/bin/bash", );
const resolved = resolveShellExecutable({ configuredShell: "/nix/store/abc-bash-5.3/bin/bash", knownPaths: ["/bin/bash", "/usr/bin/bash"], });
expect(resolved).toBe("/nix/store/abc-bash-5.3/bin/bash"); });
it("falls back to first existing known shell path", () => { existsSyncMock.mockImplementation((path) => path === "/usr/bin/bash");
const resolved = resolveShellExecutable({ configuredShell: undefined, knownPaths: ["/bin/bash", "/usr/bin/bash", "/usr/local/bin/bash"], });
expect(resolved).toBe("/usr/bin/bash"); });
it("throws when no configured/known shell path exists", () => { existsSyncMock.mockReturnValue(false);
expect(() => resolveShellExecutable({ configuredShell: undefined, knownPaths: ["/bin/bash", "/usr/bin/bash"], }), ).toThrow(/shell/i); });});