mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-11 03:38:38 +00:00
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.
This commit is contained in:
parent
119ec62952
commit
76ac63abd4
1 changed files with 15 additions and 3 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue