core/workbench-ui/src/app/WrongZeroFrame.test.tsx
Shay c84127adf8 feat(workbench): wrong=0 as a felt global presence (Wave M B3)
An always-present invariant in the TopBar chrome: the live serving triplet
(N correct · N refused · 0 wrong) aggregated across lanes from
/serving/metrics, the wrong count load-bearing — 0 in the verified token,
>0 in the contradicted token. It is a MIRROR, never a hard-coded zero:
renders a non-zero wrong honestly, and an honest 'metrics unavailable' when
the reports can't be read. Links to the Calibration route (the discipline
behind the number).

Tests: aggregate triplet + 0-wrong, non-zero-wrong-honest (not hard-coded),
metrics-unavailable-not-fake-zero. (Adds fetchServingMetrics/useServingMetrics
locally; unioned with B2 on rebase.)
2026-06-13 01:12:24 -07:00

80 lines
2.6 KiB
TypeScript

import { QueryClientProvider } from "@tanstack/react-query";
import { render, screen } from "@testing-library/react";
import { MemoryRouter } from "react-router-dom";
import { afterEach, describe, expect, it, vi } from "vitest";
import { createTestQueryClient } from "../test/createTestQueryClient";
import type { ServingMetrics } from "../types/api";
import { WrongZeroFrame } from "./WrongZeroFrame";
function renderFrame() {
return render(
<QueryClientProvider client={createTestQueryClient()}>
<MemoryRouter>
<WrongZeroFrame />
</MemoryRouter>
</QueryClientProvider>,
);
}
function stub(metrics: ServingMetrics[] | "error") {
vi.stubGlobal(
"fetch",
vi.fn(() =>
metrics === "error"
? Promise.resolve({
json: () =>
Promise.resolve({
ok: false,
generated_at: "now",
error: { code: "read_error", message: "boom" },
}),
})
: Promise.resolve({
json: () => Promise.resolve({ ok: true, generated_at: "now", data: { items: metrics } }),
}),
),
);
}
function lane(correct: number, refused: number, wrong: number, name: string): ServingMetrics {
return {
lane: name,
correct,
refused,
wrong,
sample_count: correct + refused + wrong,
source_path: `evals/${name}/report.json`,
source_digest: "sha256:x",
};
}
describe("WrongZeroFrame", () => {
afterEach(() => {
vi.restoreAllMocks();
localStorage.clear();
});
it("aggregates the live serving triplet across lanes with wrong load-bearing", async () => {
stub([lane(4, 46, 0, "train_sample"), lane(5, 495, 0, "holdout_dev")]);
renderFrame();
// 9 correct · 541 refused · 0 wrong
expect(await screen.findByText(/9 correct · 541 refused ·/)).toBeInTheDocument();
expect(screen.getByText("0 wrong")).toBeInTheDocument();
// it links to the discipline behind it
expect(screen.getByRole("link")).toHaveAttribute("href", "/calibration");
});
it("is a mirror — renders a non-zero wrong honestly, not a hard-coded zero", async () => {
stub([lane(90, 5, 5, "drifted")]);
renderFrame();
expect(await screen.findByText("5 wrong")).toBeInTheDocument();
expect(screen.queryByText("0 wrong")).not.toBeInTheDocument();
});
it("renders an honest 'metrics unavailable', never a fake zero, on error", async () => {
stub("error");
renderFrame();
expect(await screen.findByText(/metrics unavailable/)).toBeInTheDocument();
expect(screen.queryByText("0 wrong")).not.toBeInTheDocument();
});
});