Skip to content

Commit 45c2488

Browse files
committed
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
1 parent f814458 commit 45c2488

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/strands/models/test_bedrock.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,6 +1913,32 @@ def test_format_request_filters_cache_point_content_blocks(model, model_id):
19131913
assert "extraField" not in cache_point_block
19141914

19151915

1916+
def test_format_request_cachepoint_after_text_separate_blocks(model, model_id):
1917+
"""Test that cachePoint after text is kept as separate block (Issue #1219).
1918+
1919+
This test verifies that cachePoint blocks are not merged into previous blocks,
1920+
but are formatted as standalone blocks. The Bedrock API requires each content
1921+
block to be a tagged union with exactly one key.
1922+
"""
1923+
messages = [
1924+
{
1925+
"role": "user",
1926+
"content": [
1927+
{"text": "Some long text content"},
1928+
{"cachePoint": {"type": "default"}},
1929+
],
1930+
}
1931+
]
1932+
1933+
formatted_request = model._format_request(messages)
1934+
1935+
# cachePoint should be a separate block, not merged into text block
1936+
content = formatted_request["messages"][0]["content"]
1937+
assert len(content) == 2
1938+
assert content[0] == {"text": "Some long text content"}
1939+
assert content[1] == {"cachePoint": {"type": "default"}}
1940+
1941+
19161942
def test_config_validation_warns_on_unknown_keys(bedrock_client, captured_warnings):
19171943
"""Test that unknown config keys emit a warning."""
19181944
BedrockModel(model_id="test-model", invalid_param="test")

0 commit comments

Comments
 (0)