Skip to content

Commit 73ab90f

Browse files
la14-1spawn-qa-bot
andauthored
test: remove duplicate getSpawnDir/getHistoryPath tests from history.test.ts (#2426)
These path-utility tests were duplicated between history.test.ts and paths.test.ts. Consolidate into paths.test.ts (the canonical location) and move 4 unique test cases (dot-relative path, .. resolution, outside home rejection, home-as-SPAWN_HOME) that only existed in history.test.ts. Removes 64 lines of duplicate test code with zero coverage loss. Co-authored-by: spawn-qa-bot <qa@openrouter.ai>
1 parent 0126319 commit 73ab90f

2 files changed

Lines changed: 21 additions & 64 deletions

File tree

packages/cli/src/__tests__/history.test.ts

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { afterEach, beforeEach, describe, expect, it } from "bun:test";
44
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
55
import { join } from "node:path";
66
import { filterHistory, HISTORY_SCHEMA_VERSION, loadHistory, saveSpawnRecord } from "../history.js";
7-
import { getHistoryPath, getSpawnDir, getUserHome } from "../shared/paths.js";
87

98
describe("history", () => {
109
let testDir: string;
@@ -32,69 +31,6 @@ describe("history", () => {
3231
}
3332
});
3433

35-
// ── getSpawnDir ─────────────────────────────────────────────────────────
36-
37-
describe("getSpawnDir", () => {
38-
it("returns SPAWN_HOME when set to valid path within home", () => {
39-
const validPath = join(process.env.HOME ?? "", "custom", "spawn", "dir");
40-
process.env.SPAWN_HOME = validPath;
41-
expect(getSpawnDir()).toBe(validPath);
42-
});
43-
44-
it("falls back to ~/.spawn when SPAWN_HOME is not set", () => {
45-
delete process.env.SPAWN_HOME;
46-
expect(getSpawnDir()).toBe(join(getUserHome(), ".spawn"));
47-
});
48-
49-
it("throws for relative SPAWN_HOME path", () => {
50-
process.env.SPAWN_HOME = "relative/path";
51-
expect(() => getSpawnDir()).toThrow("must be an absolute path");
52-
});
53-
54-
it("throws for dot-relative SPAWN_HOME path", () => {
55-
process.env.SPAWN_HOME = "./local/dir";
56-
expect(() => getSpawnDir()).toThrow("must be an absolute path");
57-
});
58-
59-
it("resolves .. segments in absolute SPAWN_HOME within home", () => {
60-
const pathWithDots = join(process.env.HOME ?? "", "foo", "..", "bar");
61-
process.env.SPAWN_HOME = pathWithDots;
62-
expect(getSpawnDir()).toBe(join(process.env.HOME ?? "", "bar"));
63-
});
64-
65-
it("accepts normal absolute SPAWN_HOME within home", () => {
66-
const validPath = join(process.env.HOME ?? "", ".spawn");
67-
process.env.SPAWN_HOME = validPath;
68-
expect(getSpawnDir()).toBe(validPath);
69-
});
70-
71-
it("throws for SPAWN_HOME outside home directory", () => {
72-
process.env.SPAWN_HOME = "/tmp/spawn";
73-
expect(() => getSpawnDir()).toThrow("must be within your home directory");
74-
});
75-
76-
it("throws for path traversal attempt to escape home directory", () => {
77-
// Attempt to traverse outside home using .. segments
78-
// e.g., /home/user/../../etc/.spawn
79-
const traversalPath = join(process.env.HOME ?? "", "..", "..", "etc", ".spawn");
80-
process.env.SPAWN_HOME = traversalPath;
81-
expect(() => getSpawnDir()).toThrow("must be within your home directory");
82-
});
83-
84-
it("accepts home directory itself as SPAWN_HOME", () => {
85-
process.env.SPAWN_HOME = process.env.HOME ?? "";
86-
expect(getSpawnDir()).toBe(process.env.HOME ?? "");
87-
});
88-
});
89-
90-
// ── getHistoryPath ──────────────────────────────────────────────────────
91-
92-
describe("getHistoryPath", () => {
93-
it("returns history.json inside spawn dir", () => {
94-
expect(getHistoryPath()).toBe(join(testDir, "history.json"));
95-
});
96-
});
97-
9834
// ── loadHistory ─────────────────────────────────────────────────────────
9935

10036
describe("loadHistory", () => {

packages/cli/src/__tests__/paths.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,31 @@ describe("paths", () => {
5555
expect(() => getSpawnDir()).toThrow("must be an absolute path");
5656
});
5757

58+
it("rejects dot-relative SPAWN_HOME", () => {
59+
process.env.SPAWN_HOME = "./local/dir";
60+
expect(() => getSpawnDir()).toThrow("must be an absolute path");
61+
});
62+
63+
it("resolves .. segments in absolute SPAWN_HOME within home", () => {
64+
const pathWithDots = join(getUserHome(), "foo", "..", "bar");
65+
process.env.SPAWN_HOME = pathWithDots;
66+
expect(getSpawnDir()).toBe(join(getUserHome(), "bar"));
67+
});
68+
69+
it("rejects SPAWN_HOME outside home directory", () => {
70+
process.env.SPAWN_HOME = "/tmp/spawn";
71+
expect(() => getSpawnDir()).toThrow("must be within your home directory");
72+
});
73+
5874
it("rejects path traversal outside home directory", () => {
5975
process.env.SPAWN_HOME = "/tmp/../../root/.spawn";
6076
expect(() => getSpawnDir()).toThrow("must be within your home directory");
6177
});
78+
79+
it("accepts home directory itself as SPAWN_HOME", () => {
80+
process.env.SPAWN_HOME = getUserHome();
81+
expect(getSpawnDir()).toBe(getUserHome());
82+
});
6283
});
6384

6485
describe("getHistoryPath", () => {

0 commit comments

Comments
 (0)