Q75: charts and billing use full-period statistics computed per org

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-08 12:41:44 -04:00
1 parent daea9797d4
commit 8b4df5e11f
14 files changed
+231 -83

No files matched your search

+5 -6
View File
@@ -1,18 +1,17 @@
import { describe, expect, test } from "vitest";
import { buildAgentSpend } from "../../src/renderer/src/pages/settings/billing-helpers";
import type { AgentRecord, ProviderRequestRecord } from "../../src/shared/domain";
import type { AgentRecord } from "../../src/shared/domain";
const agent = (id: string, modelProviderId: string) => ({ id, name: id, modelProviderId, budgetCents: 1000 }) as AgentRecord;
const call = (agentId: string | null, providerId: string, costCents: number | null) =>
({ agentId, providerId, inputTokens: 100, outputTokens: 50, costCents }) as ProviderRequestRecord;
describe("billing attribution", () => {
test("each call counts once for the agent that made it, not for everyone on the same provider", () => {
test("rows come from per-agent totals, highest spend first, agents without calls at zero", () => {
const rows = buildAgentSpend([agent("ada", "prv_a"), agent("bo", "prv_a"), agent("cy", "prv_b")], [
call("ada", "prv_a", 10), call("ada", "prv_a", 5), call("bo", "prv_a", 1), call("cy", "prv_a", 2), call(null, "prv_a", 99),
{ agentId: "ada", requests: 2, tokens: 300, costCents: 15 },
{ agentId: "cy", requests: 1, tokens: 150, costCents: 2 },
]);
expect(rows.map((row) => [row.agent.id, row.requestCount, row.tokens, row.spentCents])).toEqual([
["ada", 2, 300, 15], ["cy", 1, 150, 2], ["bo", 1, 150, 1],
["ada", 2, 300, 15], ["cy", 1, 150, 2], ["bo", 0, 0, 0],
]);
});
});