@devries-cameron20 / t3code-1 / commits / 487d1766ca
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

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

Julius Marminge committed Sep 5, 2026 at 00:19 UTC 487d1766caba52579f07a3e5ebc6f276227e4382
2 files changed +10 -26
apps/web/src/components/usage/UsageProviderChart.test.ts
+9 -7
@@ -1,6 +1,6 @@
1 import { describe, expect, it } from "vite-plus/test";
2
3 -import { buildDayColumns, niceScale } from "./UsageProviderChart";
3 +import { buildPeriodColumns, niceScale } from "./UsageProviderChart";
4 import { providersWithUsage } from "./usageProviders";
5
6 describe("niceScale", () => {
@@ -41,7 +41,7 @@ describe("niceScale", () => {
41 });
42 });
43
44 -describe("buildDayColumns", () => {
44 +describe("buildPeriodColumns", () => {
45 const days = ["2026-08-01", "2026-08-02", "2026-08-03"];
46 const byDay = new Map([
47 [
@@ -69,11 +69,13 @@ describe("buildDayColumns", () => {
69 ]);
70
71 it("plots each day on its own", () => {
72 - expect(buildDayColumns(days, byDay, "cost").map((column) => column.total)).toEqual([30, 0, 5]);
72 + expect(buildPeriodColumns(days, byDay, "cost").map((column) => column.total)).toEqual([
73 + 30, 0, 5,
74 + ]);
75 });
76
77 it("reads the requested metric", () => {
76 - expect(buildDayColumns(days, byDay, "tokens").map((column) => column.total)).toEqual([
78 + expect(buildPeriodColumns(days, byDay, "tokens").map((column) => column.total)).toEqual([
79 300, 0, 50,
80 ]);
81 });
@@ -81,7 +83,7 @@ describe("buildDayColumns", () => {
83 it("keeps band values absolute rather than cumulative", () => {
84 // Regression: the bands were once stack offsets, which drew Claude Code
85 // permanently above Codex regardless of which provider spent more.
84 - const [first] = buildDayColumns(days, byDay, "cost");
86 + const [first] = buildPeriodColumns(days, byDay, "cost");
87
88 expect(first?.bands).toEqual([
89 { provider: "codex", value: 10 },
@@ -91,7 +93,7 @@ describe("buildDayColumns", () => {
93 });
94
95 it("reports the total as the sum of its bands", () => {
94 - for (const column of buildDayColumns(days, byDay, "cost")) {
96 + for (const column of buildPeriodColumns(days, byDay, "cost")) {
97 const sum = column.bands.reduce((running, band) => running + band.value, 0);
98 expect(column.total).toBeCloseTo(sum, 9);
99 }
@@ -125,7 +127,7 @@ describe("hourly chart columns", () => {
127 ]);
128
129 expect(
128 - buildDayColumns(
130 + buildPeriodColumns(
131 ["2026-08-11T08:37:00.000Z", "2026-08-11T09:37:00.000Z", "2026-08-11T10:37:00.000Z"],
132 byHour,
133 "cost",
apps/web/src/components/usage/UsageProviderChart.tsx
+1 -19
@@ -54,7 +54,7 @@ function valueFor(
54 return metric === "tokens" ? entry.totalTokens : entry.costUsd;
55 }
56
57 -function buildPeriodColumns(
57 +export function buildPeriodColumns(
58 periods: readonly string[],
59 byPeriod: ReadonlyMap<string, DailyTotals | HourlyTotals>,
60 metric: UsageChartMetric,
@@ -169,24 +169,6 @@ export function niceScale(peak: number, count: number): { max: number; ticks: re
169 return { max, ticks };
170 }
171
172 -/**
173 - * Turns the merged daily totals into one column per day.
174 - *
175 - * Values are absolute, not cumulative: each provider is drawn from the same
176 - * zero baseline so the chart never implies that one provider is always larger.
177 - *
178 - * The chart paths and the hover readout both consume this, so the number under
179 - * the cursor is by construction the number that was plotted rather than a
180 - * second derivation that can drift from it.
181 - */
182 -export function buildDayColumns(
183 - days: readonly string[],
184 - byDay: ReadonlyMap<string, DailyTotals>,
185 - metric: UsageChartMetric,
186 -): readonly DayColumn[] {
187 - return buildPeriodColumns(days, byDay, metric);
188 -}
189 -
172 export function UsageProviderChart({
173 providers,
174 days,