mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
[Fix] UI - Policies: Type accuracy and mutation guard for usePolicyVersions
- 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 <noreply@anthropic.com>
This commit is contained in:
parent
8aa1ebfb07
commit
80e55804af
2 changed files with 14 additions and 3 deletions
|
|
@ -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");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue