Spaces:
Running
Running
| from __future__ import annotations | |
| from app.services.query_profile import ( | |
| analyze_query, | |
| build_deterministic_query_variants, | |
| ) | |
| def test_procedure_listing_query_gets_broad_retrieval_profile(): | |
| profile = analyze_query( | |
| "apa saja SOP penanganan keterlambatan penerbangan langkah per langkah" | |
| ) | |
| assert profile.needs_broad_retrieval is True | |
| assert profile.selection_top_k_floor >= 8 | |
| assert profile.candidate_multiplier_floor >= 7 | |
| assert profile.context_window_radius_floor >= 3 | |
| assert profile.prompt_context_limit >= 8 | |
| assert profile.prompt_char_budget >= 12_000 | |
| def test_simple_factual_query_keeps_small_fast_profile(): | |
| profile = analyze_query("berapa batas berat bagasi kabin?") | |
| assert profile.needs_broad_retrieval is False | |
| assert profile.needs_context_expansion is False | |
| assert profile.selection_top_k_floor == 0 | |
| assert profile.prompt_context_limit == 3 | |
| assert profile.prompt_char_budget == 3_500 | |
| def test_broad_query_builds_deduplicated_focus_variant(): | |
| profile = analyze_query( | |
| "apa saja SOP penanganan keterlambatan penerbangan langkah per langkah" | |
| ) | |
| assert build_deterministic_query_variants( | |
| "apa saja SOP penanganan keterlambatan penerbangan langkah per langkah", | |
| profile, | |
| ) == ["keterlambatan penerbangan"] | |
| def test_generic_sop_question_requires_clarification(): | |
| profile = analyze_query("apa saja SOP nya langkah per langkah") | |
| assert profile.needs_clarification is True | |
| def test_specific_sop_question_does_not_require_clarification(): | |
| profile = analyze_query( | |
| "apa saja SOP penanganan keterlambatan penerbangan langkah per langkah" | |
| ) | |
| assert profile.needs_clarification is False | |
| def test_comprehensive_non_sop_question_gets_broad_retrieval_profile(): | |
| profile = analyze_query( | |
| "apa saja persyaratan penanganan bagasi bermasalah secara lengkap?" | |
| ) | |
| assert profile.intent == "exhaustive" | |
| assert profile.needs_broad_retrieval is True | |
| assert profile.selection_top_k_floor >= 8 | |
| assert profile.context_window_radius_floor >= 3 | |
| assert profile.needs_clarification is False | |
| def test_comparison_question_gets_broad_retrieval_profile(): | |
| profile = analyze_query( | |
| "jelaskan perbedaan kompensasi delay kategori 2 dan kategori 5" | |
| ) | |
| assert profile.intent == "comparison" | |
| assert profile.needs_broad_retrieval is True | |
| assert profile.prompt_context_limit >= 8 | |
| def test_document_reference_question_gets_medium_profile(): | |
| profile = analyze_query( | |
| "jelaskan ketentuan PM 89 Tahun 2015 tentang keterlambatan penerbangan" | |
| ) | |
| assert profile.intent == "reference" | |
| assert profile.needs_broad_retrieval is False | |
| assert profile.needs_context_expansion is True | |
| assert profile.selection_top_k_floor >= 5 | |
| def test_generic_rules_question_requires_clarification(): | |
| profile = analyze_query("jelaskan semua aturan yang ada secara rinci") | |
| assert profile.needs_clarification is True | |