fix: force cost_usd for percentile/histogram queries, fix test + prettier

- Backend: always pass tracking_type=None to _build_raw_where for
  percentile and histogram queries so they compute stats on cost_usd
  rows regardless of the caller's tracking_type filter.
- Frontend test: use getAllByText for "5" which appears in both the
  Active Users card and the $1-2 bucket count.
- Frontend: fix prettier formatting in PlatformCostContent.tsx.
This commit is contained in:
majdyz
2026-04-13 06:36:59 +00:00
parent 7dc4319125
commit 040637dd68
3 changed files with 8 additions and 4 deletions

View File

@@ -352,8 +352,11 @@ async def get_platform_cost_dashboard(
# Build parameterised WHERE clause for the raw SQL percentile/bucket
# queries. Uses _build_raw_where so filter logic is shared with
# _build_prisma_where and only maintained in one place.
# Always force tracking_type=None here so _build_raw_where defaults to
# "cost_usd" — percentile and histogram queries only make sense on
# cost-denominated rows, regardless of what the caller is filtering.
raw_where, raw_params = _build_raw_where(
start, end, provider, user_id, model, block_name, tracking_type
start, end, provider, user_id, model, block_name, tracking_type=None
)
# Queries that always run regardless of tracking_type filter.

View File

@@ -185,7 +185,9 @@ describe("PlatformCostContent", () => {
);
expect(screen.getByText("$5.0000")).toBeDefined();
expect(screen.getByText("100")).toBeDefined();
expect(screen.getByText("5")).toBeDefined();
// "5" appears in multiple places (Active Users card + bucket count),
// so verify at least one element renders it.
expect(screen.getAllByText("5").length).toBeGreaterThanOrEqual(1);
expect(screen.getByText("openai")).toBeDefined();
expect(screen.getByText("google_maps")).toBeDefined();
});

View File

@@ -264,8 +264,7 @@ export function PlatformCostContent({ searchParams }: Props) {
value: Math.round(
dashboard.avg_output_tokens_per_request ?? 0,
).toLocaleString(),
subtitle:
"Completion tokens per request (response length)",
subtitle: "Completion tokens per request (response length)",
},
{
label: "Total Tokens",