File size: 2,144 Bytes
0cd3dc5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import sys
import os
import pytest
import json

# Add project root to path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from services.query_decomposition import QueryDecomposerService
from services.graph_planner import GraphPlannerService
from services.context_organization import ContextOrganizationService
from services.legal_reasoner import LegalReasonerService
from services.quality_assurance import QualityAssuranceService

@pytest.fixture
def decomposer():
    return QueryDecomposerService()

@pytest.fixture
def planner():
    return GraphPlannerService()

def test_decomposer(decomposer):
    """Test Query Decomposer returns valid JSON structure"""
    query = "Explain Article 21"
    result = decomposer.decompose(query)
    
    assert isinstance(result, dict)
    assert "query_type" in result
    assert "intent" in result
    assert "entities" in result
    print(f"\n✅ Decomposer Output: {json.dumps(result, indent=2)}")

def test_planner(planner):
    """Test Graph Planner returns valid Tree Routing JSON"""
    # Mock classification input
    classification = {
        "query_type": "simple_article",
        "intent": "explain",
        "entities": {"articles": ["21"]},
        "raw_query": "Explain Article 21"
    }
    
    plan = planner.generate_plan(classification)
    
    assert isinstance(plan, dict)
    assert "tree_start_node" in plan
    assert "cypher_queries" in plan
    assert "qdrant_scope" in plan
    print(f"\n✅ Planner Output: {json.dumps(plan, indent=2)}")

def test_context_organizer():
    """Test Context Organizer formats chunks"""
    organizer = ContextOrganizationService()
    fake_chunks = [{"text": "Article 21: No person...", "metadata": {"year": 1950}}]
    
    context = organizer.organize_context(fake_chunks)
    assert isinstance(context, dict)
    assert "context_block" in context or "temporal_narrative" in context
    print("\n✅ Organizer Output: SUCCESS")

if __name__ == "__main__":
    # Manual run
    d = QueryDecomposerService()
    test_decomposer(d)
    p = GraphPlannerService()
    test_planner(p)
    test_context_organizer()