// Runs before any test module is evaluated (see the --preload flag in the // "test" script). // // src/db/index.ts opens the database and runs migrations in its module body, // and src/config.ts reads DATA_DIR in its own. Both happen while imports are // still being hoisted, i.e. before any statement in a test file or in // helpers.ts can assign to config. Pointing DATA_DIR at a per-worker path // here is the only way to get in front of that — otherwise every parallel // worker opens the real ./data/hearthforge.db and they contend for the write // lock ("SQLiteError: database is locked"). const worker = process.env.BUN_TEST_WORKER_ID; process.env.DATA_DIR = worker ? `./data-test-${worker}` : "./data-test"; // One highlight worker per test process is plenty, and the pool is only // built if a test actually highlights something. process.env.HIGHLIGHT_WORKERS ??= "1";