{"record":{"id":"ffe4ce886a2a3ece","repo":"tobi/qmd","slug":"database-path-not-set-tests-must-set-index-path-e","errorCode":null,"errorMessage":"Database path not set. Tests must set INDEX_PATH env var or use createStore() with explicit path. This prevents tests from accidentally writing to the global index.","messagePattern":"Database path not set\\. Tests must set INDEX_PATH env var or use createStore\\(\\) with explicit path\\. This prevents tests from accidentally writing to the global index\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/store.ts","lineNumber":644,"sourceCode":"\nexport function enableProductionMode(): void {\n  _productionMode = true;\n}\n\n/** Reset production mode flag — only for testing. */\nexport function _resetProductionModeForTesting(): void {\n  _productionMode = false;\n}\n\nexport function getDefaultDbPath(indexName: string = \"index\"): string {\n  // Always allow override via INDEX_PATH (for testing)\n  if (process.env.INDEX_PATH) {\n    return process.env.INDEX_PATH;\n  }\n\n  // In non-production mode (tests), require explicit path\n  if (!_productionMode) {\n    throw new Error(\n      \"Database path not set. Tests must set INDEX_PATH env var or use createStore() with explicit path. \" +\n      \"This prevents tests from accidentally writing to the global index.\"\n    );\n  }\n\n  const cacheDir = process.env.XDG_CACHE_HOME || resolve(homedir(), \".cache\");\n  const qmdCacheDir = resolve(cacheDir, \"qmd\");\n  try { mkdirSync(qmdCacheDir, { recursive: true }); } catch { }\n  return resolve(qmdCacheDir, `${indexName}.sqlite`);\n}\n\nexport function getPwd(): string {\n  return process.env.PWD || process.cwd();\n}\n\nexport function getRealPath(path: string): string {\n  try {\n    return realpathSync(path);","sourceCodeStart":626,"sourceCodeEnd":662,"githubUrl":"https://github.com/tobi/qmd/blob/dbfd0b4736aeaf761d1a16ca8e424f071df8feb9/src/store.ts#L626-L662","documentation":"getDefaultDbPath() refuses to fall back to the default cache location when not in production mode and INDEX_PATH is unset. This is a safety rail so tests never write to the user's global index.sqlite (~/.cache/qmd/index.sqlite).","triggerScenarios":"Running code in non-production mode (tests, NODE_ENV != production) that constructs a store or calls getDbPath/setIndexName without setting process.env.INDEX_PATH and without passing an explicit path to createStore().","commonSituations":"A new test file forgot the INDEX_PATH setup hook; a script run with NODE_ENV=test; importing store.ts transitively in a dev tool that instantiates a store lazily.","solutions":["Set process.env.INDEX_PATH to a temp file before any store call in tests","Use createStore() with an explicit path argument","Run with production mode enabled if you genuinely want the global index"],"exampleFix":"// before\nconst db = getDbPath(); // throws in tests\n// after\nprocess.env.INDEX_PATH ||= path.join(os.tmpdir(), 'qmd-test.sqlite');\nconst db = getDbPath();","handlingStrategy":"validation","validationCode":"process.env.INDEX_PATH ||= path.join(os.tmpdir(), `qmd-${process.pid}.sqlite`);","typeGuard":null,"tryCatchPattern":"try { const db = createStore(); } catch (e) { if (/INDEX_PATH/.test((e as Error).message)) { process.env.INDEX_PATH = tmp(); return createStore(); } throw e; }","preventionTips":["Set INDEX_PATH in a global test setup/beforeAll","Always pass explicit paths in tests","Assert env is configured before importing store modules"],"tags":["env-var","test-mode","database","configuration"],"backgroundTag":"missing-env-var","analyzedSha":"dbfd0b4736aeaf761d1a16ca8e424f071df8feb9","analyzedAt":"2026-08-28T18:07:46.628Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}