diff --git a/bench/golden.ts b/bench/golden.ts index 67fe115..96bd965 100644 --- a/bench/golden.ts +++ b/bench/golden.ts @@ -1,5 +1,6 @@ -import { readdirSync, readFileSync } from "node:fs"; -import { join } from "node:path"; +import { existsSync, readdirSync, readFileSync } from "node:fs"; +import { dirname, join, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; import { RunState, buildIntervention, @@ -195,6 +196,24 @@ export async function replayFixture(fixture: GoldenFixture): Promise { - const loopFiles = listJsonFiles(join(dir, "loops")); - const productiveFiles = listJsonFiles(join(dir, "productive")); + const root = dir ?? defaultGoldenDir(); + const loopFiles = listJsonFiles(join(root, "loops")); + const productiveFiles = listJsonFiles(join(root, "productive")); + if (loopFiles.length === 0 && productiveFiles.length === 0) { + throw Object.assign( + new Error( + `LL4005 no golden fixtures found under ${root} ` + + `(expected .json files in ${join(root, "loops")} and ${join(root, "productive")})`, + ), + { code: "LL4005" }, + ); + } const detectMs: number[] = []; const replays: GoldenReplay[] = []; diff --git a/packages/cli/src/commands/bench.ts b/packages/cli/src/commands/bench.ts index d0f65df..65dbe3a 100644 --- a/packages/cli/src/commands/bench.ts +++ b/packages/cli/src/commands/bench.ts @@ -1,6 +1,7 @@ import type { Command } from "commander"; import { goldenPassed, runGoldenBench } from "../../../../bench/golden.ts"; import { CI_FAIL_MS, detectLoadPassed, runDetectLoad } from "../../../../bench/detect_load.ts"; +import { exitWith, formatUnknown } from "../exit.ts"; export function addBenchCommand(program: Command): void { const bench = program.command("bench").description("Golden corpus and detect load bench"); @@ -8,12 +9,15 @@ export function addBenchCommand(program: Command): void { bench .command("golden") .description("Replay fixtures/golden") - .option("--dir ", "fixtures/golden", "fixtures/golden") + .option("--dir ", "golden fixture dir (default: /fixtures/golden)") .action(async (opts: { dir?: string }) => { - const dir = opts.dir ?? "fixtures/golden"; - const { result } = await runGoldenBench(dir); - process.stdout.write(`${JSON.stringify(result, null, 2)}\n`); - if (!goldenPassed(result)) process.exit(3); + try { + const { result } = await runGoldenBench(opts.dir); + process.stdout.write(`${JSON.stringify(result, null, 2)}\n`); + if (!goldenPassed(result)) process.exit(3); + } catch (err) { + exitWith(2, formatUnknown(err)); + } }); bench