2026-09-19 12:37:57 +08:00
|
|
|
// Global test isolation: never let the unit/translator suite write to the user's
|
|
|
|
|
// real database (~/.9router). Some tests (e.g. zed-live-models, zed-native-auth)
|
|
|
|
|
// exercise real route handlers that call createProviderConnection — without this
|
|
|
|
|
// they append test rows ("zed-live-*@example.com", "guard-*@example.com",
|
|
|
|
|
// "Account N") straight into the live DB.
|
|
|
|
|
//
|
2026-09-19 12:52:19 +08:00
|
|
|
// GUARD — DO NOT DELETE this file or remove it from vitest.config.js setupFiles.
|
|
|
|
|
// See AGENTS.md §2. Covered by tests/unit/test-data-dir-isolation.test.js.
|
|
|
|
|
//
|
2026-09-19 12:37:57 +08:00
|
|
|
// DATA_DIR must be set before src/lib/dataDir.js is imported (it reads the env
|
|
|
|
|
// at module-eval time), which is exactly what a vitest setupFile guarantees.
|
|
|
|
|
//
|
|
|
|
|
// Escape hatches:
|
|
|
|
|
// - RUN_REAL=1 → keep the real DATA_DIR so *.real.test.js can read it.
|
|
|
|
|
// - DATA_DIR=<path> → respect an explicit override (CI / manual isolation).
|
|
|
|
|
import fs from "node:fs";
|
|
|
|
|
import os from "node:os";
|
|
|
|
|
import path from "node:path";
|
|
|
|
|
|
|
|
|
|
const RUN_REAL = process.env.RUN_REAL === "1";
|
|
|
|
|
const explicit = process.env.DATA_DIR;
|
|
|
|
|
|
|
|
|
|
if (!RUN_REAL && !explicit) {
|
|
|
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "9router-test-"));
|
|
|
|
|
process.env.DATA_DIR = dir;
|
|
|
|
|
process.on("exit", () => {
|
|
|
|
|
try { fs.rmSync(dir, { recursive: true, force: true }); } catch { /* best effort */ }
|
|
|
|
|
});
|
|
|
|
|
}
|