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.
This commit is contained in:
parent
cf78349911
commit
07d70a0345
1 changed files with 22 additions and 0 deletions
|
|
@ -519,6 +519,28 @@ class TestConvertMessages:
|
||||||
assert tool_block["content"] == "result"
|
assert tool_block["content"] == "result"
|
||||||
assert tool_block["cache_control"] == {"type": "ephemeral"}
|
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
|
# Build kwargs
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue