From 0e17461fcdc4b95cf4405962944595bd0f906556 Mon Sep 17 00:00:00 2001 From: A <258483684+la14-1@users.noreply.github.com> Date: Mon, 23 Mar 2026 07:35:44 -0700 Subject: [PATCH] test: remove duplicate cmdFix tests from cmd-fix-cov.test.ts (#2910) Three tests in the `cmdFix (additional coverage)` describe block were exact duplicates of tests already in cmd-fix.test.ts: - "fixes directly when only one server" = "directly fixes when only one active server" - "finds record by name when spawnId matches name" = "fixes by spawn name" - "shows no active spawns when history is empty" = "shows message when no active spawns" Removed the duplicate describe block and its now-unused imports. Unique fixSpawn coverage (security validation, manifest failure, label fallbacks, success message) is preserved. Agent: pr-maintainer Co-authored-by: B <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.5 --- .../cli/src/__tests__/cmd-fix-cov.test.ts | 110 +----------------- 1 file changed, 4 insertions(+), 106 deletions(-) diff --git a/packages/cli/src/__tests__/cmd-fix-cov.test.ts b/packages/cli/src/__tests__/cmd-fix-cov.test.ts index 59b89b8b..953cd8ea 100644 --- a/packages/cli/src/__tests__/cmd-fix-cov.test.ts +++ b/packages/cli/src/__tests__/cmd-fix-cov.test.ts @@ -4,15 +4,13 @@ * Covers paths not exercised in cmd-fix.test.ts: * - fixSpawn with security validation failures for server_id/server_name * - fixSpawn loading manifest from network when it fails - * - cmdFix non-interactive mode with multiple servers - * - cmdFix with interactive picker (select + cancel) + * - fixSpawn label fallbacks (record name, IP) + * - fixSpawn success message */ import type { SpawnRecord } from "../history"; -import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from "bun:test"; -import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs"; -import { join } from "node:path"; +import { beforeEach, describe, expect, it, mock } from "bun:test"; import { tryCatch } from "@openrouter/spawn-shared"; import { createMockManifest, mockClackPrompts } from "./test-helpers"; @@ -25,7 +23,7 @@ const clack = mockClackPrompts({ }); // ── Import modules under test ─────────────────────────────────────────────── -const { fixSpawn, cmdFix } = await import("../commands/fix.js"); +const { fixSpawn } = await import("../commands/fix.js"); const { _resetCacheForTesting } = await import("../manifest.js"); // ── Helpers ──────────────────────────────────────────────────────────────── @@ -143,106 +141,6 @@ describe("fixSpawn (additional coverage)", () => { }); }); -// ── Tests: cmdFix edge cases ───────────────────────────────────────────────── - -describe("cmdFix (additional coverage)", () => { - let testDir: string; - let savedSpawnHome: string | undefined; - let processExitSpy: ReturnType; - - function writeHistory(records: SpawnRecord[]) { - writeFileSync( - join(testDir, "history.json"), - JSON.stringify({ - version: 1, - records, - }), - ); - } - - beforeEach(() => { - testDir = join(process.env.HOME ?? "", `spawn-fix-cov-${Date.now()}`); - mkdirSync(testDir, { - recursive: true, - }); - savedSpawnHome = process.env.SPAWN_HOME; - process.env.SPAWN_HOME = testDir; - - clack.logError.mockReset(); - clack.logInfo.mockReset(); - clack.logSuccess.mockReset(); - - const savedFetch = global.fetch; - global.fetch = mock(() => Promise.resolve(new Response(JSON.stringify(mockManifest)))); - _resetCacheForTesting(); - - processExitSpy = spyOn(process, "exit").mockImplementation((_code?: number): never => { - throw new Error("process.exit"); - }); - }); - - afterEach(() => { - process.env.SPAWN_HOME = savedSpawnHome; - processExitSpy.mockRestore(); - if (existsSync(testDir)) { - rmSync(testDir, { - recursive: true, - force: true, - }); - } - }); - - it("fixes directly when only one server (no picker needed)", async () => { - const mockRunner = mock(async () => true); - writeHistory([ - makeRecord({ - id: "only-one", - }), - ]); - - const savedFetch = global.fetch; - global.fetch = mock(() => Promise.resolve(new Response(JSON.stringify(mockManifest)))); - _resetCacheForTesting(); - - await cmdFix(undefined, { - runScript: mockRunner, - }); - - expect(mockRunner).toHaveBeenCalled(); - global.fetch = savedFetch; - }); - - it("finds record by name when spawnId matches name", async () => { - const mockRunner = mock(async () => true); - writeHistory([ - makeRecord({ - id: "id-1", - name: "my-spawn", - }), - makeRecord({ - id: "id-2", - name: "other-spawn", - }), - ]); - - const savedFetch = global.fetch; - global.fetch = mock(() => Promise.resolve(new Response(JSON.stringify(mockManifest)))); - _resetCacheForTesting(); - - await cmdFix("my-spawn", { - runScript: mockRunner, - }); - - expect(mockRunner).toHaveBeenCalled(); - global.fetch = savedFetch; - }); - - it("shows no active spawns when history is empty", async () => { - await cmdFix(); - expect(clack.logInfo).toHaveBeenCalledWith(expect.stringContaining("No active spawns")); - }); -}); - // ── Tests: fixSpawn success message ────────────────────────────────────────── // (error paths are covered in cmd-fix.test.ts; this covers the exact success message)