test(responses): replace no-op regression test with real assertions against _stream_usage_tracking_updates

Greptile flagged that the async test body was a bare pass and the only
running assertion checked Python's `in` operator on a hardcoded list,
never touching production code. Parametrized over route_type against
the actual function, verified red-before-green by disabling the gate.
This commit is contained in:
STiFLeR7 2026-09-23 10:15:58 +05:30
parent 4229cea6cf
commit 874f920613
No known key found for this signature in database

View file

@ -1,44 +1,23 @@
from litellm.proxy.common_request_processing import ProxyBaseLLMRequestProcessing
import pytest
from litellm.proxy.common_request_processing import _stream_usage_tracking_updates
async def test_regression_issue_28553_stream_usage_whitelist():
"""
Test that stream_options.include_usage is only injected for chat/text completions,
and explicitly NOT for the Responses API (aresponses).
Fixes #28553.
"""
# Initialize processor with mock data
processor = ProxyBaseLLMRequestProcessing(data={"stream": True, "model": "gpt-4o"})
assert processor.data["stream"] is True
# 1. Test case: acompletion (Chat Completions) - SHOULD inject
# We call common_processing_pre_call_logic
# It takes many args, but we only care about usage tracking injection
# For simplicity, we can mock the rest of the method or just isolate the block
# Actually, the block uses:
# general_settings.get("always_include_stream_usage", False)
# self.data.get("stream", False)
# route_type in ["acompletion", "atext_completion"]
# Since we can't easily call the async method without full setup,
# let's verify the logic by running the isolated block if possible,
# or just trust the A2A test for now.
# Wait, I can try to call it by mocking everything it needs.
pass
def test_logic_verification():
# Manual verification of the whitelist logic
route_types = ["acompletion", "atext_completion", "aresponses", "arealtime", "auth"]
whitelist = ["acompletion", "atext_completion"]
results = {rt: (rt in whitelist) for rt in route_types}
assert results["acompletion"] is True
assert results["atext_completion"] is True
assert results["aresponses"] is False
assert results["arealtime"] is False
assert results["auth"] is False
@pytest.mark.parametrize(
"route_type,expect_injected",
[
("acompletion", True),
("atext_completion", False),
("aresponses", False),
("aget_responses", False),
("arealtime", False),
],
)
def test_stream_usage_only_injected_for_whitelisted_route_types(route_type, expect_injected):
updates = _stream_usage_tracking_updates(
data={"stream": True, "model": "gpt-4o"},
general_settings={},
route_type=route_type,
supports_stream_options=lambda: True,
)
assert ("stream_options" in updates) is expect_injected