From 5e2381f217fd1d7c9bc845e0fd48c809febac63b Mon Sep 17 00:00:00 2001 From: atul naik Date: Sat, 3 Oct 2026 22:54:02 +0530 Subject: [PATCH] test(usage): cover unknown throughput branches Co-authored-by: Cursor --- tests/unit/proxy/db/test_daily_spend_bulk_upsert.py | 8 ++++++++ .../management_endpoints/test_common_daily_activity.py | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/tests/unit/proxy/db/test_daily_spend_bulk_upsert.py b/tests/unit/proxy/db/test_daily_spend_bulk_upsert.py index 2101d5c2a4e..ff5b43e5b39 100644 --- a/tests/unit/proxy/db/test_daily_spend_bulk_upsert.py +++ b/tests/unit/proxy/db/test_daily_spend_bulk_upsert.py @@ -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")) diff --git a/tests/unit/proxy/management_endpoints/test_common_daily_activity.py b/tests/unit/proxy/management_endpoints/test_common_daily_activity.py index 7e3a80f75da..74b3b2ae463 100644 --- a/tests/unit/proxy/management_endpoints/test_common_daily_activity.py +++ b/tests/unit/proxy/management_endpoints/test_common_daily_activity.py @@ -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."""