The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test(ui): query the tokens cell by role instead of walking the DOM
ryan3b13a5fda968
diff --git a/ui/litellm-dashboard/src/components/view_logs/RequestLogsTableColumns.test.tsx b/ui/litellm-dashboard/src/components/view_logs/RequestLogsTableColumns.test.tsxindex d2c84173fd1..3c9e6543c1c 100644--- a/ui/litellm-dashboard/src/components/view_logs/RequestLogsTableColumns.test.tsx+++ b/ui/litellm-dashboard/src/components/view_logs/RequestLogsTableColumns.test.tsx@@ -1,4 +1,4 @@-import { render, screen, within } from "@testing-library/react";+import { render, screen } from "@testing-library/react";import userEvent from "@testing-library/user-event";import { describe, expect, it, vi } from "vitest";@@ -76,43 +76,37 @@ describe("Cost column", () => {});describe("Tokens column", () => {+ const sessionRow: Partial<LogEntry> = {+ request_id: "req-session-tokens",+ total_tokens: 10,+ prompt_tokens: 7,+ completion_tokens: 3,+ session_id: "sess-1",+ session_total_count: 3,+ };+it("shows the summed session token usage, not the representative call's tokens, for a multi-round session", () => {- renderRows([- logEntry({- request_id: "req-session-tokens",- total_tokens: 10,- prompt_tokens: 7,- completion_tokens: 3,- session_id: "sess-1",- session_total_count: 3,- session_total_tokens: 60,- session_total_prompt_tokens: 42,- session_total_completion_tokens: 18,- }),- ]);+ const aggregatedRow: Partial<LogEntry> = {+ ...sessionRow,+ session_total_tokens: 60,+ session_total_prompt_tokens: 42,+ session_total_completion_tokens: 18,+ };+ renderRows([logEntry(aggregatedRow)]);- const tokensCell = screen.getByText("60").closest("td")!;- expect(within(tokensCell).getByText("(42+18)")).toBeInTheDocument();- expect(within(tokensCell).getByText("session total")).toBeInTheDocument();+ const tokensCell = screen.getByRole("cell", { name: /\(42\+18\)/ });+ expect(tokensCell).toHaveTextContent("60");+ expect(tokensCell).toHaveTextContent("session total");expect(screen.queryByText("10")).not.toBeInTheDocument();expect(screen.queryByText("(7+3)")).not.toBeInTheDocument();});it("falls back to the call's own tokens with no session label when the backend sent no session token sums", () => {- renderRows([- logEntry({- request_id: "req-no-token-aggregate",- total_tokens: 10,- prompt_tokens: 7,- completion_tokens: 3,- session_id: "sess-2",- session_total_count: 3,- }),- ]);+ renderRows([logEntry(sessionRow)]);- const tokensCell = screen.getByText("10").closest("td")!;- expect(within(tokensCell).getByText("(7+3)")).toBeInTheDocument();- expect(within(tokensCell).queryByText("session total")).not.toBeInTheDocument();+ const tokensCell = screen.getByRole("cell", { name: /\(7\+3\)/ });+ expect(tokensCell).toHaveTextContent("10");+ expect(tokensCell).not.toHaveTextContent("session total");});});