The platform for continuously improving AI agents.
// covers: console-logic
import { describe, expect, it } from "vitest";
import type { EvalRun } from "@/openapi";
import { benchmarkHistory } from "./benchmark-library";
import { NEW_CRITERION, saveBlocker } from "./criteria-card";
const run = (overrides: Partial<EvalRun>): EvalRun =>
({
capabilityId: "c",
cell: "cell",
createdAt: new Date("2026-11-01"),
dataset: "d",
evalSet: "set",
judgeModel: "j",
matrix: [{ name: "Tone" }],
maxItems: 50,
mode: "recorded",
sampling: 1,
status: "completed",
...overrides,
}) as EvalRun;
describe("benchmark history", () => {
it("compares only with an earlier run on the same data and rubric", () => {
const latest = run({ createdAt: new Date("2026-11-03"), id: "latest" });
const otherData = run({ createdAt: new Date("2026-11-02"), dataset: "other", id: "other" });
const sameSetup = run({ createdAt: new Date("2026-11-01"), id: "same" });
const running = run({ createdAt: new Date("2026-11-04"), status: "running" });
expect(benchmarkHistory([sameSetup, otherData, running, latest], "set")).toEqual({
latest,
previous: sameSetup,
});
const newRubric = run({ createdAt: new Date("2026-11-05"), matrix: [{ name: "Length" }] });
expect(benchmarkHistory([newRubric, latest], "set").previous).toBeUndefined();
});
});
describe("save checks", () => {
it("names the first problem in the order the editor shows them", () => {
const judge = { ...NEW_CRITERION.llm, name: "Tone", source: "Is it polite?" };
expect(saveBlocker("", [judge])).toBe("Enter a benchmark name.");
expect(saveBlocker("Replies", [])).toBe("Add at least one criterion.");
expect(saveBlocker("Replies", [judge, judge])).toBe("Use a unique name for criterion 2.");
const choice = {
...judge,
options: [
{ label: "A", score: 1 },
{ label: "A", score: 0 },
],
output: "multiple_choice" as const,
};
expect(saveBlocker("Replies", [choice])).toBe("Use distinct answer names for “Tone”.");
expect(
saveBlocker("Replies", [
{
...judge,
options: [
{ label: "Yes", score: 2 },
{ label: "No", score: 0 },
],
},
])
).toBe("Enter a score from 0 to 1 for each answer to “Tone”.");
expect(
saveBlocker("Replies", [judge, { ...NEW_CRITERION.deterministic, name: "Short" }])
).toBeNull();
});
});