mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-15 09:12:18 +00:00
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>
This commit is contained in:
parent
159037df7b
commit
2a61a6c48c
3 changed files with 32 additions and 35 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(<GuardrailInfoView guardrailId="123" onClose={() => {}} accessToken="tok" isAdmin={false} />);
|
||||
|
|
|
|||
|
|
@ -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> = {
|
||||
guardrail_id: "cfg-2",
|
||||
guardrail_name: "Config Headroom",
|
||||
guardrail_definition_location: GuardrailDefinitionLocation.CONFIG,
|
||||
enabled: false,
|
||||
});
|
||||
};
|
||||
const guardrail = makeGuardrail(disabledConfigOverrides);
|
||||
render(<GuardrailTable guardrailsList={[guardrail]} {...baseProps} onToggleEnabled={onToggleEnabled} />);
|
||||
|
||||
const toggle = screen.getByRole("switch", { name: "Enable Config Headroom" });
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue