Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"benchmark:spreadsheetbench:official-v2-project": "tsx scripts/spreadsheetbench-official-v2-project.ts",
"benchmark:spreadsheetbench:refresh-excel": "python scripts/spreadsheetbench-refresh-excel.py",
"benchmark:spreadsheetbench:accept-official-v2": "tsx scripts/spreadsheetbench-accept-official-v2.ts",
"benchmark:spreadsheetbench:v2-quality-gate": "tsx scripts/spreadsheetbench-v2-quality-gate.ts",
"benchmark:spreadsheetbench:visible-repair-replay": "tsx scripts/spreadsheetbench-visible-repair-replay.ts",
"benchmark:spreadsheetbench:project-model-report": "tsx scripts/spreadsheetbench-project-model-report.ts",
"benchmark:spreadsheetbench:score": "tsx scripts/spreadsheetbench-score.ts",
Expand Down
96 changes: 96 additions & 0 deletions scripts/spreadsheetbench-v2-quality-gate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { mkdirSync, writeFileSync } from "node:fs";
import { dirname, relative, resolve } from "node:path";
import {
buildSpreadsheetBenchV2QualityGate,
defaultSpreadsheetBenchV2QualityGateInputs,
formatSpreadsheetBenchV2QualityGateDense,
} from "../src/eval/spreadsheetBenchV2QualityGate";

const args = process.argv.slice(2);
if (args.includes("--help") || args.includes("-h")) usage(0);
if (args.includes("--json") && args.includes("--dense")) {
console.error("--json and --dense are mutually exclusive");
usage(2);
}

const defaults = defaultSpreadsheetBenchV2QualityGateInputs();
const officialReceiptPath = optionValue("--official-receipt") ?? defaults.officialReceiptPath;
const suppliedModelRuns = [
...optionValues("--model-run-receipt"),
...optionValues("--model-run"),
];
const modelRunReceiptPaths = suppliedModelRuns.length ? suppliedModelRuns : defaults.modelRunReceiptPaths;
const receiptRoots = optionValues("--receipt-root");
const jsonOut = optionValue("--json-out");
const jsonMode = args.includes("--json");
const strict = args.includes("--strict");

const verdict = buildSpreadsheetBenchV2QualityGate({
officialReceiptPath,
modelRunReceiptPaths,
receiptRoots,
});
const json = `${JSON.stringify(verdict, null, 2)}\n`;

if (jsonOut) {
const absolute = resolve(jsonOut);
mkdirSync(dirname(absolute), { recursive: true });
writeFileSync(absolute, json, "utf8");
}

if (jsonMode) process.stdout.write(json);
else process.stdout.write(`${formatSpreadsheetBenchV2QualityGateDense(verdict)}\n`);

if (jsonOut && !jsonMode) process.stderr.write(`wrote ${rel(jsonOut)}\n`);
if (strict && !verdict.pass) process.exitCode = 1;

function optionValue(name: string): string | undefined {
const prefix = `${name}=`;
const inline = args.find((arg) => arg.startsWith(prefix));
if (inline) return inline.slice(prefix.length);
const index = args.indexOf(name);
const value = index >= 0 ? args[index + 1] : undefined;
return value && !value.startsWith("--") ? value : undefined;
}

function optionValues(name: string): string[] {
const values: string[] = [];
const prefix = `${name}=`;
for (let index = 0; index < args.length; index += 1) {
const arg = args[index];
if (arg.startsWith(prefix)) values.push(arg.slice(prefix.length));
else if (arg === name) {
const value = args[index + 1];
if (value && !value.startsWith("--")) {
values.push(value);
index += 1;
}
}
}
return values;
}

function usage(exitCode: number): never {
const lines = [
"Usage:",
" npx tsx scripts/spreadsheetbench-v2-quality-gate.ts [options]",
"",
"Options:",
" --official-receipt <path> Accepted official V2 scorer receipt.",
" --model-run-receipt <path> Model-run/trace receipt (repeatable; --model-run is an alias).",
" --receipt-root <dir> Additional sidecar receipt root (repeatable).",
" --dense Emit one deterministic dense status line (default).",
" --json Emit the full deterministic JSON verdict.",
" --json-out <path> Also write the full JSON verdict.",
" --strict Exit 1 unless every quality sub-gate passes.",
" --help Show this help.",
"",
"The gate is read-only and never invokes a model, provider, or scorer.",
];
(exitCode === 0 ? process.stdout : process.stderr).write(`${lines.join("\n")}\n`);
process.exit(exitCode);
}

function rel(path: string): string {
return relative(process.cwd(), resolve(path)).replace(/\\/g, "/");
}
Loading
Loading