Arag / tests /unit /test_upsell_cache.py
AuthorBot
Wire upsell strategy into LLM prompts for humanistic persuasion.
a0ab367
Raw
History Blame Contribute Delete
842 Bytes
"""Cache stores raw answers; upsell layer is session-specific."""
from app.services.pipeline.cache import CachedAnswer, cache_get, cache_key, cache_set, invalidate_book_cache
def test_cache_stores_raw_answer_not_formatted_response():
key = cache_key("author-1", "book-1", "Who is the hero?")
invalidate_book_cache("author-1", "book-1")
cache_set(
key,
CachedAnswer(
raw_response="The hero is Marcus — quiet, stubborn, and hiding something.",
faithfulness_score=0.95,
top_book_ids=["book-1"],
intent="question",
intent_confidence=0.92,
),
)
hit = cache_get(key)
assert hit is not None
assert hit.raw_response.startswith("The hero is Marcus")
assert not hasattr(hit, "response")
assert not hasattr(hit, "link_shown")