From 4522ec6a0c896d221b590179a35194a1e0076aef Mon Sep 17 00:00:00 2001 From: Moses Man <56060463+mosesman831@users.noreply.github.com> Date: Sat, 10 Oct 2026 12:40:54 +0000 Subject: [PATCH] fix(cli): resolve golden bench fixtures relative to package, not cwd lexloop bench golden resolved the default fixtures/golden dir against process.cwd(), so running it from anywhere but the repo root silently found zero fixtures and reported an all-zero result. Resolve the corpus relative to the module location instead (walk up from import.meta.url until fixtures/golden exists; works from the bundled dist/cli.js and from the source tree alike) and fail loudly with LL4005 when a fixture dir yields zero files. Explicit --dir still resolves against cwd. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- bench/golden.ts | 39 ++++++++++++++++++++++++++---- packages/cli/src/commands/bench.ts | 14 +++++++---- 2 files changed, 43 insertions(+), 10 deletions(-) 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