@@ -309,7 +309,17 @@ async def test_cache_point_adds_cache_control(allow_model_requests: None):
309309 # Verify cache_control was added to the right content block
310310 completion_kwargs = get_mock_chat_completion_kwargs (mock_client )[0 ]
311311 messages = completion_kwargs ['messages' ]
312- assert messages == snapshot ()
312+ assert messages == snapshot (
313+ [
314+ {
315+ 'role' : 'user' ,
316+ 'content' : [
317+ {'text' : 'Some context to cache' , 'type' : 'text' , 'cache_control' : {'type' : 'ephemeral' }},
318+ {'text' : 'Now the question' , 'type' : 'text' },
319+ ],
320+ }
321+ ]
322+ )
313323
314324
315325async def test_cache_point_multiple_markers (allow_model_requests : None ):
@@ -327,7 +337,13 @@ async def test_cache_point_multiple_markers(allow_model_requests: None):
327337 completion_kwargs = get_mock_chat_completion_kwargs (mock_client )[0 ]
328338 content = completion_kwargs ['messages' ][0 ]['content' ]
329339
330- assert content == snapshot ()
340+ assert content == snapshot (
341+ [
342+ {'text' : 'First chunk' , 'type' : 'text' , 'cache_control' : {'type' : 'ephemeral' }},
343+ {'text' : 'Second chunk' , 'type' : 'text' , 'cache_control' : {'type' : 'ephemeral' }},
344+ {'text' : 'Question' , 'type' : 'text' },
345+ ]
346+ )
331347
332348
333349async def test_cache_point_as_first_content_raises_error (allow_model_requests : None ):
@@ -368,7 +384,16 @@ async def test_cache_point_with_image_content(allow_model_requests: None):
368384 completion_kwargs = get_mock_chat_completion_kwargs (mock_client )[0 ]
369385 content = completion_kwargs ['messages' ][0 ]['content' ]
370386
371- assert content == snapshot ()
387+ assert content == snapshot (
388+ [
389+ {
390+ 'source' : {'type' : 'url' , 'url' : 'https://example.com/image.jpg' },
391+ 'type' : 'image' ,
392+ 'cache_control' : {'type' : 'ephemeral' },
393+ },
394+ {'text' : 'What is in this image?' , 'type' : 'text' },
395+ ]
396+ )
372397
373398
374399async def test_cache_point_in_otel_message_parts (allow_model_requests : None ):
@@ -384,7 +409,9 @@ async def test_cache_point_in_otel_message_parts(allow_model_requests: None):
384409 otel_parts = part .otel_message_parts (settings )
385410
386411 # Should have 2 text parts, CachePoint is skipped
387- assert otel_parts == snapshot ()
412+ assert otel_parts == snapshot (
413+ [{'type' : 'text' , 'content' : 'text before' }, {'type' : 'text' , 'content' : 'text after' }]
414+ )
388415
389416
390417def test_cache_control_unsupported_param_type ():
@@ -428,7 +455,21 @@ def tool_two() -> str:
428455 # Verify cache_control was added to the last tool
429456 completion_kwargs = get_mock_chat_completion_kwargs (mock_client )[0 ]
430457 tools = completion_kwargs ['tools' ]
431- assert tools == snapshot ()
458+ assert tools == snapshot (
459+ [
460+ {
461+ 'name' : 'tool_one' ,
462+ 'description' : '' ,
463+ 'input_schema' : {'additionalProperties' : False , 'properties' : {}, 'type' : 'object' },
464+ },
465+ {
466+ 'name' : 'tool_two' ,
467+ 'description' : '' ,
468+ 'input_schema' : {'additionalProperties' : False , 'properties' : {}, 'type' : 'object' },
469+ 'cache_control' : {'type' : 'ephemeral' },
470+ },
471+ ]
472+ )
432473
433474
434475async def test_anthropic_cache_instructions (allow_model_requests : None ):
@@ -450,7 +491,15 @@ async def test_anthropic_cache_instructions(allow_model_requests: None):
450491 # Verify system is a list with cache_control on last block
451492 completion_kwargs = get_mock_chat_completion_kwargs (mock_client )[0 ]
452493 system = completion_kwargs ['system' ]
453- assert system == snapshot ()
494+ assert system == snapshot (
495+ [
496+ {
497+ 'type' : 'text' ,
498+ 'text' : 'This is a test system prompt with instructions.' ,
499+ 'cache_control' : {'type' : 'ephemeral' },
500+ }
501+ ]
502+ )
454503
455504
456505async def test_anthropic_cache_tools_and_instructions (allow_model_requests : None ):
@@ -480,8 +529,24 @@ def my_tool(value: str) -> str:
480529 completion_kwargs = get_mock_chat_completion_kwargs (mock_client )[0 ]
481530 tools = completion_kwargs ['tools' ]
482531 system = completion_kwargs ['system' ]
483- assert tools == snapshot ()
484- assert system == snapshot ()
532+ assert tools == snapshot (
533+ [
534+ {
535+ 'name' : 'my_tool' ,
536+ 'description' : '' ,
537+ 'input_schema' : {
538+ 'additionalProperties' : False ,
539+ 'properties' : {'value' : {'type' : 'string' }},
540+ 'required' : ['value' ],
541+ 'type' : 'object' ,
542+ },
543+ 'cache_control' : {'type' : 'ephemeral' },
544+ }
545+ ]
546+ )
547+ assert system == snapshot (
548+ [{'type' : 'text' , 'text' : 'System instructions to cache.' , 'cache_control' : {'type' : 'ephemeral' }}]
549+ )
485550
486551
487552async def test_async_request_text_response (allow_model_requests : None ):
0 commit comments