test(proxy): cover inherited moderation overrides through during_call_hook

Replaces the capability flag assertion with a behavioral test that dispatches an
async_moderation_hook inherited from a parent class, and drops the dispatch
docstring that restated the code

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
yucheng 2026-09-17 05:00:01 +00:00
parent 2cbfd280e9
commit 719d7a1983
2 changed files with 17 additions and 10 deletions

View file

@ -2645,10 +2645,6 @@ class ProxyLogging:
user_api_key_dict: UserAPIKeyAuth | None,
call_type: CallTypesLiteral,
):
"""
Runs the async_moderation_hook() of every CustomGuardrail, and of every
CustomLogger that overrides it, in parallel
"""
caps: Final = ProxyLogging._callback_capabilities()
if not caps.has_guardrail and not caps.has_moderation_override:
return data

View file

@ -652,13 +652,24 @@ async def test_during_call_hook_skips_custom_logger_moderation_without_auth(monk
assert moderator.moderated == []
def test_callback_capabilities_detects_custom_logger_moderation_override(monkeypatch):
ProxyLogging._callback_capabilities_cache.clear()
monkeypatch.setattr(litellm, "callbacks", [CustomLogger(), CustomGuardrail()])
assert ProxyLogging._callback_capabilities().has_moderation_override is False
class _InheritsModerationOverride(_RejectsInModeration):
pass
monkeypatch.setattr(litellm, "callbacks", [_RejectsInModeration()])
assert ProxyLogging._callback_capabilities().has_moderation_override is True
@pytest.mark.asyncio
async def test_during_call_hook_runs_moderation_override_inherited_from_parent(monkeypatch):
moderator = _InheritsModerationOverride()
monkeypatch.setattr(litellm, "callbacks", [moderator])
with pytest.raises(HTTPException) as exc_info:
await ProxyLogging(user_api_key_cache=DualCache()).during_call_hook(
data={"messages": [{"role": "user", "content": "hi"}]},
user_api_key_dict=UserAPIKeyAuth(api_key="sk-1234"),
call_type="acompletion",
)
assert exc_info.value.status_code == 400
assert moderator.moderated == ["acompletion"]
@pytest.mark.asyncio