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.
This commit is contained in:
kshitijk4poor
2026-08-21 12:19:58 +05:30
committed by kshitij
parent c26357ad6a
commit 8e77d03188
+19 -19
View File
@@ -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