import { test, expect } from "@playwright/test"; import { readFileSync, rmSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { WARM_TIMEOUT, warm } from "./warm"; import { BENCH_RUN, BENCH_RUN_V2, QWEN, SONNET, makeBenchRun, makeBenchRunV2 } from "./fixtures/bench-fixture.mjs"; // --------------------------------------------------------------------------- // The verdict bench's page (release 28 M7) over a synthetic run in the // fixture's `.generation`-style root (GENERATION_USAGE_FILE is the fixture's, // so the runs root is /bench/verdicts): the tiles against the // baseline, the confusion matrix, the items with disagreements first and the // filters, and the bar — written through the (stubbed) editor's settings // action, each model's pass or fail read against it, and a failing model // never tickable. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const ROOT = path.join(FIXTURE, "bench", "verdicts"); const STUB_LOG = path.join(FIXTURE, "editor-stub.requests.json"); const stubAsked = (route: string) => (JSON.parse(readFileSync(STUB_LOG, "utf8")) as { route?: string; [k: string]: unknown }[]).filter((r) => r.route === route); test.beforeAll(async ({ playwright }) => { test.setTimeout(WARM_TIMEOUT); makeBenchRun(ROOT); makeBenchRunV2(ROOT); await warm(playwright, ["/bench", "/api/bench/bar"]); }); test.afterAll(async ({ request }) => { await request.post("/api/bench/bar", { data: { bar: { agreement: 0, contradictedRecall: 0, notFoundRecall: 0 }, models: [] } }); rmSync(path.join(ROOT, BENCH_RUN), { recursive: true, force: true }); rmSync(path.join(ROOT, BENCH_RUN_V2), { recursive: true, force: true }); }); test("the run: each model's tile against the baseline, the matrix, the items with disagreements first, the filters", async ({ page }) => { await page.goto("/tools"); await page.getByRole("link", { name: "verdict bench" }).click(); await expect(page).toHaveURL(/\/bench$/); await expect(page.locator(`[data-bench-run="${BENCH_RUN}"]`)).toHaveAttribute("data-status", "done"); const models = page.getByRole("region", { name: "models" }); const sonnet = models.locator(`[data-model="${SONNET}"]`); await expect(sonnet.locator('[data-metric="agreement"]')).toHaveText("75% (baseline 25%)"); await expect(sonnet.locator('[data-metric="contradicted"]')).toHaveText("100% (baseline 0%) of 1"); await expect(sonnet.locator('[data-metric="not-found"]')).toHaveText("100% (baseline 0%) of 1"); await expect(sonnet.locator('[data-metric="cost"]')).toHaveText("$0.0160"); const qwen = models.locator(`[data-model="${QWEN}"]`); await expect(qwen.locator('[data-metric="agreement"]')).toHaveText("25% (baseline 25%)"); await expect(qwen).toContainText("3 of 4 · 1 parse failures"); await expect(models.locator('[data-model="always-CORROBORATED"]')).toBeVisible(); // The matrix: rows the operator, columns the model. const m = page.getByRole("table", { name: `confusion ${SONNET}` }); await expect(m.locator('[data-cell="PARTLY:CORROBORATED"]')).toHaveText("1"); await expect(m.locator('[data-cell="CONTRADICTED:CONTRADICTED"]')).toHaveText("1"); // The items: every disagreement first. const rows = page.getByRole("region", { name: "items" }).locator("tbody tr"); await expect(rows).toHaveCount(4); await expect(rows.nth(0)).toHaveAttribute("data-item", "synth-bench/c2"); await expect(rows.nth(3)).toHaveAttribute("data-item", "synth-bench/c1"); await expect(rows.nth(0).locator(`[data-model="${SONNET}"]`)).toContainText("read the window for c2"); await expect(rows.nth(2).locator(`[data-model="${QWEN}"]`)).toContainText("parse: the answer is not JSON"); // Bench v3: what the model saw (the cited post, the window's lines), and the model's parts. const c2 = rows.nth(0); await expect(c2.locator('[data-seen="synth-bench/c2"] summary')).toHaveText("what the model saw · 1 window · 1 post or page"); await c2.locator('[data-seen="synth-bench/c2"] summary').click(); await expect(c2.locator('[data-evidence="post"]')).toContainText("the oven was off for a week"); await expect(c2.locator('[data-window="synth-kitchen/bread-day-01"]')).toContainText("[0:25] a line"); await expect(c2.locator(`[data-model="${SONNET}"] [data-part-finding="shown"]`)).toContainText("c2: what the article says"); await expect(c2.locator(`[data-model="${QWEN}"] [data-part-finding]`)).toHaveCount(0); // By model: that model's disagreements first, its column alone. await page.getByRole("region", { name: "items" }).getByRole("link", { name: SONNET, exact: true }).click(); await expect(rows.nth(0)).toHaveAttribute("data-item", "synth-bench/c2"); await expect(rows.nth(1)).toHaveAttribute("data-item", "synth-bench/c1"); await expect(page.getByRole("region", { name: "items" }).locator(`thead th`)).toHaveCount(3); // By the operator's verdict. await page.getByRole("region", { name: "items" }).getByRole("link", { name: "CONTRADICTED 1" }).click(); await expect(rows).toHaveCount(1); await expect(rows.nth(0)).toHaveAttribute("data-item", "synth-bench/c3"); await expect(page.getByText("skipped 1")).toBeVisible(); }); test("the bar: saved through the editor's settings action; a passing model ticked, a failing one never", async ({ page }) => { await page.goto(`/bench?run=${BENCH_RUN}`); const form = page.getByRole("form", { name: "bar" }); await form.getByRole("spinbutton", { name: "minimum agreement" }).fill("50"); await form.getByRole("spinbutton", { name: "minimum CONTRADICTED recall" }).fill("50"); await form.getByRole("spinbutton", { name: "minimum NOT_FOUND recall" }).fill("50"); await expect(form.getByRole("checkbox", { name: `use ${QWEN}` })).toBeDisabled(); await expect(form.locator(`[data-model="${QWEN}"]`)).toHaveAttribute("data-pass", "false"); const use = form.getByRole("checkbox", { name: `use ${SONNET}` }); await expect(use).toBeEnabled(); await use.check(); await expect(form.locator("[data-window]")).toHaveText(/^proposals read ±60 s \(this run's window\)/); await form.getByRole("button", { name: "Save the bar" }).click(); await expect(form.getByRole("status")).toHaveText("Saved."); expect(stubAsked("settings").at(-1)).toMatchObject({ // The window proposals read is the run's the bar was set on (release 29). patch: { generation: { verdicts: { bar: { agreement: 0.5, contradictedRecall: 0.5, notFoundRecall: 0.5 }, models: [SONNET], window: { mode: "seconds", seconds: 60 } } } }, authorization: "Bearer umtool-e2e-token", }); // Read back: the tiles say who passes the saved bar. await page.reload(); const models = page.getByRole("region", { name: "models" }); await expect(models.locator(`[data-model="${SONNET}"]`)).toHaveAttribute("data-pass", "true"); await expect(models.locator(`[data-model="${QWEN}"]`)).toHaveAttribute("data-pass", "false"); await expect(page.getByRole("form", { name: "bar" }).getByRole("checkbox", { name: `use ${SONNET}` })).toBeChecked(); await expect(page.getByRole("form", { name: "bar" }).getByRole("spinbutton", { name: "minimum agreement" })).toHaveValue("50"); }); test("V1: the run's prompt version and items hash; compare with a run over the same items", async ({ page }) => { await page.goto(`/tools/bench?run=${BENCH_RUN_V2}`); const status = page.locator(`[data-bench-run="${BENCH_RUN_V2}"]`).getByRole("status"); await expect(status.locator("[data-prompt-version]")).toHaveText("prompt v2"); const hash = await status.locator("[data-items-hash]").getAttribute("data-items-hash"); expect(hash).toMatch(/^[0-9a-f]{16}$/); // The first run (made before V1: version 1) has the same items. await page.goto(`/tools/bench?run=${BENCH_RUN}`); await expect(page.locator(`[data-bench-run="${BENCH_RUN}"]`).getByRole("status").locator("[data-prompt-version]")).toHaveText("prompt v1"); await expect(page.locator(`[data-bench-run="${BENCH_RUN}"]`).getByRole("status").locator("[data-items-hash]")).toHaveAttribute("data-items-hash", hash!); await page.goto(`/tools/bench?run=${BENCH_RUN_V2}`); const compare = page.getByRole("region", { name: "compare" }); await compare.getByRole("navigation", { name: "compare with" }).getByRole("link", { name: `${BENCH_RUN} · prompt v1` }).click(); await expect(page).toHaveURL(new RegExp(`compare=${BENCH_RUN}`)); const row = compare.locator(`[data-compare="${BENCH_RUN}"] tr[data-model="${SONNET}"]`); await expect(row.locator('[data-metric="agreement-a"]')).toHaveText("75%"); await expect(row.locator('[data-metric="agreement-b"]')).toHaveText("75%"); await expect(row.locator('[data-metric="changed"]')).toHaveText("2 · 1 now agree · 1 no longer"); // Only Sonnet was asked in both. await expect(compare.locator(`tr[data-model="${QWEN}"]`)).toHaveCount(0); const changed = compare.getByRole("list", { name: "changed answers" }).locator("li"); await expect(changed).toHaveCount(2); await expect(changed.nth(0)).toHaveText(`${SONNET} synth-bench/c2: CORROBORATED → PARTLY (ruled PARTLY)`); await expect(changed.nth(1)).toHaveText(`${SONNET} synth-bench/c3: CONTRADICTED → PARTLY (ruled CONTRADICTED)`); // What the verdicts mean: the one copy. await page.getByText("what the verdicts mean").click(); await expect(page.locator('[data-meaning="CORROBORATED"]')).toContainText("every part of the claim is shown by the cited evidence in substance"); await expect(page.locator('[data-meaning="PARTLY"]')).toContainText("some parts of the claim are shown and at least one is not"); await expect(page.getByText("A claim's parts are the separate things it says were said or done")).toBeVisible(); }); test("V1: a Right mark on a disagreement moves the marked precision; again unmarks", async ({ page }) => { await page.goto(`/tools/bench?run=${BENCH_RUN}`); const precision = page.getByRole("region", { name: "precision" }).locator(`tr[data-model="${SONNET}"]`); await expect(precision.locator('[data-metric="precision"]')).toHaveText("100% / 66.7%"); await expect(precision.locator('[data-metric="marked-precision"]')).toHaveText("100% / 66.7%"); await expect(precision.locator('[data-metric="marks"]')).toHaveText("none yet"); // Sonnet called the PARTLY claim c2 CORROBORATED: the operator says the model was right. const cell = page.getByRole("region", { name: "items" }).locator('tr[data-item="synth-bench/c2"]').locator(`[data-model="${SONNET}"]`); // An agreeing answer has no mark buttons. await expect(page.getByRole("region", { name: "items" }).locator('tr[data-item="synth-bench/c1"]').locator(`[data-model="${SONNET}"]`).getByRole("button")).toHaveCount(0); await cell.getByRole("button", { name: "Right" }).click(); await expect(cell.getByRole("button", { name: "Right" })).toHaveAttribute("aria-pressed", "true"); await expect(precision.locator('[data-metric="marked-precision"]')).toHaveText("100% / 100%"); await expect(precision.locator('[data-metric="marks"]')).toHaveText("1 right · 0 wrong"); // The plain score is the ruling's, unmoved. await expect(precision.locator('[data-metric="precision"]')).toHaveText("100% / 66.7%"); // Kept across a reload; again unmarks. await page.reload(); await expect(cell.locator("[data-mark]")).toHaveAttribute("data-mark", "right"); await cell.getByRole("button", { name: "Right" }).click(); await expect(precision.locator('[data-metric="marks"]')).toHaveText("none yet"); await expect(cell.getByRole("button", { name: "Right" })).toHaveAttribute("aria-pressed", "false"); });