From 91c0449c4569ce2a0beb6d9623928d3170149612 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Sun, 8 Nov 2026 11:13:23 -0800 Subject: [PATCH] test: wrap the new developer cache mark test lines at 120 characters Backport of #49412 to lts/1.108.x. Cherry-picked from 4ac3beafcaa25bcc27244d50e5dfdf855dd373fd (litellm_cache_injection_system_covers_developer) --- .../test_anthropic_cache_control_hook.py | 42 ++++++++++++++----- .../chat/test_provider_chat_translation.py | 16 ++++--- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/tests/unit/integrations/test_anthropic_cache_control_hook.py b/tests/unit/integrations/test_anthropic_cache_control_hook.py index 474f99e1a4e..7bd0be8faa5 100644 --- a/tests/unit/integrations/test_anthropic_cache_control_hook.py +++ b/tests/unit/integrations/test_anthropic_cache_control_hook.py @@ -1312,7 +1312,9 @@ def test_cache_control_hook_never_counts_fewer_marks_than_anthropic_receives_aft pytest.param("invoke/us.anthropic.claude-opus-5-5", "claude-opus-5-5", id="provider-left-out-of-the-params"), pytest.param("anthropic/my-claude-alias", "my-claude-alias", id="model-the-cost-map-does-not-know"), pytest.param( - "anthropic/my-unreadable-claude-alias", "my-unreadable-claude-alias", id="cost-map-entry-the-lookup-cannot-read" + "anthropic/my-unreadable-claude-alias", + "my-unreadable-claude-alias", + id="cost-map-entry-the-lookup-cannot-read", ), ], ) @@ -4941,7 +4943,9 @@ def test_cache_control_hook_injects_next_to_a_malformed_message_instead_of_raisi ] -_DEVELOPER_PREFIX: Final = "Policy handbook rule 8.3: record every backup decision in the tracker within 4 business days." +_DEVELOPER_PREFIX: Final = ( + "Policy handbook rule 8.3: record every backup decision in the tracker within 4 business days." +) _CLAUDE_ON_CONVERSE: Final = "bedrock/converse/us.anthropic.claude-haiku-5-5" _OFFLINE_AWS_CREDENTIALS: Final[Mapping[str, str]] = { "aws_access_key_id": "AKIADEVELOPERPREFIX", @@ -5131,7 +5135,9 @@ def test_system_injection_point_leaves_a_developer_prompt_unmarked_when_its_mark {"role": "developer", "content": [{"type": "text", "text": _DEVELOPER_PREFIX}]}, { "role": "user", - "content": [question_part if question_mark is None else {**question_part, "cache_control": question_mark}], + "content": [ + question_part if question_mark is None else {**question_part, "cache_control": question_mark} + ], }, ], tools=[dict(_WEATHER_TOOL) if tool_mark is None else {**_WEATHER_TOOL, "cache_control": tool_mark}], @@ -5165,7 +5171,9 @@ _TOOL_WITH_A_CACHE_CONTROL_ARGUMENT: Final = MappingProxyType( ("developer_mark", "points"), [ pytest.param(dict(_ONE_HOUR), None, id="client_mark"), - pytest.param(None, [{"location": "message", "role": "system", "control": dict(_ONE_HOUR)}], id="injection_point"), + pytest.param( + None, [{"location": "message", "role": "system", "control": dict(_ONE_HOUR)}], id="injection_point" + ), ], ) def test_one_hour_developer_prompt_stays_cached_beside_a_tool_argument_named_cache_control( @@ -5199,9 +5207,15 @@ _FIVE_MINUTE_TOOL: Final = MappingProxyType({**_WEATHER_TOOL, "cache_control": d @pytest.mark.parametrize( ("outside_fields", "keeps_the_mark"), [ - pytest.param({"tools": [dict(_TOOL_WITH_A_CACHE_CONTROL_ARGUMENT)]}, True, id="tool_argument_named_cache_control"), pytest.param( - {"tools": [{**_WEATHER_TOOL, "function": {**_WEATHER_TOOL["function"], "cache_control": dict(_FIVE_MINUTES)}}]}, + {"tools": [dict(_TOOL_WITH_A_CACHE_CONTROL_ARGUMENT)]}, True, id="tool_argument_named_cache_control" + ), + pytest.param( + { + "tools": [ + {**_WEATHER_TOOL, "function": {**_WEATHER_TOOL["function"], "cache_control": dict(_FIVE_MINUTES)}} + ] + }, False, id="mark_under_the_tool_function", ), @@ -5269,7 +5283,9 @@ def _server_search_replaying(results_field: str) -> dict[str, object]: "messages": [ { "role": "user", - "content": [{"type": "text", "text": "Which rule covers backups?", "cache_control": dict(_ONE_HOUR)}], + "content": [ + {"type": "text", "text": "Which rule covers backups?", "cache_control": dict(_ONE_HOUR)} + ], } ] } @@ -5305,7 +5321,9 @@ def test_system_injection_point_marks_a_developer_prompt_for_openai_prompt_cache "object": "chat.completion", "created": 0, "model": "gpt-5.6", - "choices": [{"index": 0, "message": {"role": "assistant", "content": "Rule 8.3."}, "finish_reason": "stop"}], + "choices": [ + {"index": 0, "message": {"role": "assistant", "content": "Rule 8.3."}, "finish_reason": "stop"} + ], "usage": {"prompt_tokens": 30, "completion_tokens": 4, "total_tokens": 34}, }, request=request, @@ -5510,7 +5528,9 @@ async def test_system_injection_point_leaves_a_developer_prompt_for_a_routed_gem "object": "chat.completion", "created": 0, "model": "gemini-3.8-flash", - "choices": [{"index": 0, "message": {"role": "assistant", "content": "Rule 8.3."}, "finish_reason": "stop"}], + "choices": [ + {"index": 0, "message": {"role": "assistant", "content": "Rule 8.3."}, "finish_reason": "stop"} + ], "usage": {"prompt_tokens": 30, "completion_tokens": 4, "total_tokens": 34}, }, ) @@ -5546,7 +5566,9 @@ def test_system_injection_point_marks_a_developer_prompt_for_a_gateway_alias_wit "object": "chat.completion", "created": 0, "model": "claude-haiku-5-5", - "choices": [{"index": 0, "message": {"role": "assistant", "content": "Rule 8.3."}, "finish_reason": "stop"}], + "choices": [ + {"index": 0, "message": {"role": "assistant", "content": "Rule 8.3."}, "finish_reason": "stop"} + ], "usage": {"prompt_tokens": 30, "completion_tokens": 4, "total_tokens": 34}, }, ) diff --git a/tests/unit/llms/base_llm/chat/test_provider_chat_translation.py b/tests/unit/llms/base_llm/chat/test_provider_chat_translation.py index ec7b1bb3aff..615770f7401 100644 --- a/tests/unit/llms/base_llm/chat/test_provider_chat_translation.py +++ b/tests/unit/llms/base_llm/chat/test_provider_chat_translation.py @@ -791,7 +791,9 @@ def test_developer_message_cache_control_survives_the_system_role_translation( @pytest.mark.parametrize( ("case", "unmarked_system"), [ - pytest.param(_BY_ID["anthropic_sonnet45"], [{"type": "text", "text": "Be a good bot!"}], id="anthropic_sonnet45"), + pytest.param( + _BY_ID["anthropic_sonnet45"], [{"type": "text", "text": "Be a good bot!"}], id="anthropic_sonnet45" + ), pytest.param( _BY_ID["bedrock_invoke_haiku"], [{"type": "text", "text": "Be a good bot!"}], id="bedrock_invoke_haiku" ), @@ -968,10 +970,10 @@ _BEDROCK_CONVERSE_SYSTEMS: Final = pytest.param( ) +@pytest.mark.parametrize(("case", "marked_system", "unmarked_system"), [_ANTHROPIC_SYSTEMS, _BEDROCK_CONVERSE_SYSTEMS]) @pytest.mark.parametrize( - ("case", "marked_system", "unmarked_system"), [_ANTHROPIC_SYSTEMS, _BEDROCK_CONVERSE_SYSTEMS] + ("user_marks", "keeps_developer_mark"), [(3, True), (4, False)], ids=["at_limit", "over_limit"] ) -@pytest.mark.parametrize(("user_marks", "keeps_developer_mark"), [(3, True), (4, False)], ids=["at_limit", "over_limit"]) def test_a_developer_cache_control_is_kept_only_within_the_four_mark_limit( case: _Case, marked_system: list[JsonValue], @@ -993,9 +995,7 @@ def test_a_developer_cache_control_is_kept_only_within_the_four_mark_limit( assert _request_body(route)["system"] == (marked_system if keeps_developer_mark else unmarked_system) -@pytest.mark.parametrize( - ("case", "marked_system", "unmarked_system"), [_ANTHROPIC_SYSTEMS, _BEDROCK_CONVERSE_SYSTEMS] -) +@pytest.mark.parametrize(("case", "marked_system", "unmarked_system"), [_ANTHROPIC_SYSTEMS, _BEDROCK_CONVERSE_SYSTEMS]) @pytest.mark.parametrize( ("user_marks", "developer_mark", "tool_mark", "keeps_developer_mark"), [ @@ -1030,9 +1030,7 @@ def test_a_developer_cache_control_counts_tool_marks_and_their_ttl( assert _request_body(route)["system"] == (marked_system if keeps_developer_mark else unmarked_system) -@pytest.mark.parametrize( - ("case", "marked_system", "unmarked_system"), [_ANTHROPIC_SYSTEMS, _BEDROCK_CONVERSE_SYSTEMS] -) +@pytest.mark.parametrize(("case", "marked_system", "unmarked_system"), [_ANTHROPIC_SYSTEMS, _BEDROCK_CONVERSE_SYSTEMS]) @pytest.mark.parametrize( ("developer_mark", "keeps_developer_mark"), [({"type": "ephemeral"}, True), ({"type": "ephemeral", "ttl": "1h"}, False)],