Files
OpenJarvis/tests/engine/test_cache_breakpoint.py
Tarun SureshandClaude Opus 4.6 981f665913 feat: add Anthropic prompt cache breakpoint annotation
Add _annotate_anthropic_cache helper that annotates system messages
with cache_control for Anthropic prompt caching.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 18:42:54 +00:00

38 lines
1.3 KiB
Python

from __future__ import annotations
def test_anthropic_cache_breakpoint_added():
from openjarvis.engine.cloud import _annotate_anthropic_cache
messages = [
{"role": "system", "content": "You are Jarvis. ## Persona\nHelpful assistant."},
{"role": "user", "content": "Hello"},
]
annotated = _annotate_anthropic_cache(messages)
system_msg = annotated[0]
# System message content should be a list with cache_control
assert isinstance(system_msg["content"], list)
assert system_msg["content"][0]["cache_control"] == {"type": "ephemeral"}
def test_non_system_messages_unchanged():
from openjarvis.engine.cloud import _annotate_anthropic_cache
messages = [
{"role": "user", "content": "Hello"},
{"role": "assistant", "content": "Hi there"},
]
annotated = _annotate_anthropic_cache(messages)
assert annotated[0]["content"] == "Hello"
assert annotated[1]["content"] == "Hi there"
def test_already_list_content_gets_cache_control():
from openjarvis.engine.cloud import _annotate_anthropic_cache
messages = [
{"role": "system", "content": [{"type": "text", "text": "You are Jarvis."}]},
]
annotated = _annotate_anthropic_cache(messages)
assert annotated[0]["content"][0]["cache_control"] == {"type": "ephemeral"}