import pytest from app.services.literature_contract import LiteratureRequest, build_deterministic_contract def test_latest_author_request_is_singular_and_date_ranked(): result = build_deterministic_contract( "I need the latest paper of Jonas Gehring", LiteratureRequest(), ) assert result.operation == "author_works" assert result.author_names == ["Jonas Gehring"] assert result.ranking == "publication_date" assert result.result_limit == 1 def test_top_five_2026_by_citations_is_year_bounded(): result = build_deterministic_contract( "What are the top 5 papers of 2026 by citation?", LiteratureRequest(), ) assert result.operation == "ranked_papers" assert result.year_start == result.year_end == 2026 assert result.ranking == "citation_count" assert result.result_limit == 5 @pytest.mark.parametrize( ("query", "direction"), [ ("top 5 papers that cite Attention Is All You Need", "cites_seed"), ("top 5 papers Attention Is All You Need cites", "cited_by_seed"), ], ) def test_citation_direction_is_explicit(query, direction): result = build_deterministic_contract(query, LiteratureRequest()) assert result.citation_direction == direction assert result.result_limit == 5 assert result.ranking == "citation_count" def test_explicit_author_constraint_survives_planner_topics(): planned = LiteratureRequest(topics=["sequence modeling"], result_limit=5) result = build_deterministic_contract("latest paper by Jonas Gehring", planned) assert result.author_names == ["Jonas Gehring"] assert result.topics == ["sequence modeling"] assert result.result_limit == 1