Spaces:
Sleeping
Sleeping
File size: 4,816 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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
"""Integration tests for LLM providers."""
import pytest
import os
from pathlib import Path
import tempfile
from src.rag import ProjectRAG
from src.agent import ProjectAgent
# Sample meeting for testing
SAMPLE_MEETING = """# Meeting: Test Sprint Planning
Date: 2025-01-15
Participants: Alice, Bob
## Discussion
Discussed the test implementation.
## Decisions
- Use pytest for testing
## Action Items
- [ ] Alice: Write unit tests by 2025-01-20
- [ ] Bob: Review code by 2025-01-18
## Blockers
- Waiting for API access
"""
@pytest.fixture
def test_rag():
"""Create a RAG system with test data."""
with tempfile.TemporaryDirectory() as temp_dir:
# Create data structure
data_dir = Path(temp_dir) / "data"
project_dir = data_dir / "test_project" / "meetings"
project_dir.mkdir(parents=True)
# Write sample meeting
(project_dir / "2025-01-15-sprint.md").write_text(SAMPLE_MEETING)
# Create persistent dir for ChromaDB
persist_dir = Path(temp_dir) / "chroma"
# Initialize RAG
rag = ProjectRAG(data_dir, persist_dir=persist_dir)
rag.load_and_index()
yield rag
class TestHuggingFaceProvider:
"""Integration tests for HuggingFace provider."""
def test_hf_agent_creation(self, test_rag):
"""Test that HuggingFace agent can be created with valid token."""
hf_token = os.getenv("HF_TOKEN")
if not hf_token:
pytest.skip("HF_TOKEN not set")
agent = ProjectAgent(test_rag, provider="huggingface")
assert agent is not None
assert agent.provider == "huggingface"
assert agent.llm is not None
def test_hf_simple_query(self, test_rag):
"""Test a simple query with HuggingFace."""
hf_token = os.getenv("HF_TOKEN")
if not hf_token:
pytest.skip("HF_TOKEN not set")
agent = ProjectAgent(test_rag, provider="huggingface")
response = agent.query("What are the action items?")
assert response is not None
assert len(response) > 0
# Should mention Alice or Bob from the test data
assert "alice" in response.lower() or "bob" in response.lower() or "test" in response.lower()
def test_hf_blockers_query(self, test_rag):
"""Test blockers query with HuggingFace."""
hf_token = os.getenv("HF_TOKEN")
if not hf_token:
pytest.skip("HF_TOKEN not set")
agent = ProjectAgent(test_rag, provider="huggingface")
response = agent.query("What blockers do we have?")
assert response is not None
assert len(response) > 0
def test_hf_invalid_token(self, test_rag):
"""Test that invalid token raises appropriate error."""
os.environ["HF_TOKEN"] = "invalid_token_12345"
agent = ProjectAgent(test_rag, provider="huggingface")
with pytest.raises(Exception) as exc_info:
agent.query("What are the action items?")
# Should get an authentication error
error_msg = str(exc_info.value).lower()
assert "401" in error_msg or "unauthorized" in error_msg or "invalid" in error_msg or "error" in error_msg
class TestGoogleProvider:
"""Integration tests for Google provider."""
def test_google_agent_creation(self, test_rag):
"""Test that Google agent can be created with valid key."""
api_key = os.getenv("GOOGLE_API_KEY")
if not api_key:
pytest.skip("GOOGLE_API_KEY not set")
agent = ProjectAgent(test_rag, provider="google")
assert agent is not None
assert agent.provider == "google"
assert agent.llm is not None
def test_google_simple_query(self, test_rag):
"""Test a simple query with Google."""
api_key = os.getenv("GOOGLE_API_KEY")
if not api_key:
pytest.skip("GOOGLE_API_KEY not set")
agent = ProjectAgent(test_rag, provider="google")
response = agent.query("What are the action items?")
assert response is not None
assert len(response) > 0
def test_google_blockers_query(self, test_rag):
"""Test blockers query with Google."""
api_key = os.getenv("GOOGLE_API_KEY")
if not api_key:
pytest.skip("GOOGLE_API_KEY not set")
agent = ProjectAgent(test_rag, provider="google")
response = agent.query("What blockers do we have?")
assert response is not None
assert len(response) > 0
def test_google_invalid_key(self, test_rag):
"""Test that invalid key raises appropriate error."""
os.environ["GOOGLE_API_KEY"] = "invalid_key_12345"
agent = ProjectAgent(test_rag, provider="google")
with pytest.raises(Exception):
agent.query("What are the action items?")
|