mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-04-28 03:49:31 +00:00
test: remove duplicate and theatrical tests (#2831)
Remove 10 duplicate test cases from cmd-list-cov.test.ts and cmd-run-cov.test.ts that were already covered by dedicated test files: - buildRecordLabel (3 tests) — duplicated from cmdlast.test.ts - buildRecordSubtitle (3 tests) — duplicated from cmdlast.test.ts - cmdListClear (2 tests) — weaker duplicates of clear-history.test.ts - cmdLast (1 test) — duplicated from cmdlast.test.ts - cmdRun detectAndFixSwappedArgs (1 test) — duplicated from commands-swap-resolve.test.ts which has 10 thorough swap tests -- qa/dedup-scanner Co-authored-by: spawn-qa-bot <qa@openrouter.ai>
This commit is contained in:
parent
32525f5dd7
commit
5e263dd12f
2 changed files with 7 additions and 143 deletions
|
|
@ -1,10 +1,12 @@
|
|||
/**
|
||||
* cmd-list-cov.test.ts — Coverage tests for commands/list.ts
|
||||
*
|
||||
* Focuses on uncovered paths: buildRecordLabel, buildRecordSubtitle,
|
||||
* resolveListFilters, showEmptyListMessage, cmdListClear, cmdList
|
||||
* non-interactive path, cmdLast with no history, handleRecordAction branches.
|
||||
* (formatRelativeTime is covered in commands-exported-utils.test.ts)
|
||||
* Focuses on uncovered paths: resolveListFilters, showEmptyListMessage,
|
||||
* cmdList non-interactive path, handleRecordAction branches.
|
||||
* (buildRecordLabel/buildRecordSubtitle covered in cmdlast.test.ts)
|
||||
* (cmdListClear covered in clear-history.test.ts)
|
||||
* (cmdLast covered in cmdlast.test.ts)
|
||||
* (formatRelativeTime covered in commands-exported-utils.test.ts)
|
||||
*/
|
||||
|
||||
import type { SpawnRecord } from "../history.js";
|
||||
|
|
@ -17,7 +19,7 @@ import { createConsoleMocks, createMockManifest, mockClackPrompts, restoreMocks
|
|||
|
||||
const clack = mockClackPrompts();
|
||||
|
||||
const { buildRecordLabel, buildRecordSubtitle, cmdList, cmdListClear, cmdLast } = await import("../commands/index.js");
|
||||
const { cmdList } = await import("../commands/index.js");
|
||||
const { resolveListFilters, handleRecordAction, RecordActionOutcome } = await import("../commands/list.js");
|
||||
|
||||
const mockManifest = createMockManifest();
|
||||
|
|
@ -54,90 +56,6 @@ describe("commands/list.ts coverage", () => {
|
|||
restoreMocks(consoleMocks.log, consoleMocks.error);
|
||||
});
|
||||
|
||||
// ── buildRecordLabel ──────────────────────────────────────────────────
|
||||
|
||||
describe("buildRecordLabel", () => {
|
||||
it("returns name when set", () => {
|
||||
const r: SpawnRecord = {
|
||||
id: "1",
|
||||
agent: "claude",
|
||||
cloud: "sprite",
|
||||
timestamp: "2026-01-01T00:00:00Z",
|
||||
name: "my-server",
|
||||
};
|
||||
expect(buildRecordLabel(r)).toBe("my-server");
|
||||
});
|
||||
|
||||
it("falls back to server_name when no name", () => {
|
||||
const r: SpawnRecord = {
|
||||
id: "1",
|
||||
agent: "claude",
|
||||
cloud: "sprite",
|
||||
timestamp: "2026-01-01T00:00:00Z",
|
||||
connection: {
|
||||
ip: "1.2.3.4",
|
||||
user: "root",
|
||||
server_name: "srv-123",
|
||||
},
|
||||
};
|
||||
expect(buildRecordLabel(r)).toBe("srv-123");
|
||||
});
|
||||
|
||||
it("returns 'unnamed' when no name or server_name", () => {
|
||||
const r: SpawnRecord = {
|
||||
id: "1",
|
||||
agent: "claude",
|
||||
cloud: "sprite",
|
||||
timestamp: "2026-01-01T00:00:00Z",
|
||||
};
|
||||
expect(buildRecordLabel(r)).toBe("unnamed");
|
||||
});
|
||||
});
|
||||
|
||||
// ── buildRecordSubtitle ───────────────────────────────────────────────
|
||||
|
||||
describe("buildRecordSubtitle", () => {
|
||||
it("includes agent, cloud, and time", () => {
|
||||
const r: SpawnRecord = {
|
||||
id: "1",
|
||||
agent: "claude",
|
||||
cloud: "sprite",
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
const subtitle = buildRecordSubtitle(r, mockManifest);
|
||||
expect(subtitle).toContain("Claude Code");
|
||||
expect(subtitle).toContain("Sprite");
|
||||
});
|
||||
|
||||
it("shows [deleted] for deleted connections", () => {
|
||||
const r: SpawnRecord = {
|
||||
id: "1",
|
||||
agent: "claude",
|
||||
cloud: "sprite",
|
||||
timestamp: new Date().toISOString(),
|
||||
connection: {
|
||||
ip: "1.2.3.4",
|
||||
user: "root",
|
||||
deleted: true,
|
||||
},
|
||||
};
|
||||
const subtitle = buildRecordSubtitle(r, mockManifest);
|
||||
expect(subtitle).toContain("[deleted]");
|
||||
});
|
||||
|
||||
it("falls back to key when manifest is null", () => {
|
||||
const r: SpawnRecord = {
|
||||
id: "1",
|
||||
agent: "claude",
|
||||
cloud: "sprite",
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
const subtitle = buildRecordSubtitle(r, null);
|
||||
expect(subtitle).toContain("claude");
|
||||
expect(subtitle).toContain("sprite");
|
||||
});
|
||||
});
|
||||
|
||||
// ── resolveListFilters ────────────────────────────────────────────────
|
||||
|
||||
describe("resolveListFilters", () => {
|
||||
|
|
@ -182,37 +100,6 @@ describe("commands/list.ts coverage", () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ── cmdListClear ──────────────────────────────────────────────────────
|
||||
|
||||
describe("cmdListClear", () => {
|
||||
it("reports no history when empty", async () => {
|
||||
await cmdListClear();
|
||||
expect(clack.logInfo).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("clears history when confirmed in non-interactive mode", async () => {
|
||||
const records: SpawnRecord[] = [
|
||||
{
|
||||
id: "1",
|
||||
agent: "claude",
|
||||
cloud: "sprite",
|
||||
timestamp: "2026-01-01T00:00:00Z",
|
||||
},
|
||||
];
|
||||
writeFileSync(
|
||||
join(testDir, "history.json"),
|
||||
JSON.stringify({
|
||||
version: 1,
|
||||
records,
|
||||
}),
|
||||
);
|
||||
// Make non-interactive
|
||||
process.env.SPAWN_NON_INTERACTIVE = "1";
|
||||
await cmdListClear();
|
||||
expect(clack.logSuccess).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
// ── cmdList non-interactive ───────────────────────────────────────────
|
||||
|
||||
describe("cmdList", () => {
|
||||
|
|
@ -364,16 +251,6 @@ describe("commands/list.ts coverage", () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ── cmdLast ───────────────────────────────────────────────────────────
|
||||
|
||||
describe("cmdLast", () => {
|
||||
it("shows no-history message when empty", async () => {
|
||||
global.fetch = mock(async () => new Response(JSON.stringify(mockManifest)));
|
||||
await cmdLast();
|
||||
expect(clack.logInfo).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
// ── handleRecordAction — only testable branches ────────────────────
|
||||
// NOTE: rerun/fix/enter/reconnect/dashboard actions call real I/O
|
||||
// (cmdRun, fixSpawn, cmdConnect, etc.) and cannot be tested without
|
||||
|
|
|
|||
|
|
@ -103,19 +103,6 @@ describe("commands/run.ts coverage", () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ── cmdRun with swapped arguments ─────────────────────────────────────
|
||||
|
||||
describe("cmdRun detectAndFixSwappedArgs", () => {
|
||||
it("detects and fixes swapped agent/cloud arguments in dry run", async () => {
|
||||
global.fetch = mock(async () => new Response(JSON.stringify(mockManifest)));
|
||||
await loadManifest(true);
|
||||
// Pass cloud name as agent, agent name as cloud
|
||||
await cmdRun("sprite", "claude", undefined, true);
|
||||
// Should still succeed as dry run (swap detection fixes it)
|
||||
expect(clack.logInfo).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
// ── cmdRun additional ─────────────────────────────────────────────
|
||||
|
||||
describe("cmdRun validation", () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue