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): pin wire contracts for key, model and MCP server forms (#40019)

yuneng-jianga2b7868a5bdb
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/editServerPayload.differential.test.ts b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/editServerPayload.differential.test.ts
index f9cab181e71..66786fac1c3 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/editServerPayload.differential.test.ts
+++ b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/editServerPayload.differential.test.ts
@@ -12,7 +12,7 @@ import {
} from "@/components/mcp_tools/types";
import { AUTH_TYPES_REQUIRING_CREDENTIALS } from "./createServerPayload";
import { TOOL_DISPLAY_NAME_PATTERN, normalizeEnvVars } from "./utils";
-import { buildEditServerPayload, type EditServerUiState } from "./editServerPayload";
+import { buildEditServerPayload, type EditServerFormValues, type EditServerUiState } from "./editServerPayload";
import { CASES, baseUi } from "./editServerPayload.differential.cases";
// GENERATED by scratchpad/emit_test.py. The body below is machine-extracted from
@@ -317,6 +317,47 @@ describe("buildEditServerPayload matches the pre-extraction handleSave body", ()
});
});
+const EDIT_FORM_VALUES: EditServerFormValues = {
+ server_name: "srv",
+ alias: "srv_alias",
+ description: "a server",
+ transport: "http",
+ url: "https://example.com/mcp",
+ auth_type: "none",
+ mcp_access_groups: [],
+ extra_headers: [],
+ static_headers: [],
+ env_vars: [],
+ allow_all_keys: false,
+ available_on_public_internet: true,
+};
+
+describe("buildEditServerPayload wire contract", () => {
+ it("carries an edited alias and the server identifier onto the wire", () => {
+ const result = buildEditServerPayload({ ...EDIT_FORM_VALUES, alias: "renamed" }, baseUi);
+
+ expect(result).toMatchObject({ kind: "ok", payload: { server_id: "srv_1", alias: "renamed" } });
+ });
+
+ it.fails(
+ "sends description as an explicit null when the field is cleared (expected to fail until the forms revamp, tri-state PATCH tracker: today the cleared field reaches the wire as an empty string)",
+ () => {
+ const result = buildEditServerPayload({ ...EDIT_FORM_VALUES, description: "" }, baseUi);
+
+ expect(result).toMatchObject({ kind: "ok", payload: { description: null } });
+ },
+ );
+
+ it.fails(
+ "sends only the server identifier and the edited alias (expected to fail until the forms revamp, tri-state PATCH tracker)",
+ () => {
+ const result = buildEditServerPayload({ ...EDIT_FORM_VALUES, alias: "renamed" }, baseUi);
+
+ expect(result).toStrictEqual({ kind: "ok", payload: { server_id: "srv_1", alias: "renamed" } });
+ },
+ );
+});
+
void ADMIN_CONFIG_CREDENTIAL_KEYS;
void AUTH_TYPE;
void AUTH_TYPES_REQUIRING_CREDENTIALS;
diff --git a/ui/litellm-dashboard/src/components/model_info_view.test.tsx b/ui/litellm-dashboard/src/components/model_info_view.test.tsx
index 768183907db..3db9418dfb9 100644
--- a/ui/litellm-dashboard/src/components/model_info_view.test.tsx
+++ b/ui/litellm-dashboard/src/components/model_info_view.test.tsx
@@ -1729,5 +1729,77 @@ describe("ModelInfoView", () => {
expect(payload.litellm_params.cache_control_injection_points).toEqual([{ location: "message", index: "2" }]);
});
});
+
+ const setInputCost = (value: string) => {
+ fireEvent.change(screen.getByPlaceholderText("Enter input cost"), { target: { value } });
+ };
+
+ it("carries an edited input cost and the model identifier onto the wire", async () => {
+ const user = userEvent.setup();
+ await enterEditMode(user);
+ setInputCost("5");
+ const payload = await save(user);
+
+ expect(mockModelPatchUpdateCall.mock.calls[0][2]).toBe("123");
+ expect(payload.litellm_params.input_cost_per_token).toBe(5 / 1_000_000);
+ });
+
+ it.fails(
+ "sends only the edited input cost (expected to fail until the forms revamp, tri-state PATCH tracker)",
+ async () => {
+ const user = userEvent.setup();
+ await enterEditMode(user);
+ setInputCost("5");
+ const payload = await save(user);
+
+ expect(payload).toStrictEqual({ litellm_params: { input_cost_per_token: 5 / 1_000_000 } });
+ },
+ );
+
+ const savePayloadAfterCostEditOnResolvedModel = async () => {
+ const resolved = {
+ ...defaultModelData,
+ model_info: {
+ ...defaultModelData.model_info,
+ max_input_tokens: 128_000,
+ mode: "chat",
+ supports_vision: true,
+ supports_function_calling: true,
+ },
+ };
+ mockUseModelsInfo.mockReturnValue({ data: { data: [resolved] }, isLoading: false, error: null });
+ mockModelInfoV1Call.mockResolvedValue({ data: [resolved] });
+ const user = userEvent.setup();
+ await enterEditMode(user);
+ setInputCost("5");
+ return save(user);
+ };
+
+ it.fails(
+ "leaves max_input_tokens off the wire when only the input cost is edited (expected to fail until the forms revamp, tri-state PATCH tracker)",
+ async () => {
+ const payload = await savePayloadAfterCostEditOnResolvedModel();
+
+ expect(payload.model_info).not.toHaveProperty("max_input_tokens");
+ },
+ );
+
+ it.fails(
+ "leaves mode off the wire when only the input cost is edited (expected to fail until the forms revamp, tri-state PATCH tracker)",
+ async () => {
+ const payload = await savePayloadAfterCostEditOnResolvedModel();
+
+ expect(payload.model_info).not.toHaveProperty("mode");
+ },
+ );
+
+ it.fails(
+ "leaves every supports_ capability off the wire when only the input cost is edited (expected to fail until the forms revamp, tri-state PATCH tracker)",
+ async () => {
+ const payload = await savePayloadAfterCostEditOnResolvedModel();
+
+ expect(Object.keys(payload.model_info).filter((key) => key.startsWith("supports_"))).toStrictEqual([]);
+ },
+ );
});
});
diff --git a/ui/litellm-dashboard/src/components/organisms/create_key_button.integration.test.tsx b/ui/litellm-dashboard/src/components/organisms/create_key_button.integration.test.tsx
index 045dcfa3ceb..3471ef00eb0 100644
--- a/ui/litellm-dashboard/src/components/organisms/create_key_button.integration.test.tsx
+++ b/ui/litellm-dashboard/src/components/organisms/create_key_button.integration.test.tsx
@@ -544,6 +544,37 @@ describe("CreateKey", () => {
expect((await createdPayload()).metadata).toBe('{"team":"research"}');
});
+
+ it("carries the typed key alias and the chosen team onto the wire", async () => {
+ state.teams = [{ team_id: "team-1", team_alias: "Team One", models: [] }];
+ await openModal({ teams: state.teams as unknown as Team[] });
+ await nameTheKey("wire-alias");
+ await userEvent.click(await screen.findByLabelText("Team"));
+ await userEvent.click(await screen.findByRole("option", { name: /Team One/ }));
+ await submit();
+
+ expect(await createdPayload()).toMatchObject({ key_alias: "wire-alias", team_id: "team-1" });
+ });
+
+ it("sends team_id as an explicit null when no team is chosen", async () => {
+ await openModal();
+ await nameTheKey();
+ await submit();
+
+ expect(await createdPayload()).toHaveProperty("team_id", null);
+ });
+
+ it.fails(
+ "adds no keys for an Optional Settings section the user opened but never filled (expected to fail until the forms revamp, tri-state PATCH tracker)",
+ async () => {
+ await openModal();
+ await nameTheKey();
+ await openSection(/Optional Settings/i);
+ await submit();
+
+ expect(await createdPayload()).toStrictEqual(ALL_CLOSED_PAYLOAD);
+ },
+ );
});
describe("key ownership", () => {
diff --git a/ui/litellm-dashboard/src/components/templates/key_edit_view.test.tsx b/ui/litellm-dashboard/src/components/templates/key_edit_view.test.tsx
index 8b506329595..4f732083c3e 100644
--- a/ui/litellm-dashboard/src/components/templates/key_edit_view.test.tsx
+++ b/ui/litellm-dashboard/src/components/templates/key_edit_view.test.tsx
@@ -2300,5 +2300,57 @@ describe("KeyEditView", () => {
});
expect(onSubmitMock.mock.calls[0][0]).toHaveProperty("tag_rpm_limit", { "test-tag": 7 });
});
+
+ const setRpmLimit = (value: string) => {
+ fireEvent.change(screen.getByLabelText("RPM Limit"), { target: { value } });
+ };
+
+ it("carries an edited RPM limit and the key identifier onto the wire", async () => {
+ const onSubmitMock = vi.fn().mockResolvedValue(undefined);
+ renderForPayload(onSubmitMock);
+ await screen.findByRole("button", { name: /save changes/i });
+
+ setRpmLimit("25");
+ await userEvent.click(screen.getByRole("button", { name: /save changes/i }));
+
+ await waitFor(() => {
+ expect(onSubmitMock).toHaveBeenCalledTimes(1);
+ });
+ expect(onSubmitMock.mock.calls[0][0]).toMatchObject({ token: "test-token-123", rpm_limit: "25" });
+ });
+
+ it.fails(
+ "sends max_budget as an explicit null when the field is cleared (expected to fail until the forms revamp, tri-state PATCH tracker: today the view hands KeyInfoView an empty string and handleKeyUpdate maps it to null)",
+ async () => {
+ const onSubmitMock = vi.fn().mockResolvedValue(undefined);
+ renderForPayload(onSubmitMock);
+ await screen.findByRole("button", { name: /save changes/i });
+
+ await userEvent.clear(screen.getByLabelText("Max Budget (USD)"));
+ await userEvent.click(screen.getByRole("button", { name: /save changes/i }));
+
+ await waitFor(() => {
+ expect(onSubmitMock).toHaveBeenCalledTimes(1);
+ });
+ expect(onSubmitMock.mock.calls[0][0]).toHaveProperty("max_budget", null);
+ },
+ );
+
+ it.fails(
+ "sends only the key identifier and the edited RPM limit (expected to fail until the forms revamp, tri-state PATCH tracker)",
+ async () => {
+ const onSubmitMock = vi.fn().mockResolvedValue(undefined);
+ renderForPayload(onSubmitMock);
+ await screen.findByRole("button", { name: /save changes/i });
+
+ setRpmLimit("25");
+ await userEvent.click(screen.getByRole("button", { name: /save changes/i }));
+
+ await waitFor(() => {
+ expect(onSubmitMock).toHaveBeenCalledTimes(1);
+ });
+ expect(onSubmitMock.mock.calls[0][0]).toStrictEqual({ token: "test-token-123", rpm_limit: "25" });
+ },
+ );
});
});
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 7817d4e7cea..7a27cc41e5e 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
@@ -1015,6 +1015,16 @@ describe("KeyInfoView", () => {
expect(keyUpdateCall).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({ policies: [] }));
});
+
+ it("puts the key identifier and an explicit null max_budget on the wire when the edit view hands over a cleared budget", async () => {
+ await enterEditMode({ ...MOCK_KEY_DATA, user_id: "proxy-admin-user" } as KeyResponse);
+ await editViewMocks.onSubmit!({ token: MOCK_KEY_DATA.token, max_budget: "" });
+
+ expect(keyUpdateCall).toHaveBeenCalledWith(
+ expect.anything(),
+ expect.objectContaining({ key: "test-token-123", max_budget: null }),
+ );
+ });
});
describe("MCP tool permissions on save", () => {