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, }; } const SETTINGS_STUB = (_s: ChatSettings) => {}; describe("stats bar", () => { it("renders — everywhere when the record has no turns yet (doctrine)", () => { const html = renderToStaticMarkup( , ); assert.match(html, /data-testid="stats-bar"/); assert.match(html, /data-testid="stats-context">——]*>\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; pi catalog limit // 1_048_576 → "1M" (tables regenerated from pi-ai's catalog) assert.match(html, /data-testid="stats-context">11k \/ 1M\$0\.0020]*>\s*]*>Glm 5\.3 Flash<\/span>/); }); it("shows — for cost when every turn is unpriceable, never a fake $0", () => { const html = renderToStaticMarkup( , ); assert.match(html, /data-testid="stats-cost">—— { 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"); }); });