test: tighten ssh config spawn assertions

This commit is contained in:
Shakker
2026-05-08 20:21:41 +01:00
parent 57f6521e31
commit 5b478a8fdf

View File

@@ -46,6 +46,15 @@ vi.mock("node:child_process", async () => {
const spawnMock = vi.mocked(spawn);
function requireSpawnArgs(index: number): string[] {
const args = spawnMock.mock.calls[index]?.[1] as string[] | undefined;
expect(args).toBeDefined();
if (!args) {
throw new Error("expected ssh spawn args");
}
return args;
}
let parseSshConfigOutput: typeof import("./ssh-config.js").parseSshConfigOutput;
let resolveSshConfig: typeof import("./ssh-config.js").resolveSshConfig;
@@ -81,8 +90,7 @@ describe("ssh-config", () => {
expect(config?.host).toBe("peters-mac-studio-1.sheep-coho.ts.net");
expect(config?.port).toBe(2222);
expect(config?.identityFiles).toEqual(["/tmp/id_ed25519"]);
const args = spawnMock.mock.calls[0]?.[1] as string[] | undefined;
expect(args?.slice(-2)).toEqual(["--", "me@alias"]);
expect(requireSpawnArgs(0).slice(-2)).toEqual(["--", "me@alias"]);
});
it("adds non-default port and trimmed identity arguments", async () => {