File size: 3,726 Bytes
420bcec |
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
"""Tests for RAG system."""
import pytest
from pathlib import Path
import tempfile
import shutil
from src.rag import ProjectRAG
class TestProjectRAG:
"""Tests for ProjectRAG class."""
def test_rag_initialization(self, temp_data_dir):
"""Test RAG system initializes correctly."""
with tempfile.TemporaryDirectory() as persist_dir:
rag = ProjectRAG(temp_data_dir, persist_dir=Path(persist_dir))
assert rag is not None
assert rag.data_dir == temp_data_dir
def test_load_and_index(self, temp_data_dir):
"""Test loading and indexing meetings."""
with tempfile.TemporaryDirectory() as persist_dir:
rag = ProjectRAG(temp_data_dir, persist_dir=Path(persist_dir))
rag.load_and_index()
assert len(rag.meetings) == 1
assert rag.meetings[0].project_name == "test_project"
def test_get_all_projects(self, temp_data_dir):
"""Test getting all project names."""
with tempfile.TemporaryDirectory() as persist_dir:
rag = ProjectRAG(temp_data_dir, persist_dir=Path(persist_dir))
rag.load_and_index()
projects = rag.get_all_projects()
assert "test_project" in projects
def test_get_open_action_items(self, temp_data_dir):
"""Test getting open action items."""
with tempfile.TemporaryDirectory() as persist_dir:
rag = ProjectRAG(temp_data_dir, persist_dir=Path(persist_dir))
rag.load_and_index()
items = rag.get_open_action_items()
# Should have 2 open items (Alice and Bob's tasks)
assert len(items) == 2
def test_get_open_action_items_filtered(self, temp_data_dir):
"""Test getting open action items filtered by project."""
with tempfile.TemporaryDirectory() as persist_dir:
rag = ProjectRAG(temp_data_dir, persist_dir=Path(persist_dir))
rag.load_and_index()
items = rag.get_open_action_items(project="test_project")
assert len(items) == 2
items = rag.get_open_action_items(project="nonexistent")
assert len(items) == 0
def test_get_blockers(self, temp_data_dir):
"""Test getting blockers."""
with tempfile.TemporaryDirectory() as persist_dir:
rag = ProjectRAG(temp_data_dir, persist_dir=Path(persist_dir))
rag.load_and_index()
blockers = rag.get_blockers()
assert len(blockers) == 2
def test_search(self, temp_data_dir):
"""Test semantic search."""
with tempfile.TemporaryDirectory() as persist_dir:
rag = ProjectRAG(temp_data_dir, persist_dir=Path(persist_dir))
rag.load_and_index()
results = rag.search("login page implementation")
assert len(results) > 0
def test_search_with_project_filter(self, temp_data_dir):
"""Test semantic search with project filter."""
with tempfile.TemporaryDirectory() as persist_dir:
rag = ProjectRAG(temp_data_dir, persist_dir=Path(persist_dir))
rag.load_and_index()
results = rag.search("login", project_filter="test_project")
assert len(results) > 0
results = rag.search("login", project_filter="nonexistent")
assert len(results) == 0
def test_get_recent_decisions(self, temp_data_dir):
"""Test getting recent decisions."""
with tempfile.TemporaryDirectory() as persist_dir:
rag = ProjectRAG(temp_data_dir, persist_dir=Path(persist_dir))
rag.load_and_index()
decisions = rag.get_recent_decisions()
assert len(decisions) == 2
|