@@ -4,7 +4,6 @@ import { afterEach, beforeEach, describe, expect, it } from "bun:test";
44import { existsSync , mkdirSync , readFileSync , rmSync , writeFileSync } from "node:fs" ;
55import { join } from "node:path" ;
66import { filterHistory , HISTORY_SCHEMA_VERSION , loadHistory , saveSpawnRecord } from "../history.js" ;
7- import { getHistoryPath , getSpawnDir , getUserHome } from "../shared/paths.js" ;
87
98describe ( "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" , ( ) => {
0 commit comments