test(harness): isolate DATA_DIR so tests never write to the real DB

Root cause of fake connections in Usage (zed-live-*@example.com,
guard-*@example.com, zed "Account N", kimchi-nope): route-level tests
(zed-live-models, zed-native-auth) call createProviderConnection, which
persists to $DATA_DIR/db/data.sqlite. With DATA_DIR unset — the default
for `npx vitest run` — that resolved to the user's real ~/.9router DB,
appending test rows on every run. Both files documented "RUN WITH AN
ISOLATED DB" but never enforced it.

Add tests/setup/isolateDataDir.js (wired via vitest setupFiles) that
points DATA_DIR at a throwaway temp dir before src/lib/dataDir.js is
imported. Opt out with RUN_REAL=1 or an explicit DATA_DIR (used by the
*.real.test.js suites that read live credentials).

Verified: a full suite run now leaves the real DB byte-count unchanged;
new guard test tests/unit/test-data-dir-isolation.test.js locks it in.
This commit is contained in:
MUH. IQRAM BAHRING
2026-09-19 12:37:57 +08:00
parent 9d7821bdcc
commit 9c37af90a9
3 changed files with 57 additions and 0 deletions
+4
View File
@@ -9,6 +9,10 @@ export default defineConfig({
environment: "node",
globals: true,
include: ["**/*.test.js"],
// Redirect DATA_DIR to a throwaway temp dir so route-level tests that call
// createProviderConnection never touch the user's real ~/.9router DB.
// RUN_REAL=1 or an explicit DATA_DIR opts out (see setup/isolateDataDir.js).
setupFiles: ["./setup/isolateDataDir.js"],
// Don't scan into git worktrees nested under .claude/ — they carry their
// own copies of the test files but lack an installed node_modules (open-sse,
// etc.), which makes provider imports fail during collection.