opencode-bench/test/datasets.test.ts
KaKi87 9de3560b7d Add MMLU, ARC-Challenge, BBH, MATH-500, IFEval and LiveCodeBench importers
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-25 11:10:41 +01:00

39 lines
1.9 KiB
TypeScript

import { expect, test } from "bun:test";
import { existsSync, mkdtempSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";
import { SOURCES } from "../src/benchmarks/datasets";
const dir = new URL("../data/datasets/", import.meta.url).pathname;
async function grade(task: { files?: Record<string, string>; grade: string }, extra: Record<string, string>) {
const w = mkdtempSync(join(tmpdir(), "ds-"));
for (const [f, c] of Object.entries({ ...task.files, ...extra })) writeFileSync(join(w, f), c);
writeFileSync(join(w, ".grade.py"), task.grade);
const p = Bun.spawn(["python3", "-I", ".grade.py"], { cwd: w, stdout: "pipe", stderr: "pipe" });
return p.exited;
}
// Reference solutions must pass and an untouched workspace must fail. Skipped until `bench import` ran.
const refs: Record<string, (r: any) => Record<string, string>> = {
humaneval: (r) => ({ "solution.py": r.prompt + r.canonical_solution }),
mbpp: (r) => ({ "solution.py": r.code }),
gsm8k: (r) => ({ "answer.txt": String(r.answer).split("####").pop()!.trim().replace(/,/g, "") }),
mmlu: (r) => ({ "answer.txt": "ABCD"[Number(r.answer)] }),
arc: (r) => ({ "answer.txt": `${String(r.answerKey).replace(/^([1-9])$/, (d) => "ABCDE"[Number(d) - 1])}.` }),
bbh: (r) => ({ "answer.txt": String(r.target) }),
math: (r) => ({ "answer.txt": `$${r.answer}$` }),
};
for (const [id, ref] of Object.entries(refs)) {
const path = `${dir}${id}.json`;
test.skipIf(!existsSync(path))(`${id}: reference solutions pass, empty workspace fails`, async () => {
const rows = JSON.parse(readFileSync(path, "utf8")) as any[];
const step = Math.ceil(rows.length / 40);
for (let i = 0; i < rows.length; i += step) {
const task = SOURCES[id].toTask(rows[i]);
expect(await grade(task, ref(rows[i]))).toBe(0);
expect(await grade(task, {})).not.toBe(0);
}
}, 120_000);
}