import { tmpdir } from 'node:os'; import { join } from 'node:path'; /** * The neutral database path the test preload arms `CELILO_DB_PATH` with * (celilo#1315). The file does not exist, so a reader falls into whatever * "no database" branch its feature has — and no test ever opens the * operator's real `~/Library/.../celilo.db`, which is what a suite that * reads the variable without setting it would otherwise reach. * * Why teardowns RESET to this path instead of `delete`: bunfig's `[test]` * preload runs ONCE PER PROCESS, not once per test file. A teardown that * clears the variable leaves every later var-less reader on the real * database for the rest of the run. Resetting to the scratch path keeps the * preload's invariant standing from the first test to the last. */ export const SCRATCH_DB_PATH = join(tmpdir(), 'celilo-test-absent.db'); /** * Point `CELILO_DB_PATH` at the neutral scratch path. Call from a test's * afterEach (or any teardown) that pointed the variable somewhere else. */ export function resetTestDbPath(): void { process.env.CELILO_DB_PATH = SCRATCH_DB_PATH; }