// Where benchmark files live. Shared by the worker (writes) and the web app (serves reports). import { dirname, join, resolve } from "node:path"; import { coreEnv } from "@/lib/env"; /** BENCHMARKS_DIR, or "benchmarks" next to the SQLite file (e.g. /data/benchmarks). */ export function benchmarksDir(): string { const env = coreEnv(); if (env.BENCHMARKS_DIR) return resolve(env.BENCHMARKS_DIR); const db = env.DATABASE_URL.replace(/^file:/, ""); return resolve(dirname(db), "benchmarks"); } /** Run ids are ULIDs; anything else never becomes a path. */ const RUN_ID_RE = /^[0-9A-HJKMNP-TV-Z]{26}$/; export function runDir(runId: string): string { if (!RUN_ID_RE.test(runId)) throw new Error("invalid run id"); return join(benchmarksDir(), runId); } export const RESULTS_FILE = "results.json"; export const REPORT_FILE = "results.html"; export const AB_FILE = "ab.json";