From dfc92ba4cdfec8953cb306a8d617ea24c4318580 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Tue, 10 Nov 2026 10:13:02 -0800 Subject: [PATCH] test(caching): pin which max-age key wins when a request sends both The test now asserts that s-max-age decides on both the sync and the async cache read, so swapping the key order on both reads fails it --- tests/unit/caching/test_caching.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/unit/caching/test_caching.py b/tests/unit/caching/test_caching.py index 3d983e11210..b0ec0278034 100644 --- a/tests/unit/caching/test_caching.py +++ b/tests/unit/caching/test_caching.py @@ -1457,11 +1457,15 @@ def test_sync_completion_with_zero_s_maxage_skips_the_cached_response( @pytest.mark.asyncio @pytest.mark.parametrize( - "cache_controls", - [{"s-maxage": 0, "s-max-age": 60}, {"s-maxage": 60, "s-max-age": 0}, {"s-maxage": None, "s-max-age": 0}], + ("cache_controls", "serves_cached"), + [ + ({"s-maxage": 0, "s-max-age": 60}, True), + ({"s-maxage": 60, "s-max-age": 0}, False), + ({"s-maxage": None, "s-max-age": 0}, False), + ], ) -async def test_sync_and_async_completion_agree_on_the_cache_when_both_max_age_keys_are_sent( - monkeypatch: pytest.MonkeyPatch, cache_controls: dict[str, int | None] +async def test_sync_and_async_completion_follow_s_max_age_when_both_max_age_keys_are_sent( + monkeypatch: pytest.MonkeyPatch, cache_controls: dict[str, int | None], serves_cached: bool ) -> None: monkeypatch.setattr(litellm, "cache", Cache(type=LiteLLMCacheType.LOCAL)) sync_messages: Final = [{"role": "user", "content": f"sync both max-age keys {uuid.uuid4().hex}"}] @@ -1476,7 +1480,8 @@ async def test_sync_and_async_completion_agree_on_the_cache_when_both_max_age_ke model="gpt-4o-mini", messages=async_messages, cache=cache_controls, mock_response="second" ) - assert (sync_second.id == sync_first.id) == (async_second.id == async_first.id) + assert (sync_second.id == sync_first.id) is serves_cached + assert (async_second.id == async_first.id) is serves_cached @pytest.mark.asyncio