Repository navigation
fix(ui): use categorical colors for tier donut, trim redundant turn count #36300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
...tellm-dashboard/src/app/(dashboard)/cost-optimization/_components/TierTurnsChart.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| import { render, screen } from "@testing-library/react"; | ||
| import React from "react"; | ||
| import { describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import type { AutoRouterDeployment } from "@/app/(dashboard)/hooks/models/useModels"; | ||
|
|
||
| vi.mock("@/components/shared/charts", () => ({ | ||
| DonutChart: ({ label }: { label: string }) => <div data-testid="donut">{label}</div>, | ||
| SEQUENTIAL_COLOR_RAMP: ["indigo", "blue"], | ||
| chartColorValue: (color: string) => color, | ||
| })); | ||
|
|
||
| import TierTurnsChart, { tierDisplayLabel } from "./TierTurnsChart"; | ||
| import type { AutoRouterBenchmarkGroup, BenchmarkView } from "./autoRouterBenchmarks"; | ||
|
|
||
| const totalsOnly = { | ||
| sessions: 3, | ||
| turns: 9, | ||
| avg_turns_per_session: 3, | ||
| avg_session_seconds: 60, | ||
| avg_tokens_per_session: 100, | ||
| spend: 1, | ||
| saved_spend: 1, | ||
| baseline_spend: 2, | ||
| saved_pct: 50, | ||
| saved_per_session: 0.33, | ||
| cache: { | ||
| coverage_pct: 0, | ||
| hit_rate_pct: 0, | ||
| same_model: { turns: 0, hits: 0, hit_rate_pct: 0 }, | ||
| first_visit: { turns: 0, hits: 0, hit_rate_pct: 0 }, | ||
| return_to_tier: { turns: 0, hits: 0, hit_rate_pct: 0 }, | ||
| unordered_turns: 0, | ||
| return_misses_expired: 0, | ||
| return_misses_within_ttl: 0, | ||
| return_misses_unknown: 0, | ||
| ttl_5m_turns: 0, | ||
| ttl_1h_turns: 0, | ||
| }, | ||
| }; | ||
|
|
||
| const groupView = (overrides: Partial<AutoRouterBenchmarkGroup> = {}): BenchmarkView => ({ | ||
| label: "claude-auto", | ||
| stats: { | ||
| ...totalsOnly, | ||
| router_name: "claude-auto", | ||
| router_type: "complexity", | ||
| tier_turns: { SIMPLE: 3, COMPLEX: 1 }, | ||
| ...overrides, | ||
| } as AutoRouterBenchmarkGroup, | ||
| }); | ||
|
|
||
| const deployment = (config: unknown): AutoRouterDeployment => ({ | ||
| model_name: "claude-auto", | ||
| litellm_params: { model: "auto_router/claude-auto", complexity_router_config: config }, | ||
| }); | ||
|
|
||
| describe("tierDisplayLabel", () => { | ||
| it("prefers the admin's custom label for a canonical complexity tier", () => { | ||
| expect(tierDisplayLabel("SIMPLE", { SIMPLE: "Cheap" })).toBe("Cheap"); | ||
| }); | ||
|
|
||
| it("falls back to the canonical name when that tier has no custom label", () => { | ||
| expect(tierDisplayLabel("COMPLEX", { SIMPLE: "Cheap" })).toBe("Complex"); | ||
| expect(tierDisplayLabel("REASONING", undefined)).toBe("Reasoning"); | ||
| }); | ||
|
|
||
| it("shows a non-complexity tier verbatim, since no label map covers a quality router's tier", () => { | ||
| expect(tierDisplayLabel("3", { SIMPLE: "Cheap" })).toBe("3"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("TierTurnsChart", () => { | ||
| it("labels each slice with its tier and share of the tiered turns", () => { | ||
| render(<TierTurnsChart view={groupView()} autoRouters={[deployment({ tier_labels: { SIMPLE: "Cheap" } })]} />); | ||
|
|
||
| expect(screen.getByText("Cheap 75%")).toBeInTheDocument(); | ||
| expect(screen.getByText("Complex 25%")).toBeInTheDocument(); | ||
| expect(screen.getByTestId("donut")).toHaveTextContent("4 total turns"); | ||
| }); | ||
|
|
||
| it("reads tier_labels out of a config stored as a JSON string", () => { | ||
| const stored = JSON.stringify({ tier_labels: { SIMPLE: "Cheap" } }); | ||
| render(<TierTurnsChart view={groupView()} autoRouters={[deployment(stored)]} />); | ||
|
|
||
| expect(screen.getByText("Cheap 75%")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("uses canonical names when the router is not in the deployment list", () => { | ||
| render(<TierTurnsChart view={groupView()} autoRouters={[]} />); | ||
|
|
||
| expect(screen.getByText("Simple 75%")).toBeInTheDocument(); | ||
| expect(screen.getByText("Complex 25%")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("lists each tier's assigned models below its name and share", () => { | ||
| render( | ||
| <TierTurnsChart | ||
| view={groupView()} | ||
| autoRouters={[deployment({ tiers: { SIMPLE: ["gpt-4o-mini"], COMPLEX: ["gpt-4o", "claude-3-opus"] } })]} | ||
| />, | ||
| ); | ||
|
|
||
| expect(screen.getByText("gpt-4o-mini")).toBeInTheDocument(); | ||
| expect(screen.getByText("gpt-4o, claude-3-opus")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("widens a bare string tier (pinned single model) into its one-model list", () => { | ||
| render(<TierTurnsChart view={groupView()} autoRouters={[deployment({ tiers: { SIMPLE: "gpt-4o-mini" } })]} />); | ||
|
|
||
| expect(screen.getByText("gpt-4o-mini")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("omits the model line for a tier with no configured models", () => { | ||
| render(<TierTurnsChart view={groupView()} autoRouters={[deployment({ tiers: { SIMPLE: [] } })]} />); | ||
|
|
||
| expect(screen.getByText("Simple 75%")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("shows no models for a quality router's numeric tier, which has no per-tier model list", () => { | ||
| render( | ||
| <TierTurnsChart | ||
| view={groupView({ router_type: "quality", tier_turns: { "3": 3, "1": 1 } })} | ||
| autoRouters={[deployment({ quality_router_config: { available_models: ["gpt-4o"] } })]} | ||
| />, | ||
| ); | ||
|
|
||
| expect(screen.getByText("3 75%")).toBeInTheDocument(); | ||
| expect(screen.getByText("1 25%")).toBeInTheDocument(); | ||
| expect(screen.queryByText("gpt-4o")).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("ignores a same-named deployment of a different router type", () => { | ||
| const qualityDeployment = { | ||
| model_name: "claude-auto", | ||
| litellm_params: { model: "auto_router/claude-auto", quality_router_config: { available_models: ["gpt-4o"] } }, | ||
| }; | ||
|
|
||
| render( | ||
| <TierTurnsChart | ||
| view={groupView()} // complexity router | ||
| autoRouters={[qualityDeployment] as AutoRouterDeployment[]} | ||
| />, | ||
| ); | ||
|
|
||
| // No complexity_router_config on the quality deployment, so no tier labels are read, | ||
| // falling back to canonical names. No models are shown (quality config doesn't have tiers). | ||
| expect(screen.getByText("Simple 75%")).toBeInTheDocument(); | ||
| expect(screen.queryByText("gpt-4o")).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("renders nothing for the all-routers view, which carries no router identity", () => { | ||
| const { container } = render( | ||
| <TierTurnsChart view={{ label: "All auto-routers", stats: totalsOnly }} autoRouters={[]} />, | ||
| ); | ||
|
|
||
| expect(container).toBeEmptyDOMElement(); | ||
| }); | ||
|
|
||
| it("renders nothing when the router recorded no tiers", () => { | ||
| const { container } = render(<TierTurnsChart view={groupView({ tier_turns: {} })} autoRouters={[]} />); | ||
|
|
||
| expect(container).toBeEmptyDOMElement(); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These newly added comments violate the repository convention against adding source-code comments; the test name and assertions already communicate the scenario without them.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!