From b53a8623a09263dc2000a7c99dcaedbd0724b9d1 Mon Sep 17 00:00:00 2001 From: yucheng Date: Wed, 30 Sep 2026 19:57:44 +0000 Subject: [PATCH] test(grayswan): capture monitor calls immutably in the unit test client Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../guardrails/guardrail_hooks/test_grayswan.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_grayswan.py b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_grayswan.py index 4c32c0bbd55..83b0be53fee 100644 --- a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_grayswan.py +++ b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_grayswan.py @@ -1,3 +1,6 @@ +from collections.abc import Mapping +from types import MappingProxyType + import pytest from fastapi import HTTPException @@ -595,12 +598,15 @@ def test_ensure_litellm_metadata_noop_when_already_present() -> None: class _CapturingClient: - def __init__(self, payload: dict | None = None): + def __init__(self, payload: dict[str, float] | None = None): self.payload = payload or {"violation": 0.0} - self.calls: list[dict] = [] + self.calls: tuple[Mapping[str, object], ...] = () async def post(self, *, url: str, headers: dict, json: dict, timeout: float): - self.calls.append({"url": url, "headers": headers, "json": json, "timeout": timeout}) + self.calls = ( + *self.calls, + MappingProxyType({"url": url, "headers": headers, "json": json, "timeout": timeout}), + ) return _DummyResponse(self.payload)