Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions packages/cli/src/__tests__/cmd-fix-cov.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 12 additions & 15 deletions packages/cli/src/__tests__/recursive-spawn.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)", () => {
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/__tests__/update-check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ───────────────────────────────────────────────────────────────

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down
Loading