Skip to content

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]

test(ui): run vitest unit tests in GitHub Actions and fix stale key-info tests (#34175)

yuneng-jiang28e93e42e5c9
diff --git a/.github/workflows/test-litellm-ui-unit.yml b/.github/workflows/test-litellm-ui-unit.yml
new file mode 100644
index 00000000000..f0f9f504752
--- /dev/null
+++ b/.github/workflows/test-litellm-ui-unit.yml
@@ -0,0 +1,57 @@
+name: UI Unit Tests
+permissions:
+ contents: read
+
+on:
+ pull_request:
+ branches:
+ - main
+ - litellm_internal_staging
+ - litellm_oss_staging
+ - "litellm_**"
+ push:
+ branches:
+ - litellm_internal_staging
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ ui-unit-tests:
+ runs-on: ubuntu-latest
+ timeout-minutes: 20
+ defaults:
+ run:
+ working-directory: ui/litellm-dashboard
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
+ with:
+ fetch-depth: 0
+ persist-credentials: false
+
+ - name: Setup Node.js
+ uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
+ with:
+ node-version: "20"
+ cache: "npm"
+ cache-dependency-path: ui/litellm-dashboard/package-lock.json
+
+ - name: Install dependencies
+ run: npm ci
+
+ - name: Run UI unit tests (Vitest)
+ env:
+ CI: "true"
+ BASE_SHA: ${{ github.event.pull_request.base.sha }}
+ run: |
+ if [ -n "$BASE_SHA" ]; then
+ echo "Pull request: running only tests related to changes since $BASE_SHA"
+ npm run test -- --run --changed "$BASE_SHA" --passWithNoTests \
+ --pool forks --poolOptions.forks.maxForks=4
+ else
+ echo "Push to $GITHUB_REF_NAME: running the full suite"
+ npm run test -- --run --pool forks --poolOptions.forks.maxForks=4
+ fi
diff --git a/ui/litellm-dashboard/src/components/page_metadata.ts b/ui/litellm-dashboard/src/components/page_metadata.ts
index 845e868b917..0f2ff639bb3 100644
--- a/ui/litellm-dashboard/src/components/page_metadata.ts
+++ b/ui/litellm-dashboard/src/components/page_metadata.ts
@@ -19,6 +19,7 @@ export const pageDescriptions: Record<string, string> = {
"tool-policies": "Configure tool use policies and permissions",
"vector-stores": "Manage vector databases for embeddings",
new_usage: "View usage analytics and metrics",
+ "cost-optimization": "Track and configure cost-saving features: prompt compression, caching, and auto routing",
logs: "Access request and response logs",
"guardrails-monitor": "Monitor guardrail performance and view logs",
users: "Manage internal user accounts and permissions",
diff --git a/ui/litellm-dashboard/src/components/templates/KeyInfoView.handleKeyUpdate.test.tsx b/ui/litellm-dashboard/src/components/templates/KeyInfoView.handleKeyUpdate.test.tsx
index 0bf0a48f285..6cf8a514e8b 100644
--- a/ui/litellm-dashboard/src/components/templates/KeyInfoView.handleKeyUpdate.test.tsx
+++ b/ui/litellm-dashboard/src/components/templates/KeyInfoView.handleKeyUpdate.test.tsx
@@ -267,6 +267,13 @@ vi.mock("@/app/(dashboard)/hooks/keys/useResetKeySpend", () => ({
}),
}));
+vi.mock("@/app/(dashboard)/hooks/keys/useSetKeyBlockedState", () => ({
+ useSetKeyBlockedState: vi.fn().mockReturnValue({
+ mutate: vi.fn(),
+ isPending: false,
+ }),
+}));
+
// useQueryClient also needs a provider; the delete-path invalidation is covered in key_info_view.test.tsx
vi.mock("@tanstack/react-query", async (importOriginal) => {
const actual = await importOriginal<typeof import("@tanstack/react-query")>();
diff --git a/ui/litellm-dashboard/src/components/templates/key_info_view.test.tsx b/ui/litellm-dashboard/src/components/templates/key_info_view.test.tsx
index 5e9156fcacf..e46c6fd5c30 100644
--- a/ui/litellm-dashboard/src/components/templates/key_info_view.test.tsx
+++ b/ui/litellm-dashboard/src/components/templates/key_info_view.test.tsx
@@ -147,6 +147,10 @@ describe("KeyInfoView", () => {
showSSOBanner: false,
};
+ const openMoreKeyActions = async () => {
+ await userEvent.click(await screen.findByRole("button", { name: /more key actions/i }));
+ };
+
it("should render tags", async () => {
vi.mocked(useAuthorized).mockReturnValue(baseUseAuthorizedMock);
@@ -203,8 +207,9 @@ describe("KeyInfoView", () => {
await waitFor(() => {
expect(screen.getByText("Regenerate Key")).toBeInTheDocument();
- expect(screen.getByText("Delete Key")).toBeInTheDocument();
});
+ await openMoreKeyActions();
+ expect(await screen.findByRole("menuitem", { name: /delete key/i })).toBeInTheDocument();
});
it("should allow team admin to modify key", async () => {
@@ -248,8 +253,9 @@ describe("KeyInfoView", () => {
await waitFor(() => {
expect(screen.getByText("Regenerate Key")).toBeInTheDocument();
- expect(screen.getByText("Delete Key")).toBeInTheDocument();
});
+ await openMoreKeyActions();
+ expect(await screen.findByRole("menuitem", { name: /delete key/i })).toBeInTheDocument();
});
it("should allow owner to modify their own key", async () => {
@@ -272,8 +278,9 @@ describe("KeyInfoView", () => {
await waitFor(() => {
expect(screen.getByText("Regenerate Key")).toBeInTheDocument();
- expect(screen.getByText("Delete Key")).toBeInTheDocument();
});
+ await openMoreKeyActions();
+ expect(await screen.findByRole("menuitem", { name: /delete key/i })).toBeInTheDocument();
});
it("should not allow other user to modify key", async () => {
@@ -295,7 +302,7 @@ describe("KeyInfoView", () => {
await waitFor(() => {
expect(screen.queryByText("Regenerate Key")).not.toBeInTheDocument();
- expect(screen.queryByText("Delete Key")).not.toBeInTheDocument();
+ expect(screen.queryByRole("button", { name: /more key actions/i })).not.toBeInTheDocument();
});
});
@@ -319,7 +326,7 @@ describe("KeyInfoView", () => {
await waitFor(() => {
expect(screen.queryByText("Regenerate Key")).not.toBeInTheDocument();
- expect(screen.queryByText("Delete Key")).not.toBeInTheDocument();
+ expect(screen.queryByRole("button", { name: /more key actions/i })).not.toBeInTheDocument();
});
});
@@ -363,7 +370,7 @@ describe("KeyInfoView", () => {
await waitFor(() => {
expect(screen.queryByText("Regenerate Key")).not.toBeInTheDocument();
- expect(screen.queryByText("Delete Key")).not.toBeInTheDocument();
+ expect(screen.queryByRole("button", { name: /more key actions/i })).not.toBeInTheDocument();
});
});
@@ -573,9 +580,8 @@ describe("KeyInfoView", () => {
/>,
);
- await waitFor(() => {
- expect(screen.getByRole("button", { name: /reset spend/i })).toBeInTheDocument();
- });
+ await openMoreKeyActions();
+ expect(await screen.findByRole("menuitem", { name: /reset spend/i })).toBeInTheDocument();
});
it("should show Reset Spend button for team admin of key's team", async () => {
@@ -614,9 +620,8 @@ describe("KeyInfoView", () => {
/>,
);
- await waitFor(() => {
- expect(screen.getByRole("button", { name: /reset spend/i })).toBeInTheDocument();
- });
+ await openMoreKeyActions();
+ expect(await screen.findByRole("menuitem", { name: /reset spend/i })).toBeInTheDocument();
});
it("should not show Reset Spend button for regular key owner", async () => {
@@ -638,9 +643,9 @@ describe("KeyInfoView", () => {
/>,
);
- await waitFor(() => {
- expect(screen.queryByRole("button", { name: /reset spend/i })).not.toBeInTheDocument();
- });
+ await openMoreKeyActions();
+ expect(await screen.findByRole("menuitem", { name: /delete key/i })).toBeInTheDocument();
+ expect(screen.queryByRole("menuitem", { name: /reset spend/i })).not.toBeInTheDocument();
});
});
@@ -663,11 +668,8 @@ describe("KeyInfoView", () => {
/>,
);
- await waitFor(() => {
- expect(screen.getByRole("button", { name: /reset spend/i })).toBeInTheDocument();
- });
-
- await userEvent.click(screen.getByRole("button", { name: /reset spend/i }));
+ await openMoreKeyActions();
+ await userEvent.click(await screen.findByRole("menuitem", { name: /reset spend/i }));
await waitFor(() => {
expect(screen.getByText("Reset Key Spend")).toBeInTheDocument();
@@ -694,11 +696,8 @@ describe("KeyInfoView", () => {
/>,
);
- await waitFor(() => {
- expect(screen.getByRole("button", { name: /reset spend/i })).toBeInTheDocument();
- });
-
- await userEvent.click(screen.getByRole("button", { name: /reset spend/i }));
+ await openMoreKeyActions();
+ await userEvent.click(await screen.findByRole("menuitem", { name: /reset spend/i }));
await waitFor(() => {
expect(screen.getByText("Reset Key Spend")).toBeInTheDocument();
@@ -808,7 +807,8 @@ describe("KeyInfoView", () => {
/>,
);
- await userEvent.click(await screen.findByRole("button", { name: /delete key/i }));
+ await openMoreKeyActions();
+ await userEvent.click(await screen.findByRole("menuitem", { name: /delete key/i }));
const confirmInput = await screen.findByPlaceholderText(MOCK_KEY_DATA.key_alias);
await userEvent.type(confirmInput, MOCK_KEY_DATA.key_alias);