- Create InterviewerAgent with Socratic questioning and RAG context - Build SynthesizerAgent for transcript segmentation and link generation - Integrate Google Gemini models (Flash for interviewing, Pro for synthesis) - Add structured output parsing for Zettel extraction and linking - Implement session termination detection with [END_SESSION] token - Add conversation context formatting and similarity-based neighbor filtering - Add vector service tests with mocked ChromaDB and embeddings - Test interviewer agent RAG conversations and session termination - Test synthesizer agent transcript formatting and neighbor analysis - Add prompt loader tests for external prompt system - Test all repository CRUD operations and database transactions
99 lines
3.6 KiB
Python
99 lines
3.6 KiB
Python
"""Test prompt loading functionality."""
|
|
import pytest
|
|
from pathlib import Path
|
|
|
|
from app.core.prompt_loader import PromptLoader, prompt_loader
|
|
|
|
|
|
class TestPromptLoader:
|
|
"""Test PromptLoader functionality."""
|
|
|
|
def test_prompt_loader_initialization(self):
|
|
"""Test that PromptLoader initializes correctly."""
|
|
loader = PromptLoader()
|
|
assert loader.prompts_dir.exists()
|
|
assert loader.prompts_dir.name == "prompts"
|
|
|
|
def test_load_existing_prompt(self):
|
|
"""Test loading an existing prompt file."""
|
|
loader = PromptLoader()
|
|
interviewer_prompt = loader.load_prompt("interviewer")
|
|
|
|
assert isinstance(interviewer_prompt, str)
|
|
assert len(interviewer_prompt) > 0
|
|
assert "Socratic interviewer" in interviewer_prompt
|
|
assert "{retrieved_context}" in interviewer_prompt
|
|
assert "[END_SESSION]" in interviewer_prompt
|
|
|
|
def test_load_nonexistent_prompt(self):
|
|
"""Test loading a non-existent prompt file."""
|
|
loader = PromptLoader()
|
|
|
|
with pytest.raises(FileNotFoundError):
|
|
loader.load_prompt("nonexistent_prompt")
|
|
|
|
def test_get_interviewer_prompt(self):
|
|
"""Test the interviewer prompt getter."""
|
|
loader = PromptLoader()
|
|
prompt = loader.get_interviewer_prompt()
|
|
|
|
assert isinstance(prompt, str)
|
|
assert "interviewer" in prompt.lower()
|
|
assert "question" in prompt.lower()
|
|
|
|
def test_get_segmentation_prompt(self):
|
|
"""Test the segmentation prompt getter."""
|
|
loader = PromptLoader()
|
|
prompt = loader.get_segmentation_prompt()
|
|
|
|
assert isinstance(prompt, str)
|
|
assert "transcript" in prompt.lower()
|
|
assert "zettel" in prompt.lower()
|
|
assert "{transcript}" in prompt
|
|
|
|
def test_get_linking_prompt(self):
|
|
"""Test the linking prompt getter."""
|
|
loader = PromptLoader()
|
|
prompt = loader.get_linking_prompt()
|
|
|
|
assert isinstance(prompt, str)
|
|
assert "relationship" in prompt.lower()
|
|
assert "semantic" in prompt.lower()
|
|
assert "{new_note_title}" in prompt
|
|
assert "{neighbors}" in prompt
|
|
|
|
def test_caching_functionality(self):
|
|
"""Test that prompts are cached."""
|
|
loader = PromptLoader()
|
|
|
|
# Load the same prompt twice
|
|
prompt1 = loader.load_prompt("interviewer")
|
|
prompt2 = loader.load_prompt("interviewer")
|
|
|
|
# They should be the same object (cached)
|
|
assert prompt1 is prompt2
|
|
|
|
def test_global_prompt_loader_instance(self):
|
|
"""Test that the global prompt_loader instance works."""
|
|
interviewer_prompt = prompt_loader.get_interviewer_prompt()
|
|
segmentation_prompt = prompt_loader.get_segmentation_prompt()
|
|
linking_prompt = prompt_loader.get_linking_prompt()
|
|
|
|
assert all(isinstance(p, str) and len(p) > 0 for p in [
|
|
interviewer_prompt, segmentation_prompt, linking_prompt
|
|
])
|
|
|
|
def test_all_required_prompts_exist(self):
|
|
"""Test that all required prompt files exist."""
|
|
loader = PromptLoader()
|
|
prompts_dir = loader.prompts_dir
|
|
|
|
required_prompts = ["interviewer.txt", "segmentation.txt", "linking.txt"]
|
|
|
|
for prompt_file in required_prompts:
|
|
prompt_path = prompts_dir / prompt_file
|
|
assert prompt_path.exists(), f"Required prompt file missing: {prompt_file}"
|
|
|
|
# Test that the file has content
|
|
content = prompt_path.read_text()
|
|
assert len(content.strip()) > 0, f"Prompt file is empty: {prompt_file}" |