from app.intent.intent_analyzer import IntentAnalyzer
from app.models.intent import IntentResult, QueryIntent
from app.retrieval.query_rewriter import apply_query_rewrite


def test_apply_query_rewrite_uses_tier2_rewrite():
    intent = IntentResult(
        type=QueryIntent.CODE_LOOKUP,
        confidence=0.9,
        rewritten_query="ProcessDelta symbol location",
    )
    assert apply_query_rewrite(intent, "where is ProcessDelta") == "ProcessDelta symbol location"


def test_apply_query_rewrite_boosts_crawl_auth_questions():
    intent = IntentAnalyzer().analyze("how does crawl authentication work?")
    rewritten = apply_query_rewrite(intent, "how does crawl authentication work?")
    assert "AuthProfile" in rewritten
    assert "AuthContext" in rewritten


def test_apply_query_rewrite_leaves_unrelated_questions():
    intent = IntentAnalyzer().analyze("What does the crawler do?")
    rewritten = apply_query_rewrite(intent, "What does the crawler do?")
    assert rewritten == "What does the crawler do?"
