diff --git a/packages/cli/src/__tests__/history.test.ts b/packages/cli/src/__tests__/history.test.ts index da8624af..7e60d1a2 100644 --- a/packages/cli/src/__tests__/history.test.ts +++ b/packages/cli/src/__tests__/history.test.ts @@ -1,5 +1,6 @@ import { describe, it, expect, beforeEach, afterEach } from "bun:test"; import { existsSync, mkdirSync, rmSync, writeFileSync, readFileSync } from "node:fs"; +import { homedir } from "node:os"; import { join } from "node:path"; import type { SpawnRecord } from "../history.js"; import { getSpawnDir, getHistoryPath, loadHistory, saveSpawnRecord, filterHistory } from "../history.js"; @@ -10,7 +11,6 @@ describe("history", () => { beforeEach(() => { // Use a directory within home directory for testing (required by security validation) - const { homedir } = require("node:os"); testDir = join(homedir(), `.spawn-test-${Date.now()}-${Math.random()}`); mkdirSync(testDir, { recursive: true, @@ -35,7 +35,6 @@ describe("history", () => { describe("getSpawnDir", () => { it("returns SPAWN_HOME when set to valid path within home", () => { - const { homedir } = require("node:os"); const validPath = join(homedir(), "custom", "spawn", "dir"); process.env.SPAWN_HOME = validPath; expect(getSpawnDir()).toBe(validPath); @@ -43,7 +42,6 @@ describe("history", () => { it("falls back to ~/.spawn when SPAWN_HOME is not set", () => { delete process.env.SPAWN_HOME; - const { homedir } = require("node:os"); expect(getSpawnDir()).toBe(join(homedir(), ".spawn")); }); @@ -58,14 +56,12 @@ describe("history", () => { }); it("resolves .. segments in absolute SPAWN_HOME within home", () => { - const { homedir } = require("node:os"); const pathWithDots = join(homedir(), "foo", "..", "bar"); process.env.SPAWN_HOME = pathWithDots; expect(getSpawnDir()).toBe(join(homedir(), "bar")); }); it("accepts normal absolute SPAWN_HOME within home", () => { - const { homedir } = require("node:os"); const validPath = join(homedir(), ".spawn"); process.env.SPAWN_HOME = validPath; expect(getSpawnDir()).toBe(validPath); @@ -77,7 +73,6 @@ describe("history", () => { }); it("throws for SPAWN_HOME pointing to /root when user home is different", () => { - const { homedir } = require("node:os"); // Only run this test if we're not actually running as root if (homedir() !== "/root") { process.env.SPAWN_HOME = "/root/.spawn"; @@ -86,7 +81,6 @@ describe("history", () => { }); it("throws for path traversal attempt to escape home directory", () => { - const { homedir } = require("node:os"); // Attempt to traverse outside home using .. segments // e.g., /home/user/../../etc/.spawn const traversalPath = join(homedir(), "..", "..", "etc", ".spawn"); @@ -95,7 +89,6 @@ describe("history", () => { }); it("accepts home directory itself as SPAWN_HOME", () => { - const { homedir } = require("node:os"); process.env.SPAWN_HOME = homedir(); expect(getSpawnDir()).toBe(homedir()); }); @@ -205,7 +198,6 @@ describe("history", () => { describe("saveSpawnRecord", () => { it("creates directory and file when neither exist", () => { - const { homedir } = require("node:os"); const nestedDir = join(homedir(), ".spawn-test", "nested", "spawn"); process.env.SPAWN_HOME = nestedDir;