From 2a61a6c48cfbe568f2b4ca76bb6ed00124e03965 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 8 Sep 2026 02:50:05 +0000 Subject: [PATCH] test(guardrails): name test fixtures to stay under lint budget and allowlist enabled toggle in endpoint audit Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../endpointaudit/coverage_allowlist.txt | 1 + .../_components/guardrail_info.test.tsx | 61 +++++++++---------- .../_components/guardrail_table.test.tsx | 5 +- 3 files changed, 32 insertions(+), 35 deletions(-) diff --git a/terraform/provider/tools/endpointaudit/coverage_allowlist.txt b/terraform/provider/tools/endpointaudit/coverage_allowlist.txt index 6bc8947e89f..12788d6d6d6 100644 --- a/terraform/provider/tools/endpointaudit/coverage_allowlist.txt +++ b/terraform/provider/tools/endpointaudit/coverage_allowlist.txt @@ -60,6 +60,7 @@ POST /cache/settings/test POST /coordination_redis/settings/test GET /guardrails/submissions GET /guardrails/submissions/{guardrail_id} +PATCH /guardrails/{guardrail_id}/enabled # runtime kill switch, like model/customer block; not desired state POST /credentials/migrate-encryption POST /customer/block POST /customer/unblock diff --git a/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_info.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_info.test.tsx index d6defb52843..54469cc24c7 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_info.test.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_info.test.tsx @@ -37,6 +37,29 @@ vi.mock("./content_filter/ContentFilterManager", () => ({ }), })); +const preCallUISettings = { + supported_entities: [], + supported_actions: [], + pii_entity_categories: [], + supported_modes: ["pre_call"], +}; + +const disabledConfigGuardrail = { + guardrail_id: "cfg-1", + guardrail_name: "Headroom", + litellm_params: { guardrail: "headroom", mode: "pre_call", default_on: true }, + guardrail_definition_location: "config", + enabled: false, +}; + +const disabledDbGuardrail = { + guardrail_id: "123", + guardrail_name: "Test Guardrail", + litellm_params: { guardrail: "presidio", mode: "pre_call", default_on: true }, + guardrail_definition_location: "db", + enabled: false, +}; + describe("Guardrail Info", () => { afterEach(() => { vi.clearAllMocks(); @@ -44,26 +67,9 @@ describe("Guardrail Info", () => { it("lets an admin re-enable a disabled config guardrail from the overview and refetches it", async () => { vi.mocked(networking.getGuardrailInfo) - .mockResolvedValueOnce({ - guardrail_id: "cfg-1", - guardrail_name: "Headroom", - litellm_params: { guardrail: "headroom", mode: "pre_call", default_on: true }, - guardrail_definition_location: "config", - enabled: false, - }) - .mockResolvedValueOnce({ - guardrail_id: "cfg-1", - guardrail_name: "Headroom", - litellm_params: { guardrail: "headroom", mode: "pre_call", default_on: true }, - guardrail_definition_location: "config", - enabled: true, - }); - vi.mocked(networking.getGuardrailUISettings).mockResolvedValue({ - supported_entities: [], - supported_actions: [], - pii_entity_categories: [], - supported_modes: ["pre_call"], - }); + .mockResolvedValueOnce(disabledConfigGuardrail) + .mockResolvedValueOnce({ ...disabledConfigGuardrail, enabled: true }); + vi.mocked(networking.getGuardrailUISettings).mockResolvedValue(preCallUISettings); vi.mocked(networking.getGuardrailProviderSpecificParams).mockResolvedValue({}); vi.mocked(networking.setGuardrailEnabledCall).mockResolvedValue({ guardrail_id: "cfg-1", enabled: true }); @@ -83,19 +89,8 @@ describe("Guardrail Info", () => { }); it("hides the enable switch from non-admins but still shows the state", async () => { - vi.mocked(networking.getGuardrailInfo).mockResolvedValue({ - guardrail_id: "123", - guardrail_name: "Test Guardrail", - litellm_params: { guardrail: "presidio", mode: "pre_call", default_on: true }, - guardrail_definition_location: "db", - enabled: false, - }); - vi.mocked(networking.getGuardrailUISettings).mockResolvedValue({ - supported_entities: [], - supported_actions: [], - pii_entity_categories: [], - supported_modes: ["pre_call"], - }); + vi.mocked(networking.getGuardrailInfo).mockResolvedValue(disabledDbGuardrail); + vi.mocked(networking.getGuardrailUISettings).mockResolvedValue(preCallUISettings); vi.mocked(networking.getGuardrailProviderSpecificParams).mockResolvedValue({}); render( {}} accessToken="tok" isAdmin={false} />); diff --git a/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_table.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_table.test.tsx index d14daeb6666..a295538b443 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_table.test.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/guardrails/_components/guardrail_table.test.tsx @@ -132,12 +132,13 @@ describe("GuardrailTable", () => { it("lets config guardrails be toggled even though they cannot be deleted", async () => { const user = userEvent.setup(); const onToggleEnabled = vi.fn(); - const guardrail = makeGuardrail({ + const disabledConfigOverrides: Partial = { guardrail_id: "cfg-2", guardrail_name: "Config Headroom", guardrail_definition_location: GuardrailDefinitionLocation.CONFIG, enabled: false, - }); + }; + const guardrail = makeGuardrail(disabledConfigOverrides); render(); const toggle = screen.getByRole("switch", { name: "Enable Config Headroom" });