test(usage): cover unknown throughput branches

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
atul naik 2026-10-03 22:54:02 +05:30
parent 311494b59d
commit 5e2381f217
2 changed files with 17 additions and 0 deletions

View file

@ -8,6 +8,7 @@ import pytest
from litellm.proxy.db.daily_spend_bulk_upsert import (
DAILY_SPEND_TABLES,
_counter_value,
build_bulk_upsert,
conflict_key,
merge_by_conflict_key,
@ -90,6 +91,13 @@ def test_legacy_timed_requests_keep_timed_tokens_unknown_when_rows_merge():
assert merged[0][1]["timed_completion_tokens"] is None
def test_legacy_timed_request_serializes_unknown_token_total():
legacy = tag_txn(timed_requests=1)
del legacy["timed_completion_tokens"]
assert _counter_value("timed_completion_tokens", legacy) is None
def test_distinct_keys_are_not_merged_and_are_ordered_deterministically():
unordered = (tag_txn(tag="z-team"), tag_txn(tag="a-team"), tag_txn(tag="m-team"))

View file

@ -1902,6 +1902,15 @@ def test_grouping_sets_dispatcher_returns_no_throughput_for_legacy_rows_without_
assert day.breakdown.models["gpt-4o"].provider_breakdown["openai"].output_tokens_per_second is None
def test_combined_timed_tokens_propagates_unknown_measurements():
from litellm.proxy.management_endpoints.common_daily_activity import _combined_timed_completion_tokens
from litellm.types.proxy.management_endpoints.common_daily_activity import ProviderThroughputMetrics
existing = ProviderThroughputMetrics(timed_completion_tokens=10)
assert _combined_timed_completion_tokens(existing, None) is None
def test_grouping_sets_dispatcher_keeps_ptu_flat_cost_out_of_the_provider_breakdown():
"""Sentinel rows carry no provider, so their flat cost must not surface under the
"unknown" provider - the per-row path skips them for exactly the same reason."""