The platform for continuously improving AI agents.
// @vitest-environment jsdom
// covers: console-logic
import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
import { afterEach, expect, it, vi } from "vitest";
import type { ChatEvalSetDraft } from "@/openapi";
import { BenchmarkReview } from "./benchmark-review";
afterEach(cleanup);
const polite = {
name: "polite",
options: [
{ label: "Yes", score: 1 },
{ label: "No", score: 0 },
],
output: "yes_no" as const,
source: "Is the reply polite?",
type: "llm" as const,
};
const short = {
name: "short",
source: "def evaluate(span):\n return 1.0",
type: "deterministic" as const,
};
const draft: ChatEvalSetDraft = {
criteria: [polite, short],
current: null,
description: "",
evalSet: null,
name: "Support replies",
rationale: "The request asks for polite, short replies",
};
it("approves with the criteria as the user left them", async () => {
const onDecide = vi.fn().mockResolvedValue(undefined);
render(<BenchmarkReview draft={draft} onDecide={onDecide} status="pending" />);
fireEvent.click(screen.getByRole("button", { name: "Save benchmark" }));
await waitFor(() => expect(onDecide).toHaveBeenCalledWith(true, "Approved", [polite, short]));
});
it("rejects with the reason and no criteria", async () => {
const onDecide = vi.fn().mockResolvedValue(undefined);
render(<BenchmarkReview draft={draft} onDecide={onDecide} status="pending" />);
fireEvent.click(screen.getByRole("button", { name: "Reject" }));
fireEvent.change(screen.getByRole("textbox", { name: "Reason for rejecting" }), {
target: { value: "Too vague" },
});
fireEvent.click(screen.getByRole("button", { name: "Confirm reject" }));
await waitFor(() => expect(onDecide).toHaveBeenCalledWith(false, "Too vague", undefined));
});
it("shows an amendment as a diff of the saved benchmark and offers no decision once decided", () => {
render(
<BenchmarkReview
draft={{
...draft,
current: { criteria: [polite], description: "", name: "Support replies" },
evalSet: "8b0f1f0e-5d1c-4f2b-9b1a-2f6f1f0e5d1c",
}}
onDecide={vi.fn()}
status="rejected"
/>
);
fireEvent.click(screen.getByRole("button", { name: /Review changes/ }));
expect(screen.getByText(/\+ ## short · python/)).toBeTruthy();
expect(screen.queryByRole("button", { name: "Apply amendment" })).toBeNull();
expect(screen.queryByRole("button", { name: "Reject" })).toBeNull();
});