Owner ruling (2026-09-23, amendment to 04e336d): no hardcoded fallback exists anywhere. contextWindow(record, limits) resolves the denominator ONLY from the live index (provider:id -> contextWindow straight from pi's catalog); a model missing from it (historical session, package update, failed fetch) reads limit null and the meter renders usage-only — the honest-render precedent, never a fake window. - src/core/prices.ts: the 1354-entry CONTEXT_LIMITS table (65KB) and its generation apparatus deleted; the fold returns limit: number | null. PRICES untouched (regen verified byte-identical via the reworked sync-pricing script). - scripts/sync-pricing.ts: generates PRICES only; contextWindow leaves the priced map, the guard, and the template. - The dock meter's owner-selected treatment: the activity feed carries the limit server-side. catalogContextLimits() (server/model-catalog.ts) builds the index over the same keyed providers the picker federates; activityFeed() joins it onto every running job (ActivityJob.contextLimit, null when the model is missing — the dock reads it off the feed, no client-side table, no regression while the UI's catalog-join chunk lands). - components/activity-dock.tsx: toBlobs reads job.contextLimit (import of CONTEXT_LIMITS gone); stats-bar renders usage-only on null limit (mechanical interim — UI stream's join chunk follows). - tests: usage.test.ts pins the no-fallback contract (index hit / absent / empty / missing-model -> null); activity-feed.test.ts pins the server join (catalog model -> 1048576, unknown -> null, no-usage -> null); render pins updated to the interim usage-only render.
93 lines
4.5 KiB
TypeScript
93 lines
4.5 KiB
TypeScript
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<string, number | undefined> = {}) {
|
||
return { inputTokens, outputTokens, cacheReadTokens: undefined, cacheWriteTokens: undefined, reasoningTokens: undefined, ...over };
|
||
}
|
||
|
||
function turn(over: Partial<TurnUsage> = {}): 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(
|
||
<StatsBar turns={[]} />,
|
||
);
|
||
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[^>]*>—<\/span>/);
|
||
assert.match(html, /data-testid="stats-thinking"[^>]*>\s*<span[^>]*>—<\/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(
|
||
<StatsBar turns={[turn(), turn()]} />,
|
||
);
|
||
// 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</);
|
||
// pi catalog price 0.075/0.25 per 1M: each turn 10k×0.075 + 1k×0.25
|
||
// = $0.001 → two = $0.0020
|
||
assert.match(html, /data-testid="stats-cost">\$0\.0020</);
|
||
// model button label: SSR (record fetch not run yet) reads "—" —
|
||
// the strong slot arrives client-side via GET /api/settings; the
|
||
// turn log below still folds the ACTUAL models billed
|
||
assert.match(html, /data-testid="stats-model"[^>]*>\s*<span[^>]*>—<\/span>/);
|
||
});
|
||
|
||
it("shows — for cost when every turn is unpriceable, never a fake $0", () => {
|
||
const html = renderToStaticMarkup(
|
||
<StatsBar turns={[turn({ model: "nope/unknown" })]} />,
|
||
);
|
||
assert.match(html, /data-testid="stats-cost">—</);
|
||
// unknown model: no catalog limit exists, but the footprint is
|
||
// still an honest reading — usage-only (never "—" theater over
|
||
// real data, never a fake window)
|
||
assert.match(html, /data-testid="stats-context">11k</);
|
||
});
|
||
|
||
it("prettyModel strips vendor + date suffix, capitalizes", () => {
|
||
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");
|
||
});
|
||
}); |