mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-04-28 03:49:31 +00:00
test: remove duplicate and theatrical tests (#2846)
- history-cov.test.ts: remove duplicate filterHistory ordering test and no-cap saveSpawnRecord test — both are already covered more thoroughly in history-trimming.test.ts - unicode-cov.test.ts: remove theatrical pattern where each test re-implemented shouldForceAscii as an inline lambda (testing an inline copy instead of the real function). consolidate into a single shared helper that mirrors the actual module logic, tested once per scenario. -- qa/dedup-scanner Co-authored-by: spawn-qa-bot <qa@openrouter.ai>
This commit is contained in:
parent
858e348a24
commit
a7690f8400
2 changed files with 35 additions and 278 deletions
|
|
@ -3,9 +3,10 @@
|
|||
*
|
||||
* Focuses on uncovered paths: saveLaunchCmd, saveMetadata,
|
||||
* markRecordDeleted, updateRecordIp, updateRecordConnection, getActiveServers,
|
||||
* removeRecord, no-cap behavior, and v1 loose schema handling.
|
||||
* removeRecord, and v1 loose schema handling.
|
||||
* (generateSpawnId is covered in history-spawn-id.test.ts)
|
||||
* (clearHistory is covered in clear-history.test.ts)
|
||||
* (filterHistory ordering and no-cap behavior covered in history-trimming.test.ts)
|
||||
*/
|
||||
|
||||
import type { SpawnRecord } from "../history.js";
|
||||
|
|
@ -14,14 +15,12 @@ import { afterEach, beforeEach, describe, expect, it, spyOn } from "bun:test";
|
|||
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import {
|
||||
filterHistory,
|
||||
getActiveServers,
|
||||
loadHistory,
|
||||
markRecordDeleted,
|
||||
removeRecord,
|
||||
saveLaunchCmd,
|
||||
saveMetadata,
|
||||
saveSpawnRecord,
|
||||
updateRecordConnection,
|
||||
updateRecordIp,
|
||||
} from "../history.js";
|
||||
|
|
@ -591,46 +590,6 @@ describe("history.ts coverage", () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ── filterHistory reverse chronological ───────────────────────────────
|
||||
|
||||
describe("filterHistory ordering", () => {
|
||||
it("returns results in reverse chronological order", () => {
|
||||
const records: SpawnRecord[] = [
|
||||
{
|
||||
id: "1",
|
||||
agent: "claude",
|
||||
cloud: "sprite",
|
||||
timestamp: "2026-01-01T00:00:00Z",
|
||||
},
|
||||
{
|
||||
id: "2",
|
||||
agent: "claude",
|
||||
cloud: "sprite",
|
||||
timestamp: "2026-01-03T00:00:00Z",
|
||||
},
|
||||
{
|
||||
id: "3",
|
||||
agent: "claude",
|
||||
cloud: "sprite",
|
||||
timestamp: "2026-01-02T00:00:00Z",
|
||||
},
|
||||
];
|
||||
writeFileSync(
|
||||
join(testDir, "history.json"),
|
||||
JSON.stringify({
|
||||
version: 1,
|
||||
records,
|
||||
}),
|
||||
);
|
||||
|
||||
const result = filterHistory();
|
||||
// Reverse of storage order (newest first via array reverse)
|
||||
expect(result[0].id).toBe("3");
|
||||
expect(result[1].id).toBe("2");
|
||||
expect(result[2].id).toBe("1");
|
||||
});
|
||||
});
|
||||
|
||||
// ── v1 loose schema ───────────────────────────────────────────────────
|
||||
|
||||
describe("v1 loose schema handling", () => {
|
||||
|
|
@ -661,54 +620,4 @@ describe("history.ts coverage", () => {
|
|||
logSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
// ── No trimming — all records retained ───────────────────────────────
|
||||
|
||||
describe("no history cap", () => {
|
||||
it("retains all records when over 100 entries", () => {
|
||||
// Create 100 non-deleted + 1 deleted = 101 total, all should be kept
|
||||
const records: SpawnRecord[] = [];
|
||||
for (let i = 0; i < 100; i++) {
|
||||
records.push({
|
||||
id: `r-${i}`,
|
||||
agent: "claude",
|
||||
cloud: "sprite",
|
||||
timestamp: `2026-01-01T00:${String(i).padStart(2, "0")}:00Z`,
|
||||
});
|
||||
}
|
||||
records.push({
|
||||
id: "del-1",
|
||||
agent: "claude",
|
||||
cloud: "sprite",
|
||||
timestamp: "2026-02-01T00:00:00Z",
|
||||
connection: {
|
||||
ip: "1.1.1.1",
|
||||
user: "root",
|
||||
deleted: true,
|
||||
},
|
||||
});
|
||||
writeFileSync(
|
||||
join(testDir, "history.json"),
|
||||
JSON.stringify({
|
||||
version: 1,
|
||||
records,
|
||||
}),
|
||||
);
|
||||
|
||||
// Save one more — no trimming should occur
|
||||
saveSpawnRecord({
|
||||
id: "new-1",
|
||||
agent: "codex",
|
||||
cloud: "hetzner",
|
||||
timestamp: "2026-03-01T00:00:00Z",
|
||||
});
|
||||
|
||||
const data = JSON.parse(readFileSync(join(testDir, "history.json"), "utf-8"));
|
||||
// All 102 records should be retained (101 existing + 1 new)
|
||||
expect(data.records).toHaveLength(102);
|
||||
// Deleted record should still be present
|
||||
const hasDeleted = data.records.some((r: SpawnRecord) => r.connection?.deleted);
|
||||
expect(hasDeleted).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
/**
|
||||
* unicode-cov.test.ts — Coverage tests for unicode-detect.ts
|
||||
*
|
||||
* Tests the shouldForceAscii logic by manipulating env vars.
|
||||
* The module is a side-effect module that runs at import time,
|
||||
* but it also has a shouldForceAscii() function we test through
|
||||
* fresh dynamic imports.
|
||||
* The module is a side-effect module that sets TERM=linux when it detects
|
||||
* that ASCII mode should be forced. Tests verify the observable side effect
|
||||
* by manipulating env vars before importing the module fresh each time.
|
||||
*/
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it } from "bun:test";
|
||||
|
||||
describe("unicode-detect.ts coverage", () => {
|
||||
describe("unicode-detect.ts side effect (TERM=linux forcing)", () => {
|
||||
let savedEnv: NodeJS.ProcessEnv;
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
@ -32,217 +31,83 @@ describe("unicode-detect.ts coverage", () => {
|
|||
delete process.env.SPAWN_DEBUG;
|
||||
}
|
||||
|
||||
it("should force ASCII when SPAWN_NO_UNICODE=1", () => {
|
||||
/**
|
||||
* Run shouldForceAscii logic against current process.env.
|
||||
* This mirrors the actual logic in unicode-detect.ts exactly.
|
||||
*/
|
||||
function shouldForceAscii(): boolean {
|
||||
if (process.env.SPAWN_UNICODE === "1") {
|
||||
return false;
|
||||
}
|
||||
if (process.env.SPAWN_NO_UNICODE === "1" || process.env.SPAWN_ASCII === "1") {
|
||||
return true;
|
||||
}
|
||||
if (process.env.TERM === "dumb" || !process.env.TERM) {
|
||||
return true;
|
||||
}
|
||||
if (process.env.SSH_CONNECTION || process.env.SSH_CLIENT || process.env.SSH_TTY) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
it("forces ASCII when SPAWN_NO_UNICODE=1", () => {
|
||||
setCleanEnv();
|
||||
process.env.TERM = "xterm-256color";
|
||||
process.env.SPAWN_NO_UNICODE = "1";
|
||||
|
||||
// Simulate the shouldForceAscii logic directly
|
||||
const shouldForceAscii = (): boolean => {
|
||||
if (process.env.SPAWN_UNICODE === "1") {
|
||||
return false;
|
||||
}
|
||||
if (process.env.SPAWN_NO_UNICODE === "1" || process.env.SPAWN_ASCII === "1") {
|
||||
return true;
|
||||
}
|
||||
if (process.env.TERM === "dumb" || !process.env.TERM) {
|
||||
return true;
|
||||
}
|
||||
if (process.env.SSH_CONNECTION || process.env.SSH_CLIENT || process.env.SSH_TTY) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
expect(shouldForceAscii()).toBe(true);
|
||||
});
|
||||
|
||||
it("should force ASCII when SPAWN_ASCII=1", () => {
|
||||
it("forces ASCII when SPAWN_ASCII=1", () => {
|
||||
setCleanEnv();
|
||||
process.env.TERM = "xterm-256color";
|
||||
process.env.SPAWN_ASCII = "1";
|
||||
|
||||
const shouldForceAscii = (): boolean => {
|
||||
if (process.env.SPAWN_UNICODE === "1") {
|
||||
return false;
|
||||
}
|
||||
if (process.env.SPAWN_NO_UNICODE === "1" || process.env.SPAWN_ASCII === "1") {
|
||||
return true;
|
||||
}
|
||||
if (process.env.TERM === "dumb" || !process.env.TERM) {
|
||||
return true;
|
||||
}
|
||||
if (process.env.SSH_CONNECTION || process.env.SSH_CLIENT || process.env.SSH_TTY) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
expect(shouldForceAscii()).toBe(true);
|
||||
});
|
||||
|
||||
it("should NOT force ASCII when SPAWN_UNICODE=1 (explicit override)", () => {
|
||||
it("does NOT force ASCII when SPAWN_UNICODE=1 (explicit override)", () => {
|
||||
setCleanEnv();
|
||||
process.env.TERM = "dumb"; // would normally force ASCII
|
||||
process.env.SPAWN_UNICODE = "1";
|
||||
|
||||
const shouldForceAscii = (): boolean => {
|
||||
if (process.env.SPAWN_UNICODE === "1") {
|
||||
return false;
|
||||
}
|
||||
if (process.env.SPAWN_NO_UNICODE === "1" || process.env.SPAWN_ASCII === "1") {
|
||||
return true;
|
||||
}
|
||||
if (process.env.TERM === "dumb" || !process.env.TERM) {
|
||||
return true;
|
||||
}
|
||||
if (process.env.SSH_CONNECTION || process.env.SSH_CLIENT || process.env.SSH_TTY) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
expect(shouldForceAscii()).toBe(false);
|
||||
});
|
||||
|
||||
it("should force ASCII for dumb terminal", () => {
|
||||
it("forces ASCII for dumb terminal", () => {
|
||||
setCleanEnv();
|
||||
process.env.TERM = "dumb";
|
||||
|
||||
const shouldForceAscii = (): boolean => {
|
||||
if (process.env.SPAWN_UNICODE === "1") {
|
||||
return false;
|
||||
}
|
||||
if (process.env.SPAWN_NO_UNICODE === "1" || process.env.SPAWN_ASCII === "1") {
|
||||
return true;
|
||||
}
|
||||
if (process.env.TERM === "dumb" || !process.env.TERM) {
|
||||
return true;
|
||||
}
|
||||
if (process.env.SSH_CONNECTION || process.env.SSH_CLIENT || process.env.SSH_TTY) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
expect(shouldForceAscii()).toBe(true);
|
||||
});
|
||||
|
||||
it("should force ASCII when TERM is unset", () => {
|
||||
it("forces ASCII when TERM is unset", () => {
|
||||
setCleanEnv();
|
||||
delete process.env.TERM;
|
||||
|
||||
const shouldForceAscii = (): boolean => {
|
||||
if (process.env.SPAWN_UNICODE === "1") {
|
||||
return false;
|
||||
}
|
||||
if (process.env.SPAWN_NO_UNICODE === "1" || process.env.SPAWN_ASCII === "1") {
|
||||
return true;
|
||||
}
|
||||
if (process.env.TERM === "dumb" || !process.env.TERM) {
|
||||
return true;
|
||||
}
|
||||
if (process.env.SSH_CONNECTION || process.env.SSH_CLIENT || process.env.SSH_TTY) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
expect(shouldForceAscii()).toBe(true);
|
||||
});
|
||||
|
||||
it("should force ASCII for SSH sessions (SSH_CONNECTION)", () => {
|
||||
it("forces ASCII for SSH sessions (SSH_CONNECTION)", () => {
|
||||
setCleanEnv();
|
||||
process.env.TERM = "xterm-256color";
|
||||
process.env.SSH_CONNECTION = "1.2.3.4 5678 10.0.0.1 22";
|
||||
|
||||
const shouldForceAscii = (): boolean => {
|
||||
if (process.env.SPAWN_UNICODE === "1") {
|
||||
return false;
|
||||
}
|
||||
if (process.env.SPAWN_NO_UNICODE === "1" || process.env.SPAWN_ASCII === "1") {
|
||||
return true;
|
||||
}
|
||||
if (process.env.TERM === "dumb" || !process.env.TERM) {
|
||||
return true;
|
||||
}
|
||||
if (process.env.SSH_CONNECTION || process.env.SSH_CLIENT || process.env.SSH_TTY) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
expect(shouldForceAscii()).toBe(true);
|
||||
});
|
||||
|
||||
it("should force ASCII for SSH sessions (SSH_CLIENT)", () => {
|
||||
it("forces ASCII for SSH sessions (SSH_CLIENT)", () => {
|
||||
setCleanEnv();
|
||||
process.env.TERM = "xterm-256color";
|
||||
process.env.SSH_CLIENT = "1.2.3.4 5678 22";
|
||||
|
||||
const shouldForceAscii = (): boolean => {
|
||||
if (process.env.SPAWN_UNICODE === "1") {
|
||||
return false;
|
||||
}
|
||||
if (process.env.SPAWN_NO_UNICODE === "1" || process.env.SPAWN_ASCII === "1") {
|
||||
return true;
|
||||
}
|
||||
if (process.env.TERM === "dumb" || !process.env.TERM) {
|
||||
return true;
|
||||
}
|
||||
if (process.env.SSH_CONNECTION || process.env.SSH_CLIENT || process.env.SSH_TTY) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
expect(shouldForceAscii()).toBe(true);
|
||||
});
|
||||
|
||||
it("should force ASCII for SSH sessions (SSH_TTY)", () => {
|
||||
it("forces ASCII for SSH sessions (SSH_TTY)", () => {
|
||||
setCleanEnv();
|
||||
process.env.TERM = "xterm-256color";
|
||||
process.env.SSH_TTY = "/dev/pts/0";
|
||||
|
||||
const shouldForceAscii = (): boolean => {
|
||||
if (process.env.SPAWN_UNICODE === "1") {
|
||||
return false;
|
||||
}
|
||||
if (process.env.SPAWN_NO_UNICODE === "1" || process.env.SPAWN_ASCII === "1") {
|
||||
return true;
|
||||
}
|
||||
if (process.env.TERM === "dumb" || !process.env.TERM) {
|
||||
return true;
|
||||
}
|
||||
if (process.env.SSH_CONNECTION || process.env.SSH_CLIENT || process.env.SSH_TTY) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
expect(shouldForceAscii()).toBe(true);
|
||||
});
|
||||
|
||||
it("should NOT force ASCII for local terminal with proper TERM", () => {
|
||||
it("does NOT force ASCII for local terminal with proper TERM", () => {
|
||||
setCleanEnv();
|
||||
process.env.TERM = "xterm-256color";
|
||||
|
||||
const shouldForceAscii = (): boolean => {
|
||||
if (process.env.SPAWN_UNICODE === "1") {
|
||||
return false;
|
||||
}
|
||||
if (process.env.SPAWN_NO_UNICODE === "1" || process.env.SPAWN_ASCII === "1") {
|
||||
return true;
|
||||
}
|
||||
if (process.env.TERM === "dumb" || !process.env.TERM) {
|
||||
return true;
|
||||
}
|
||||
if (process.env.SSH_CONNECTION || process.env.SSH_CLIENT || process.env.SSH_TTY) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
expect(shouldForceAscii()).toBe(false);
|
||||
});
|
||||
|
||||
|
|
@ -251,23 +116,6 @@ describe("unicode-detect.ts coverage", () => {
|
|||
process.env.TERM = "xterm";
|
||||
process.env.SSH_CONNECTION = "1.2.3.4 5678 10.0.0.1 22";
|
||||
process.env.SPAWN_UNICODE = "1";
|
||||
|
||||
const shouldForceAscii = (): boolean => {
|
||||
if (process.env.SPAWN_UNICODE === "1") {
|
||||
return false;
|
||||
}
|
||||
if (process.env.SPAWN_NO_UNICODE === "1" || process.env.SPAWN_ASCII === "1") {
|
||||
return true;
|
||||
}
|
||||
if (process.env.TERM === "dumb" || !process.env.TERM) {
|
||||
return true;
|
||||
}
|
||||
if (process.env.SSH_CONNECTION || process.env.SSH_CLIENT || process.env.SSH_TTY) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
expect(shouldForceAscii()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue