From 76ac63abd4eaf9e39d5a3e1e8b921e09a0e6f918 Mon Sep 17 00:00:00 2001 From: Ninad Phalak Date: Fri, 4 Sep 2026 02:47:19 -0500 Subject: [PATCH] test(guardrails): assert the depth bound instead of only reaching the end The depth test asserted nothing, so it passed whether or not the bound held, and the test-quality gate counted it as a zero-assert test. It now sends a shallow value alongside a 200-deep chain and asserts the shallow one is collected while the value past the bound is not. --- .../guardrail_hooks/test_llm_shield_proxy.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_llm_shield_proxy.py b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_llm_shield_proxy.py index b056756ac15..42781b441f7 100644 --- a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_llm_shield_proxy.py +++ b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_llm_shield_proxy.py @@ -392,15 +392,27 @@ class TestRequestCoverage: following it as far as it goes. """ guardrail = _guardrail() - _mock_post(guardrail, {"texts": ["ok"] * 64}) - deep: dict = {"type": "tool_result", "content": "jane.doe@example.com"} + captured: list = [] + + async def echo(url, headers, json, timeout): # noqa: ARG001 + captured.append(json["texts"]) + return _response({"texts": list(json["texts"])}) + + guardrail.async_handler.post = AsyncMock(side_effect=echo) # type: ignore[method-assign] + + deep: dict = {"type": "tool_result", "content": "past-the-bound@example.com"} for _ in range(200): deep = {"type": "tool_result", "content": [deep]} - data = {"messages": [{"role": "user", "content": [deep]}]} + data = {"messages": [{"role": "user", "content": [{"type": "text", "text": "shallow"}, deep]}]} await guardrail.async_pre_call_hook(user_api_key_dict=None, cache=None, data=data, call_type="completion") + sent = captured[0] + assert "shallow" in sent + assert "past-the-bound@example.com" not in sent, "the walk followed the chain past its bound" + assert len(sent) < 200 + @pytest.mark.asyncio async def test_responses_prompt_object_variables_are_redacted(self): """A PromptObject's variables are substituted into the prompt provider side.