test: remove duplicate and theatrical tests (#2616)

The ensureSshKeys tests had two identical tests covering the same code
path: "uses all keys in non-interactive mode when multiple exist" and
"uses all keys when multiselect is unavailable". Both created the same
two fake key pairs, used the same spawnSync mock, and made the identical
assertion (toHaveLength(2)).

The first test set SPAWN_NON_INTERACTIVE=1 which ensureSshKeys does not
check — stale logic from a removed interactive multiselect flow. The
second test referenced unavailable @clack/prompts multiselect which also
no longer exists in the implementation.

Consolidated into one deterministic test that also validates key ordering
(ed25519 sorts before rsa).

-- qa/dedup-scanner

Co-authored-by: spawn-qa-bot <qa@openrouter.ai>
This commit is contained in:
A 2026-03-14 09:46:55 -07:00 committed by GitHub
parent 1195fcb648
commit 6988ac7acf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -304,25 +304,7 @@ describe("ensureSshKeys", () => {
expect(keys[0].name).toBe("id_rsa");
});
it("uses all keys in non-interactive mode when multiple exist", async () => {
process.env.SPAWN_NON_INTERACTIVE = "1";
createFakeKeyPair("id_ed25519", "ed25519");
createFakeKeyPair("id_rsa", "rsa");
const spawnSpy = spyOn(Bun, "spawnSync").mockImplementation((args: string[]) => {
const pubPath = args[args.length - 1];
const type = pubPath.includes("ed25519") ? "ED25519" : "RSA";
return sshKeygenLfResult(type);
});
const keys = await ensureSshKeys();
spawnSpy.mockRestore();
expect(keys).toHaveLength(2);
});
it("uses all keys when multiselect is unavailable", async () => {
// In test environments, @clack/prompts multiselect may not be available
// due to global mock.module ordering — ensureSshKeys falls back to all keys
it("uses all discovered keys when multiple exist", async () => {
createFakeKeyPair("id_ed25519", "ed25519");
createFakeKeyPair("id_rsa", "rsa");
@ -335,6 +317,8 @@ describe("ensureSshKeys", () => {
const keys = await ensureSshKeys();
spawnSpy.mockRestore();
expect(keys).toHaveLength(2);
expect(keys[0].name).toBe("id_ed25519");
expect(keys[1].name).toBe("id_rsa");
});
it("caches results across calls", async () => {