import { renderToStaticMarkup } from "react-dom/server"; import { describe, it } from "node:test"; import assert from "node:assert/strict"; import { StatsBar } from "../components/stats-bar.tsx"; import { prettyModel } from "../components/usage-format.ts"; import type { ChatSettings, TurnUsage } from "../src/core/contracts.ts"; // The stats bar: folds only (no cost math in the component), the "—" // doctrine for absent data, honest cost (never a fake $0), and the model + // thinking control (components/model-picker.tsx — pi-ai catalog backed). function step(inputTokens: number, outputTokens: number, over: Record = {}) { return { inputTokens, outputTokens, cacheReadTokens: undefined, cacheWriteTokens: undefined, reasoningTokens: undefined, ...over }; } function turn(over: Partial = {}): TurnUsage { return { id: "t1", messageId: "m1", at: "2026-09-09T12:00:00Z", model: "openrouter:z-ai/glm-5.3-flash", steps: [step(10_000, 1_000)], ...over, }; } describe("stats bar", () => { it("renders NOTHING on the left when there are no turns yet (owner, wave 7 sweep)", () => { const html = renderToStaticMarkup( , ); assert.match(html, /data-testid="stats-bar"/); // pre-chat: no summary button, no "—" theater (the knowledge-context // slider died with the injection — the left side is simply empty) assert.ok(!html.includes('data-testid="stats-summary"'), "no summary button pre-chat"); assert.ok(!html.includes('data-testid="stats-context"'), "no context figure pre-chat"); assert.ok(!html.includes('data-testid="stats-cost"'), "no cost figure pre-chat"); // no turns, no settings, catalog not loaded → both control labels // "—" (the thinking button shows just the level, like the model // button shows just the model name — no prefix, no dot separator) assert.match(html, /data-testid="stats-model"[^>]*>\s*]*>—<\/span>/); assert.match(html, /data-testid="stats-thinking"[^>]*>\s*]*>—<\/span>/); assert.ok(!html.includes("aria-hidden>·"), "no dot between the controls"); // the control reads as a button: pill border + dropdown chevron assert.match(html, /data-testid="stats-model"[^>]*rounded-full[^>]*>/); assert.match(html, /▾/); }); it("folds context + cost from the turns log (core/prices, no local math)", () => { const html = renderToStaticMarkup( , ); // last turn's last call: 10k in + 1k out = 11k. The LIMIT is the // live catalog's — and the bar doesn't hold the index yet (the // catalog join lands with the UI chunk), so the meter renders // USAGE-ONLY (owner amendment: never a fallback window). assert.match(html, /data-testid="stats-context">11k\$0\.0020]*>\s*]*>—<\/span>/); }); it("shows — for cost when every turn is unpriceable, never a fake $0", () => { const html = renderToStaticMarkup( , ); assert.match(html, /data-testid="stats-cost">—11k { assert.equal(prettyModel("z-ai/glm-5.3-flash"), "Glm 5.3 Flash"); assert.equal(prettyModel("qwen/qwen3.8-max-0902"), "Qwen3.8 Max"); }); it("provider-qualified stamps (usage contract, model-slots wave)", () => { // qualified: the provider rides as a quiet suffix — federation makes // the same model via two providers different bookkeeping assert.equal(prettyModel("openrouter:z-ai/glm-5.3-flash", true), "Glm 5.3 Flash · openrouter"); assert.equal(prettyModel("openai:gpt-5.2", true), "Gpt 5.2 · openai"); // unqualified on a qualified stamp: provider silently dropped (old shape) assert.equal(prettyModel("openrouter:z-ai/glm-5.3-flash"), "Glm 5.3 Flash"); // qualified on a bare id: no suffix invented assert.equal(prettyModel("z-ai/glm-5.3-flash", true), "Glm 5.3 Flash"); }); });