test(anthropic): cover malformed content blocks in the survivor predicate

_survives_assistant_conversion had a separate non-dict guard that no test reached,
since _is_empty_text_block already rejects non-dict blocks before the predicate runs
on them in practice. Folding the check into the type lookup keeps the same behaviour
for bare strings and blocks without a type key, with no unreachable branch.

Extends the sibling-block test with a block missing its type key.
This commit is contained in:
tbartik 2026-07-27 22:57:19 +02:00
parent fd83156073
commit 4932047b2e
No known key found for this signature in database
GPG key ID: D9D2D421D56FDB70
2 changed files with 3 additions and 4 deletions

View file

@ -2024,9 +2024,7 @@ def _is_empty_text_block(block: object) -> bool:
def _survives_assistant_conversion(block: object) -> bool:
if not isinstance(block, dict):
return False
block_type = block.get("type")
block_type = block.get("type") if isinstance(block, dict) else None
if not isinstance(block_type, str) or block_type == "text":
return False
if block_type == "thinking":

View file

@ -508,8 +508,9 @@ class TestMessageSanitization:
{"type": "image_url", "image_url": {"url": "data:image/png;base64,aGk="}},
{"type": "thinking", "thinking": ""},
{"type": "unknown_future_block"},
{"no_type_key": "malformed"},
],
ids=["image_url", "unsignable_thinking", "unknown_type"],
ids=["image_url", "unsignable_thinking", "unknown_type", "missing_type"],
)
def test_empty_text_kept_when_sibling_block_would_not_survive(self, sibling_block):
"""