From 8e77d031888fe26922e2658be79ee48efab791e9 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Fri, 21 Aug 2026 12:19:58 +0530 Subject: [PATCH] test(prompt_caching): home empty-tools fallback test in TestPromptCachePlan It exercises build_prompt_cache_plan's direct_native_tool_cache fallback, not repeated apply on pre-decorated input, so it belongs with the other plan-layout tests rather than in TestApplyIdempotency. --- tests/agent/test_prompt_caching.py | 38 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/tests/agent/test_prompt_caching.py b/tests/agent/test_prompt_caching.py index 1e7a47709f..950b0b6dd2 100644 --- a/tests/agent/test_prompt_caching.py +++ b/tests/agent/test_prompt_caching.py @@ -168,6 +168,25 @@ class TestPromptCachePlan: assert "cache_control" in tools[-1] assert "cache_control" not in stripped[-1] + def test_direct_tool_cache_with_no_tools_falls_back_safely(self): + """direct_native_tool_cache=True with an empty tools list must fall + back to the message-only layout: exactly one marker per message here + (system + user + assistant), none on tools. + """ + messages = [ + {"role": "system", "content": "System prompt"}, + {"role": "user", "content": "Question"}, + {"role": "assistant", "content": "Answer"}, + ] + plan = build_prompt_cache_plan( + messages, + [], + native_anthropic=True, + direct_native_tool_cache=True, + ) + assert plan.marker_count == 3 + assert len(plan.tools) == 0 + class TestApplyCacheMarker: def test_tool_message_gets_top_level_marker_on_native_anthropic(self): @@ -584,25 +603,6 @@ class TestApplyIdempotency: assert caller_history == snapshot assert _count_cache_markers(result, []) <= 4 - def test_direct_tool_cache_with_no_tools_falls_back_safely(self): - """direct_native_tool_cache=True with an empty tools list must fall - back to the message-only layout: exactly one marker per message here - (system + user + assistant), none on tools. - """ - messages = [ - {"role": "system", "content": "System prompt"}, - {"role": "user", "content": "Question"}, - {"role": "assistant", "content": "Answer"}, - ] - plan = build_prompt_cache_plan( - messages, - [], - native_anthropic=True, - direct_native_tool_cache=True, - ) - assert plan.marker_count == 3 - assert len(plan.tools) == 0 -