kumardatascience/Multi-Source-RAG-AI-System-with-Query-Routing
1
1"""Smoke tests โ basic sanity checks. No LLM calls, no network."""2 3import pytest4 5 6def test_python_works():7 """The most basic test: does Python even run?"""8 assert 1 + 1 == 29 10 11def test_string_operations():12 """Test the cleanup logic our router uses on Gemini's response."""13 raw = " RAG "14 cleaned = raw.strip().lower().split()15 decision = cleaned[0] if cleaned else "direct"16 assert decision == "rag"17 18 19def test_decision_fallback():20 """If Gemini returns garbage, we should fall back to 'direct'."""21 raw = "๐ค maybe both?"22 cleaned = raw.strip().lower().split()23 decision = cleaned[0] if cleaned else "direct"24 if decision not in {"direct", "rag", "web", "multi"}:25 decision = "direct"26 assert decision == "direct"27 28 29def test_empty_response_fallback():30 """If Gemini returns nothing, fall back to 'direct'."""31 raw = ""32 cleaned = raw.strip().lower().split()33 decision = cleaned[0] if cleaned else "direct"34 assert decision == "direct"35 36# --- Tests for real project code ---37 38import sys39from pathlib import Path40 41# Add src/app to Python's import path so we can import our modules42sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src" / "app"))43 44from llm import _build_system_prompt, BASE_SYSTEM_PROMPT45 46 47def test_system_prompt_without_context():48 """No context โ return base prompt unchanged."""49 result = _build_system_prompt(None)50 assert result == BASE_SYSTEM_PROMPT51 52 53def test_system_prompt_with_empty_context():54 """Empty string context โ also return base prompt."""55 result = _build_system_prompt("")56 assert result == BASE_SYSTEM_PROMPT57 58 59def test_system_prompt_with_context_includes_markers():60 """Context provided โ should include start/end markers."""61 fake_context = "Themis charges $5000 per project."62 result = _build_system_prompt(fake_context)63 assert "=== CONTEXT START ===" in result64 assert "=== CONTEXT END ===" in result65 assert fake_context in result66 67 68def test_system_prompt_with_context_contains_instructions():69 """The synthesis instructions should be present."""70 result = _build_system_prompt("some context")71 # Spot check: a few key instruction phrases72 assert "FROM YOUR DOCUMENTS" in result73 assert "FROM THE WEB" in result74 assert "conflict" in result.lower() 