From 07d70a034595ae3cd7b552ed0cbe0c107eb0e5c3 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Fri, 13 Mar 2026 20:44:25 -0700 Subject: [PATCH] test: cover empty cached Anthropic tool-call turns (#1222) Add an integration-style regression test that runs prompt caching output through the Anthropic adapter for an assistant tool-call turn with empty content. This locks in the empty-text-block hotfix merged in PR #1216. --- tests/test_anthropic_adapter.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_anthropic_adapter.py b/tests/test_anthropic_adapter.py index 1615c6cc..9ede37e4 100644 --- a/tests/test_anthropic_adapter.py +++ b/tests/test_anthropic_adapter.py @@ -519,6 +519,28 @@ class TestConvertMessages: assert tool_block["content"] == "result" assert tool_block["cache_control"] == {"type": "ephemeral"} + def test_empty_cached_assistant_tool_turn_converts_without_empty_text_block(self): + messages = apply_anthropic_cache_control([ + {"role": "system", "content": "System prompt"}, + {"role": "user", "content": "Find the skill"}, + { + "role": "assistant", + "content": "", + "tool_calls": [ + {"id": "tc_1", "function": {"name": "skill_view", "arguments": "{}"}}, + ], + }, + {"role": "tool", "tool_call_id": "tc_1", "content": "result"}, + ]) + + _, result = convert_messages_to_anthropic(messages) + + assistant_turn = next(msg for msg in result if msg["role"] == "assistant") + assistant_blocks = assistant_turn["content"] + + assert all(not (b.get("type") == "text" and b.get("text") == "") for b in assistant_blocks) + assert any(b.get("type") == "tool_use" for b in assistant_blocks) + # --------------------------------------------------------------------------- # Build kwargs