Remove limit from admin UI numerical input fix (#15991)

This commit is contained in:
yuneng-jiang 2025-10-27 17:20:58 -07:00 • committed by GitHub
parent 4ed9c7d7f2
commit 64167b7e34
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 4 deletions

View file

@ -332,3 +332,25 @@ describe("KeyInfoView handleKeyUpdate premium guard", () => {
expect(sentPayload.key).toBe("tok_123");
});
});
describe("KeyInfoView handleKeyUpdate empty strings", () => {
["tpm_limit", "rpm_limit", "max_parallel_requests", "max_budget"].forEach((limit) => {
it(`maps empty strings to null for ${limit}`, async () => {
renderView(true); // premiumUser = true
fireEvent.click(screen.getByText("Edit Settings"));
(globalThis as any).__TEST_FORM_VALUES = {
token: "tok_123",
[limit]: "",
};
fireEvent.click(screen.getByText("Mock Submit"));
await waitFor(() => expect(keyUpdateCallMock).toHaveBeenCalled());
const [sentAccessToken, sentPayload] = keyUpdateCallMock.mock.calls[0];
expect(sentAccessToken).toBe("access_abc");
expect(sentPayload[limit]).toBeNull();
});
});
});

View file

@ -144,10 +144,10 @@ export default function KeyInfoView({
delete formValues.mcp_tool_permissions;
}
// Handle max_budget empty string
if (formValues.max_budget === "") {
formValues.max_budget = null;
}
formValues.max_budget = mapEmptyStringToNull(formValues.max_budget);
formValues.tpm_limit = mapEmptyStringToNull(formValues.tpm_limit);
formValues.rpm_limit = mapEmptyStringToNull(formValues.rpm_limit);
formValues.max_parallel_requests = mapEmptyStringToNull(formValues.max_parallel_requests);
// Convert metadata back to an object if it exists and is a string
if (formValues.metadata && typeof formValues.metadata === "string") {