|
7 | 7 | * settable alone via PUT (legacy codexAutoStart-only PUTs keep working). |
8 | 8 | */ |
9 | 9 | import { afterEach, beforeEach, describe, expect, test } from "bun:test"; |
10 | | -import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; |
| 10 | +import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; |
| 11 | +import { tmpdir } from "node:os"; |
11 | 12 | import { join } from "node:path"; |
12 | 13 | import { getConfigPath, loadConfig, saveConfig } from "../src/config"; |
13 | 14 | import { handleManagementAPI } from "../src/server/management-api"; |
14 | 15 | import type { OcxConfig } from "../src/types"; |
15 | 16 |
|
16 | | -const TEST_DIR = join(import.meta.dir, ".tmp-settings-stream-mode-test"); |
17 | 17 | const previousHome = process.env.OPENCODEX_HOME; |
| 18 | +let testDir = ""; |
18 | 19 |
|
19 | 20 | function baseConfig(): OcxConfig { |
20 | 21 | return { |
@@ -46,15 +47,15 @@ function getSettings(config: OcxConfig): Promise<Response | null> { |
46 | 47 | } |
47 | 48 |
|
48 | 49 | beforeEach(() => { |
49 | | - if (existsSync(TEST_DIR)) rmSync(TEST_DIR, { recursive: true }); |
50 | | - mkdirSync(TEST_DIR, { recursive: true }); |
51 | | - process.env.OPENCODEX_HOME = TEST_DIR; |
| 50 | + testDir = mkdtempSync(join(tmpdir(), "ocx-settings-stream-mode-")); |
| 51 | + process.env.OPENCODEX_HOME = testDir; |
52 | 52 | }); |
53 | 53 |
|
54 | 54 | afterEach(() => { |
55 | 55 | if (previousHome === undefined) delete process.env.OPENCODEX_HOME; |
56 | 56 | else process.env.OPENCODEX_HOME = previousHome; |
57 | | - if (existsSync(TEST_DIR)) rmSync(TEST_DIR, { recursive: true }); |
| 57 | + if (testDir && existsSync(testDir)) rmSync(testDir, { recursive: true, force: true }); |
| 58 | + testDir = ""; |
58 | 59 | }); |
59 | 60 |
|
60 | 61 | describe("GET /api/settings", () => { |
|
0 commit comments