From b1a006ea66ffb209c237fe8ab4a4df70d9806877 Mon Sep 17 00:00:00 2001 From: yucheng Date: Mon, 14 Sep 2026 18:54:24 +0000 Subject: [PATCH] test(ui): hoist not_run guardrail fixtures out of inline call args Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../GuardrailViewer/GuardrailViewer.test.tsx | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/ui/litellm-dashboard/src/components/view_logs/GuardrailViewer/GuardrailViewer.test.tsx b/ui/litellm-dashboard/src/components/view_logs/GuardrailViewer/GuardrailViewer.test.tsx index 629383d5807..7f343211596 100644 --- a/ui/litellm-dashboard/src/components/view_logs/GuardrailViewer/GuardrailViewer.test.tsx +++ b/ui/litellm-dashboard/src/components/view_logs/GuardrailViewer/GuardrailViewer.test.tsx @@ -3,6 +3,7 @@ import { describe, it, expect, vi, beforeEach } from "vitest"; import userEvent from "@testing-library/user-event"; import { renderWithProviders, screen, waitFor } from "../../../../tests/test-utils"; import { + GuardrailInformation, makeBedrockResponse, makeEntity, makeGuardrailInformation, @@ -14,6 +15,24 @@ import GuardrailViewer from "@/components/view_logs/GuardrailViewer/GuardrailVie const PresidioPath = "@/components/view_logs/GuardrailViewer/PresidioDetectedEntities"; const BedrockPath = "@/components/view_logs/GuardrailViewer/BedrockGuardrailDetails"; +const skippedPreCall: Partial = { + guardrail_status: "not_run", + guardrail_mode: "pre_call", + guardrail_response: "no scannable content after message scoping", + start_time: null, + end_time: null, + duration: null, +}; + +const ranPostCall: Partial = { + guardrail_name: "ran-rail", + guardrail_status: "success", + guardrail_mode: "post_call", + start_time: 1_700_000_000, + end_time: 1_700_000_000.25, + duration: 0.25, +}; + describe("GuardrailViewer", () => { beforeEach(() => { vi.resetModules(); @@ -51,14 +70,7 @@ describe("GuardrailViewer", () => { it("renders not_run as NOT RUN (muted) and keeps it out of the evaluated and passed counts", async () => { const user = userEvent.setup(); - const data = makeGuardrailInformation({ - guardrail_status: "not_run", - guardrail_mode: "pre_call", - guardrail_response: "no scannable content after message scoping", - start_time: null, - end_time: null, - duration: null, - }); + const data = makeGuardrailInformation(skippedPreCall); renderWithProviders(); expect(screen.getByText(/0 guardrails evaluated/)).toBeInTheDocument(); @@ -74,22 +86,8 @@ describe("GuardrailViewer", () => { }); it("anchors the lifecycle timeline on timed entries when an untimed not_run entry sorts first", () => { - const skipped = makeGuardrailInformation({ - guardrail_name: "skipped-rail", - guardrail_status: "not_run", - guardrail_mode: "pre_call", - start_time: null, - end_time: null, - duration: null, - }); - const ran = makeGuardrailInformation({ - guardrail_name: "ran-rail", - guardrail_status: "success", - guardrail_mode: "post_call", - start_time: 1_700_000_000, - end_time: 1_700_000_000.25, - duration: 0.25, - }); + const skipped = makeGuardrailInformation({ ...skippedPreCall, guardrail_name: "skipped-rail" }); + const ran = makeGuardrailInformation(ranPostCall); renderWithProviders(); expect(screen.getByText(/1 guardrail evaluated/)).toBeInTheDocument();