Files
claw3d/tests/unit/runSshJson.test.ts
T
Luke The Dev 4fa4f13558 First Release of Claw3D (#11)
Co-authored-by: iamlukethedev <iamlukethedev@users.noreply.github.com>
2026-03-19 23:14:04 -05:00

48 lines
1.2 KiB
TypeScript

// @vitest-environment node
import { describe, expect, it, vi } from "vitest";
import { spawnSync } from "node:child_process";
vi.mock("node:child_process", async () => {
const actual = await vi.importActual<typeof import("node:child_process")>(
"node:child_process"
);
return {
default: actual,
...actual,
spawnSync: vi.fn(),
};
});
import { runSshJson } from "@/lib/ssh/gateway-host";
const mockedSpawnSync = vi.mocked(spawnSync);
describe("runSshJson", () => {
it("forwards maxBuffer to spawnSync when provided", () => {
mockedSpawnSync.mockReturnValueOnce({
status: 0,
stdout: JSON.stringify({ ok: true }),
stderr: "",
error: undefined,
} as never);
runSshJson({
sshTarget: "me@example.test",
argv: ["bash", "-lc", "echo ok"],
label: "ssh-json-test",
input: "echo hello",
maxBuffer: 12345,
} as unknown as Parameters<typeof runSshJson>[0]);
expect(mockedSpawnSync).toHaveBeenCalledTimes(1);
const [, , options] = mockedSpawnSync.mock.calls[0] as [
string,
string[],
{ encoding?: string; input?: string; maxBuffer?: number },
];
expect(options.maxBuffer).toBe(12345);
});
});