Skip to content
TypeScript

refactor(web): test the live usage column builder (#9993)

Julius Marminge487d1766caba
diff --git a/apps/web/src/components/usage/UsageProviderChart.test.ts b/apps/web/src/components/usage/UsageProviderChart.test.ts
index a4114cfdfb5..622d73d1384 100644
--- a/apps/web/src/components/usage/UsageProviderChart.test.ts
+++ b/apps/web/src/components/usage/UsageProviderChart.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vite-plus/test";
-import { buildDayColumns, niceScale } from "./UsageProviderChart";
+import { buildPeriodColumns, niceScale } from "./UsageProviderChart";
import { providersWithUsage } from "./usageProviders";
describe("niceScale", () => {
@@ -41,7 +41,7 @@ describe("niceScale", () => {
});
});
-describe("buildDayColumns", () => {
+describe("buildPeriodColumns", () => {
const days = ["2026-08-01", "2026-08-02", "2026-08-03"];
const byDay = new Map([
[
@@ -69,11 +69,13 @@ describe("buildDayColumns", () => {
]);
it("plots each day on its own", () => {
- expect(buildDayColumns(days, byDay, "cost").map((column) => column.total)).toEqual([30, 0, 5]);
+ expect(buildPeriodColumns(days, byDay, "cost").map((column) => column.total)).toEqual([
+ 30, 0, 5,
+ ]);
});
it("reads the requested metric", () => {
- expect(buildDayColumns(days, byDay, "tokens").map((column) => column.total)).toEqual([
+ expect(buildPeriodColumns(days, byDay, "tokens").map((column) => column.total)).toEqual([
300, 0, 50,
]);
});
@@ -81,7 +83,7 @@ describe("buildDayColumns", () => {
it("keeps band values absolute rather than cumulative", () => {
// Regression: the bands were once stack offsets, which drew Claude Code
// permanently above Codex regardless of which provider spent more.
- const [first] = buildDayColumns(days, byDay, "cost");
+ const [first] = buildPeriodColumns(days, byDay, "cost");
expect(first?.bands).toEqual([
{ provider: "codex", value: 10 },
@@ -91,7 +93,7 @@ describe("buildDayColumns", () => {
});
it("reports the total as the sum of its bands", () => {
- for (const column of buildDayColumns(days, byDay, "cost")) {
+ for (const column of buildPeriodColumns(days, byDay, "cost")) {
const sum = column.bands.reduce((running, band) => running + band.value, 0);
expect(column.total).toBeCloseTo(sum, 9);
}
@@ -125,7 +127,7 @@ describe("hourly chart columns", () => {
]);
expect(
- buildDayColumns(
+ buildPeriodColumns(
["2026-08-11T08:37:00.000Z", "2026-08-11T09:37:00.000Z", "2026-08-11T10:37:00.000Z"],
byHour,
"cost",
diff --git a/apps/web/src/components/usage/UsageProviderChart.tsx b/apps/web/src/components/usage/UsageProviderChart.tsx
index 26d49e66480..4a66349ddfa 100644
--- a/apps/web/src/components/usage/UsageProviderChart.tsx
+++ b/apps/web/src/components/usage/UsageProviderChart.tsx
@@ -54,7 +54,7 @@ function valueFor(
return metric === "tokens" ? entry.totalTokens : entry.costUsd;
}
-function buildPeriodColumns(
+export function buildPeriodColumns(
periods: readonly string[],
byPeriod: ReadonlyMap<string, DailyTotals | HourlyTotals>,
metric: UsageChartMetric,
@@ -169,24 +169,6 @@ export function niceScale(peak: number, count: number): { max: number; ticks: re
return { max, ticks };
}
-/**
- * Turns the merged daily totals into one column per day.
- *
- * Values are absolute, not cumulative: each provider is drawn from the same
- * zero baseline so the chart never implies that one provider is always larger.
- *
- * The chart paths and the hover readout both consume this, so the number under
- * the cursor is by construction the number that was plotted rather than a
- * second derivation that can drift from it.
- */
-export function buildDayColumns(
- days: readonly string[],
- byDay: ReadonlyMap<string, DailyTotals>,
- metric: UsageChartMetric,
-): readonly DayColumn[] {
- return buildPeriodColumns(days, byDay, metric);
-}
-
export function UsageProviderChart({
providers,
days,