Skip to content

Commit a55a156

Browse files
fix(storage): keep GORDON_DIR a pure path and ensure the dir at write time, not import time
1 parent 5378065 commit a55a156

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/infra/storage/paths.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ let ensuredDir: string | null = null;
3030
*/
3131
export function ensureGordonHome(): string {
3232
const dir = resolveGordonDir();
33+
// Re-check whenever the resolved dir changes (tests point GORDON_HOME at a
34+
// temp dir per case) or the directory has since been removed.
3335
if (dir !== ensuredDir || !existsSync(dir)) {
3436
try {
3537
mkdirSync(dir, { recursive: true });
@@ -56,5 +58,12 @@ export function getGordonDir(): string {
5658
return ensureGordonHome();
5759
}
5860

59-
/** Pre-resolved Gordon directory for the current process */
60-
export const GORDON_DIR = getGordonDir();
61+
/**
62+
* Pre-resolved Gordon directory for the current process.
63+
*
64+
* Deliberately a PURE path computation: doing filesystem I/O at module-import
65+
* time runs before any test's setup can redirect the home, and the resulting
66+
* first-import path would be cached for the whole process. Directory creation
67+
* happens at write time via ensureGordonHome() / getGordonDir() instead.
68+
*/
69+
export const GORDON_DIR = resolveGordonDir();

0 commit comments

Comments
 (0)