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:
Ninad Phalak 2026-09-04 02:47:19 -05:00
parent 119ec62952
commit 76ac63abd4
No known key found for this signature in database
GPG key ID: 59119ED515433744

View file

@ -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.