From 80e55804af0fadb92b2c71a1a1fc907138429bc2 Mon Sep 17 00:00:00 2001 From: yuneng-jiang Date: Fri, 20 Mar 2026 23:27:02 -0700 Subject: [PATCH] [Fix] UI - Policies: Type accuracy and mutation guard for usePolicyVersions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Make PolicyVersionsResponse.versions optional (Policy[] | undefined) to match real API shape — select fallback handles normalization - Add policyName guard to useUpdatePolicyVersionStatus mutationFn to fail loudly instead of silently skipping cache invalidation - Add test for null policyName in updateStatus mutation Co-Authored-By: Claude Opus 4.6 --- .../hooks/policies/usePolicyVersions.test.ts | 11 +++++++++++ .../(dashboard)/hooks/policies/usePolicyVersions.ts | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ui/litellm-dashboard/src/app/(dashboard)/hooks/policies/usePolicyVersions.test.ts b/ui/litellm-dashboard/src/app/(dashboard)/hooks/policies/usePolicyVersions.test.ts index f773614388f..beb40742269 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/hooks/policies/usePolicyVersions.test.ts +++ b/ui/litellm-dashboard/src/app/(dashboard)/hooks/policies/usePolicyVersions.test.ts @@ -304,4 +304,15 @@ describe("useUpdatePolicyVersionStatus", () => { "Failed to promote to production: Not found" ); }); + + it("throws when policyName is null", async () => { + const { result } = renderHook( + () => useUpdatePolicyVersionStatus(null), + { wrapper } + ); + + await expect( + result.current.mutateAsync({ policyId: "v2", status: "published" }) + ).rejects.toThrow("Missing access token or policy name"); + }); }); diff --git a/ui/litellm-dashboard/src/app/(dashboard)/hooks/policies/usePolicyVersions.ts b/ui/litellm-dashboard/src/app/(dashboard)/hooks/policies/usePolicyVersions.ts index 3eb55acafbe..9dc78180cdc 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/hooks/policies/usePolicyVersions.ts +++ b/ui/litellm-dashboard/src/app/(dashboard)/hooks/policies/usePolicyVersions.ts @@ -17,7 +17,7 @@ export const policyVersionKeys = createQueryKeys("policyVersions"); export interface PolicyVersionsResponse { policy_name: string; - versions: Policy[]; + versions: Policy[] | undefined; total_count: number; } @@ -95,8 +95,8 @@ export const useUpdatePolicyVersionStatus = ( { policyId: string; status: "published" | "production" } >({ mutationFn: async ({ policyId, status }) => { - if (!accessToken) { - throw new Error("Missing access token"); + if (!accessToken || !policyName) { + throw new Error("Missing access token or policy name"); } return await updatePolicyVersionStatus(accessToken, policyId, status); },