@@ -301,7 +301,17 @@ async def test_cache_point_adds_cache_control(allow_model_requests: None):
301301 # Verify cache_control was added to the right content block
302302 completion_kwargs = get_mock_chat_completion_kwargs (mock_client )[0 ]
303303 messages = completion_kwargs ['messages' ]
304- assert messages == snapshot ()
304+ assert messages == snapshot (
305+ [
306+ {
307+ 'role' : 'user' ,
308+ 'content' : [
309+ {'text' : 'Some context to cache' , 'type' : 'text' , 'cache_control' : {'type' : 'ephemeral' }},
310+ {'text' : 'Now the question' , 'type' : 'text' },
311+ ],
312+ }
313+ ]
314+ )
305315
306316
307317async def test_cache_point_multiple_markers (allow_model_requests : None ):
@@ -319,7 +329,13 @@ async def test_cache_point_multiple_markers(allow_model_requests: None):
319329 completion_kwargs = get_mock_chat_completion_kwargs (mock_client )[0 ]
320330 content = completion_kwargs ['messages' ][0 ]['content' ]
321331
322- assert content == snapshot ()
332+ assert content == snapshot (
333+ [
334+ {'text' : 'First chunk' , 'type' : 'text' , 'cache_control' : {'type' : 'ephemeral' }},
335+ {'text' : 'Second chunk' , 'type' : 'text' , 'cache_control' : {'type' : 'ephemeral' }},
336+ {'text' : 'Question' , 'type' : 'text' },
337+ ]
338+ )
323339
324340
325341async def test_cache_point_as_first_content_raises_error (allow_model_requests : None ):
@@ -360,7 +376,16 @@ async def test_cache_point_with_image_content(allow_model_requests: None):
360376 completion_kwargs = get_mock_chat_completion_kwargs (mock_client )[0 ]
361377 content = completion_kwargs ['messages' ][0 ]['content' ]
362378
363- assert content == snapshot ()
379+ assert content == snapshot (
380+ [
381+ {
382+ 'source' : {'type' : 'url' , 'url' : 'https://example.com/image.jpg' },
383+ 'type' : 'image' ,
384+ 'cache_control' : {'type' : 'ephemeral' },
385+ },
386+ {'text' : 'What is in this image?' , 'type' : 'text' },
387+ ]
388+ )
364389
365390
366391async def test_cache_point_in_otel_message_parts (allow_model_requests : None ):
@@ -376,7 +401,9 @@ async def test_cache_point_in_otel_message_parts(allow_model_requests: None):
376401 otel_parts = part .otel_message_parts (settings )
377402
378403 # Should have 2 text parts, CachePoint is skipped
379- assert otel_parts == snapshot ()
404+ assert otel_parts == snapshot (
405+ [{'type' : 'text' , 'content' : 'text before' }, {'type' : 'text' , 'content' : 'text after' }]
406+ )
380407
381408
382409def test_cache_control_unsupported_param_type ():
@@ -420,7 +447,21 @@ def tool_two() -> str:
420447 # Verify cache_control was added to the last tool
421448 completion_kwargs = get_mock_chat_completion_kwargs (mock_client )[0 ]
422449 tools = completion_kwargs ['tools' ]
423- assert tools == snapshot ()
450+ assert tools == snapshot (
451+ [
452+ {
453+ 'name' : 'tool_one' ,
454+ 'description' : '' ,
455+ 'input_schema' : {'additionalProperties' : False , 'properties' : {}, 'type' : 'object' },
456+ },
457+ {
458+ 'name' : 'tool_two' ,
459+ 'description' : '' ,
460+ 'input_schema' : {'additionalProperties' : False , 'properties' : {}, 'type' : 'object' },
461+ 'cache_control' : {'type' : 'ephemeral' },
462+ },
463+ ]
464+ )
424465
425466
426467async def test_anthropic_cache_instructions (allow_model_requests : None ):
@@ -442,7 +483,15 @@ async def test_anthropic_cache_instructions(allow_model_requests: None):
442483 # Verify system is a list with cache_control on last block
443484 completion_kwargs = get_mock_chat_completion_kwargs (mock_client )[0 ]
444485 system = completion_kwargs ['system' ]
445- assert system == snapshot ()
486+ assert system == snapshot (
487+ [
488+ {
489+ 'type' : 'text' ,
490+ 'text' : 'This is a test system prompt with instructions.' ,
491+ 'cache_control' : {'type' : 'ephemeral' },
492+ }
493+ ]
494+ )
446495
447496
448497async def test_anthropic_cache_tools_and_instructions (allow_model_requests : None ):
@@ -472,8 +521,24 @@ def my_tool(value: str) -> str:
472521 completion_kwargs = get_mock_chat_completion_kwargs (mock_client )[0 ]
473522 tools = completion_kwargs ['tools' ]
474523 system = completion_kwargs ['system' ]
475- assert tools == snapshot ()
476- assert system == snapshot ()
524+ assert tools == snapshot (
525+ [
526+ {
527+ 'name' : 'my_tool' ,
528+ 'description' : '' ,
529+ 'input_schema' : {
530+ 'additionalProperties' : False ,
531+ 'properties' : {'value' : {'type' : 'string' }},
532+ 'required' : ['value' ],
533+ 'type' : 'object' ,
534+ },
535+ 'cache_control' : {'type' : 'ephemeral' },
536+ }
537+ ]
538+ )
539+ assert system == snapshot (
540+ [{'type' : 'text' , 'text' : 'System instructions to cache.' , 'cache_control' : {'type' : 'ephemeral' }}]
541+ )
477542
478543
479544async def test_async_request_text_response (allow_model_requests : None ):
0 commit comments