From 45c2488e0ce28391e7b6e8065ff4a88ae68217e7 Mon Sep 17 00:00:00 2001 From: minorun365 Date: Thu, 29 Jan 2026 02:11:09 +0900 Subject: [PATCH] test(bedrock): add regression test for cachePoint as separate block Add test to verify cachePoint blocks are formatted as standalone blocks and not merged into previous content blocks. This confirms the fix from PR #1438 works correctly for the scenario reported in Issue #1219. Closes #1219 --- tests/strands/models/test_bedrock.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/strands/models/test_bedrock.py b/tests/strands/models/test_bedrock.py index e92018f35..f952c4b69 100644 --- a/tests/strands/models/test_bedrock.py +++ b/tests/strands/models/test_bedrock.py @@ -1913,6 +1913,32 @@ def test_format_request_filters_cache_point_content_blocks(model, model_id): assert "extraField" not in cache_point_block +def test_format_request_cachepoint_after_text_separate_blocks(model, model_id): + """Test that cachePoint after text is kept as separate block (Issue #1219). + + This test verifies that cachePoint blocks are not merged into previous blocks, + but are formatted as standalone blocks. The Bedrock API requires each content + block to be a tagged union with exactly one key. + """ + messages = [ + { + "role": "user", + "content": [ + {"text": "Some long text content"}, + {"cachePoint": {"type": "default"}}, + ], + } + ] + + formatted_request = model._format_request(messages) + + # cachePoint should be a separate block, not merged into text block + content = formatted_request["messages"][0]["content"] + assert len(content) == 2 + assert content[0] == {"text": "Some long text content"} + assert content[1] == {"cachePoint": {"type": "default"}} + + def test_config_validation_warns_on_unknown_keys(bedrock_client, captured_warnings): """Test that unknown config keys emit a warning.""" BedrockModel(model_id="test-model", invalid_param="test")