mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-04-28 03:49:31 +00:00
test: Remove duplicate and theatrical tests (#3089)
* test: remove duplicate and theatrical tests
- update-check.test.ts: fix 3 tests using stale hardcoded version '0.2.3'
(older than current 0.29.1) to use `pkg.version` so 'should not update
when up to date' actually tests the current-version path correctly
- run-path-credential-display.test.ts: strengthen weak `toBeDefined()`
assertion on digitalocean hint to `toContain('Simple cloud hosting')`,
making it verify the actual fallback hint content
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* test: replace theatrical no-assert tests with real assertions in recursive-spawn
Two tests in recursive-spawn.test.ts captured console.log output into a
logs array but never asserted against it. Both ended with a comment like
"should not throw" — meaning they only proved the function didn't crash,
not that it produced the right output.
- "shows empty message when no history": now spies on p.log.info and
asserts cmdTree() emits "No spawn history found."
- "shows flat message when no parent-child relationships": now asserts
cmdTree() emits "no parent-child relationships" via p.log.info.
expect() call count: 4831 to 4834 (+3 real assertions added).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* test: consolidate redundant describe block in cmd-fix-cov.test.ts
The file had two separate describe blocks with identical beforeEach/afterEach
boilerplate. The second block ("fixSpawn connection edge cases") contained only
one test ("shows success when fix script succeeds") and could be merged directly
into the first block ("fixSpawn (additional coverage)") without any loss of
coverage or setup fidelity.
Removes 23 lines of duplicated boilerplate. Test count unchanged (6 tests).
---------
Co-authored-by: spawn-qa-bot <qa@openrouter.ai>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b0f9f4e7af
commit
994a512115
4 changed files with 17 additions and 42 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 () => {
|
||||
|
|
|
|||
|
|
@ -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)", () => {
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue