"""Catalog routing must not reset to book intro during active Q&A.""" import pytest from app.services.intent import classify_intent from app.services.pipeline.guards import is_book_selection_turn, should_short_circuit_to_catalog def test_comparison_with_book_selected_does_not_short_circuit(): """LLM 'comparison' intent mid-conversation must reach RAG, not catalog intro.""" query = ( "That sounds interesting, but lots of books claim to have a 'bold vision.' " "What makes this one different, and why should I trust its arguments?" ) assert should_short_circuit_to_catalog(query, "comparison", "book-123") is False def test_book_comparison_with_book_selected_does_not_short_circuit(): query = ( "I'm browsing. Why should I buy Regime Change instead of " "the other political books here?" ) assert should_short_circuit_to_catalog(query, "book_comparison", "book-123") is False def test_catalog_question_still_short_circuits_with_book_selected(): assert should_short_circuit_to_catalog( "what books do you have", "question", "book-123", ) is True def test_comparison_without_book_still_short_circuits(): assert should_short_circuit_to_catalog( "which book should I read", "book_comparison", None, ) is True def test_book_title_remention_not_selection_after_turn_zero(): books = [type("Book", (), {"id": "b1", "title": "Regime Change: Toward a Postliberal Future"})()] assert is_book_selection_turn( "Regime Change: Toward a Postliberal Future", "b1", books, turn_count=0, ) is True assert is_book_selection_turn( "Regime Change: Toward a Postliberal Future", "b1", books, turn_count=3, ) is False @pytest.mark.asyncio async def test_critique_debate_classified_as_question(): query = ( "If I wanted to critique this book in a debate, what is its biggest weak point?" ) result = await classify_intent(query, history=[]) assert result.intent == "question"