diff --git a/packages/cli/src/__tests__/cmd-fix-cov.test.ts b/packages/cli/src/__tests__/cmd-fix-cov.test.ts index 00503f446..a8d5950e5 100644 --- a/packages/cli/src/__tests__/cmd-fix-cov.test.ts +++ b/packages/cli/src/__tests__/cmd-fix-cov.test.ts @@ -151,29 +151,6 @@ describe("fixSpawn (additional coverage)", () => { }); expect(clack.logStep).toHaveBeenCalledWith(expect.stringContaining("1.2.3.4")); }); -}); - -// ── Tests: fixSpawn success message ────────────────────────────────────────── -// (error paths are covered in cmd-fix.test.ts; this covers the exact success message) - -describe("fixSpawn connection edge cases", () => { - let savedApiKey: string | undefined; - - beforeEach(() => { - savedApiKey = process.env.OPENROUTER_API_KEY; - process.env.OPENROUTER_API_KEY = "sk-or-test-fix-key"; - clack.logError.mockReset(); - clack.logSuccess.mockReset(); - clack.logStep.mockReset(); - }); - - afterEach(() => { - if (savedApiKey === undefined) { - delete process.env.OPENROUTER_API_KEY; - } else { - process.env.OPENROUTER_API_KEY = savedApiKey; - } - }); it("shows success when fix script succeeds", async () => { const mockRunner = mock(async () => true); diff --git a/packages/cli/src/__tests__/recursive-spawn.test.ts b/packages/cli/src/__tests__/recursive-spawn.test.ts index fac81be26..f653a0f4b 100644 --- a/packages/cli/src/__tests__/recursive-spawn.test.ts +++ b/packages/cli/src/__tests__/recursive-spawn.test.ts @@ -1,8 +1,9 @@ import type { SpawnRecord } from "../history.js"; -import { afterEach, beforeEach, describe, expect, it, spyOn } from "bun:test"; +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 * as p from "@clack/prompts"; import { findDescendants, pullChildHistory } from "../commands/delete.js"; import { cmdTree } from "../commands/tree.js"; import { exportHistory, HISTORY_SCHEMA_VERSION, loadHistory, mergeChildHistory, saveSpawnRecord } from "../history.js"; @@ -396,16 +397,14 @@ describe("recursive spawn", () => { describe("cmdTree", () => { it("shows empty message when no history", async () => { - const logs: string[] = []; - const origLog = console.log; - console.log = (...args: unknown[]) => { - logs.push(args.map(String).join(" ")); - }; + const logInfoSpy = spyOn(p.log, "info").mockImplementation(mock(() => {})); await cmdTree(); - console.log = origLog; - // p.log.info writes to stderr, not captured — but cmdTree should not throw + expect(logInfoSpy).toHaveBeenCalled(); + const calls = logInfoSpy.mock.calls.map((args) => String(args[0])); + expect(calls.some((msg) => msg.includes("No spawn history found"))).toBe(true); + logInfoSpy.mockRestore(); }); it("renders tree with parent-child relationships", async () => { @@ -517,19 +516,17 @@ describe("recursive spawn", () => { timestamp: "2026-03-24T01:00:00.000Z", }); - const logs: string[] = []; - const origLog = console.log; - console.log = (...args: unknown[]) => { - logs.push(args.map(String).join(" ")); - }; - + const logInfoSpy = spyOn(p.log, "info").mockImplementation(mock(() => {})); const manifestMod = await import("../manifest.js"); const manifestSpy = spyOn(manifestMod, "loadManifest").mockRejectedValue(new Error("no network")); await cmdTree(); - console.log = origLog; manifestSpy.mockRestore(); + + const calls = logInfoSpy.mock.calls.map((args) => String(args[0])); + expect(calls.some((msg) => msg.includes("no parent-child relationships"))).toBe(true); + logInfoSpy.mockRestore(); }); it("renders deleted and depth labels", async () => { diff --git a/packages/cli/src/__tests__/run-path-credential-display.test.ts b/packages/cli/src/__tests__/run-path-credential-display.test.ts index 5f1eceec9..2dc5ec34e 100644 --- a/packages/cli/src/__tests__/run-path-credential-display.test.ts +++ b/packages/cli/src/__tests__/run-path-credential-display.test.ts @@ -219,7 +219,7 @@ describe("prioritizeCloudsByCredentials", () => { expect(result.hintOverrides["hetzner"]).toContain("credentials detected"); expect(result.hintOverrides["hetzner"]).toContain("test"); - expect(result.hintOverrides["digitalocean"]).toBeDefined(); + expect(result.hintOverrides["digitalocean"]).toContain("Simple cloud hosting"); }); it("should handle multi-var auth (both vars must be set)", () => { diff --git a/packages/cli/src/__tests__/update-check.test.ts b/packages/cli/src/__tests__/update-check.test.ts index 54b00fddf..64e27605f 100644 --- a/packages/cli/src/__tests__/update-check.test.ts +++ b/packages/cli/src/__tests__/update-check.test.ts @@ -4,6 +4,7 @@ import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from "bun:te import fs from "node:fs"; import path from "node:path"; import { tryCatch } from "@openrouter/spawn-shared"; +import pkg from "../../package.json"; // ── Test Helpers ─────────────────────────────────────────────────────────────── @@ -135,7 +136,7 @@ describe("update-check", () => { }); it("should not update when up to date", async () => { - const mockFetch = mock(() => Promise.resolve(new Response("0.2.3\n"))); + const mockFetch = mock(() => Promise.resolve(new Response(`${pkg.version}\n`))); const fetchSpy = spyOn(global, "fetch").mockImplementation(mockFetch); // Mock executor to prevent actual commands @@ -396,7 +397,7 @@ describe("update-check", () => { // Write an old timestamp (2 hours ago) writeUpdateChecked(Date.now() - 2 * 60 * 60 * 1000); - const mockFetch = mock(() => Promise.resolve(new Response("0.2.3\n"))); + const mockFetch = mock(() => Promise.resolve(new Response(`${pkg.version}\n`))); const fetchSpy = spyOn(global, "fetch").mockImplementation(mockFetch); const { checkForUpdates } = await import("../update-check.js"); @@ -407,7 +408,7 @@ describe("update-check", () => { }); it("should write cache file after successful version fetch", async () => { - const mockFetch = mock(() => Promise.resolve(new Response("0.2.3\n"))); + const mockFetch = mock(() => Promise.resolve(new Response(`${pkg.version}\n`))); const fetchSpy = spyOn(global, "fetch").mockImplementation(mockFetch); const { checkForUpdates } = await import("../update-check.js");