mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-15 09:12:18 +00:00
test(guardrails): drop the empty request_data the pipeline never produces
The case claimed a caller that sends no metadata leaves request_data empty, which only held because the harness mocked the pre-call step away. Pre-call processing always attaches the key's identity, so assert that instead.
This commit is contained in:
parent
b1da2511cc
commit
b40e6ad4bf
1 changed files with 10 additions and 5 deletions
|
|
@ -2635,20 +2635,25 @@ async def test_apply_guardrail_attaches_key_identity_when_caller_sends_no_metada
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_apply_guardrail_omits_metadata_when_not_sent(mocker):
|
||||
"""Without metadata, request_data stays empty (backward-compatible)."""
|
||||
mock_guardrail = _patch_apply_guardrail_env(mocker, {"texts": ["ok"]})
|
||||
async def test_apply_guardrail_sends_the_key_identity_when_the_caller_sends_no_metadata(mocker):
|
||||
"""A caller that sends no metadata still arrives with the key's identity attached, because
|
||||
pre-call processing fills it in. An empty request_data is not a shape the pipeline produces."""
|
||||
mock_guardrail = _patch_apply_guardrail_env(
|
||||
mocker,
|
||||
{"texts": ["ok"]},
|
||||
processed_data={"guardrail_name": "test-guardrail", "metadata": {"user_api_key_alias": "billing-app"}},
|
||||
)
|
||||
|
||||
request = ApplyGuardrailRequest(guardrail_name="test-guardrail", text="hello")
|
||||
await apply_guardrail(
|
||||
fastapi_request=mocker.Mock(),
|
||||
request=request,
|
||||
user_api_key_dict=UserAPIKeyAuth(),
|
||||
user_api_key_dict=UserAPIKeyAuth(key_alias="billing-app"),
|
||||
)
|
||||
|
||||
mock_guardrail.apply_guardrail.assert_awaited_once_with(
|
||||
inputs={"texts": ["hello"]},
|
||||
request_data={},
|
||||
request_data={"metadata": {"user_api_key_alias": "billing-app"}},
|
||||
input_type="request",
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue