Skip to main content
Glama

Codebase MCP Server

by Ravenight13
test_ai_assistant_integration.py15.8 kB
""" Integration tests for AI assistant integration (Scenario 5). Tests verify (from quickstart.md): - AI assistant context queries (FR-024 to FR-028) - Combined search and task queries - Context linking between code and tasks - MCP tool integration for AI workflow TDD Compliance: These tests MUST FAIL initially since services are not implemented yet. """ from __future__ import annotations from pathlib import Path from typing import TYPE_CHECKING import pytest from sqlalchemy.ext.asyncio import AsyncSession if TYPE_CHECKING: from src.models.task import Task from src.services.searcher import SearchResult @pytest.fixture async def repository_with_tasks( tmp_path: Path, db_session: AsyncSession, ) -> tuple[Path, list[str]]: """ Create indexed repository with associated tasks. Returns: Tuple of (repository_path, task_ids) """ pytest.skip("Repository and task services not implemented yet (T031, T033)") # Future implementation: # from src.services.indexer import index_repository # from src.services.tasks import create_task, update_task # # # Create repository # repo_path = tmp_path / "ai-test-repo" # repo_path.mkdir() # # src_dir = repo_path / "src" # src_dir.mkdir() # # (src_dir / "calculator.py").write_text('''def add(a: int, b: int) -> int: # """Add two numbers.""" # return a + b # # def multiply(a: int, b: int) -> int: # """Multiply two numbers.""" # return a * b # ''') # # # Index repository # await index_repository(path=repo_path, name="AI Test Repo", force_reindex=False) # # # Create tasks # task1 = await create_task( # title="Implement division operation", # description="Add divide() function to calculator.py", # planning_references=["specs/001-calculator/spec.md"], # ) # await update_task( # task_id=task1.id, # status="in-progress", # branch="feature/division", # ) # # task2 = await create_task( # title="Add unit tests for calculator", # description="Write tests for add() and multiply() functions", # ) # # task3 = await create_task( # title="Optimize multiplication algorithm", # description="Improve performance of multiply() function", # ) # await update_task( # task_id=task3.id, # status="complete", # branch="feature/optimize-multiply", # commit="a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0", # ) # # return repo_path, [str(task1.id), str(task2.id), str(task3.id)] @pytest.fixture async def db_session() -> AsyncSession: """Create async database session for tests.""" pytest.skip("Database session fixture not implemented yet (requires T019-T027)") @pytest.mark.integration @pytest.mark.asyncio async def test_list_in_progress_tasks_for_ai_context_not_implemented( repository_with_tasks: tuple[Path, list[str]], db_session: AsyncSession, ) -> None: """ Test listing in-progress tasks for AI context - NOT YET IMPLEMENTED. Expected workflow: 1. AI assistant queries for in-progress tasks 2. Tasks returned with full context (title, description, notes, planning_references) 3. Branch and commit information included 4. AI can understand current development state This test MUST FAIL until T033 (task service) is implemented. """ pytest.skip("Task service not implemented yet (T033)") # Future implementation: # from src.services.tasks import list_tasks # # # AI queries for in-progress tasks # tasks = await list_tasks(status="in-progress", limit=10) # # # Verify tasks returned # assert len(tasks) >= 1 # # # Verify full context provided # task = tasks[0] # assert task.title == "Implement division operation" # assert task.description == "Add divide() function to calculator.py" # assert task.status == "in-progress" # assert len(task.planning_references) > 0 # assert len(task.branches) > 0 # assert "feature/division" in task.branches # # # Verify AI can understand what user is working on # assert task.planning_references[0] == "specs/001-calculator/spec.md" @pytest.mark.integration @pytest.mark.asyncio async def test_search_code_for_ai_context( repository_with_tasks: tuple[Path, list[str]], db_session: AsyncSession, ) -> None: """ Test semantic code search for AI assistant context. Expected behavior: - AI searches for "calculator implementation" - Relevant code chunks returned - AI can provide informed assistance based on code This test MUST FAIL until T032 (searcher service) is implemented. """ pytest.skip("Search service not implemented yet (T032)") # Future implementation: # from src.services.searcher import search_code # # # AI searches for calculator code # results = await search_code( # query="calculator implementation", # limit=5, # ) # # # Verify results returned # assert len(results) > 0 # # # Verify code context provided # top_result = results[0] # assert top_result.content is not None # assert top_result.file_path.endswith(".py") # assert top_result.similarity_score > 0.5 # # # Verify AI has enough context # assert "calculator" in top_result.content.lower() or "add" in top_result.content.lower() @pytest.mark.integration @pytest.mark.asyncio async def test_combined_task_and_code_context_for_ai( repository_with_tasks: tuple[Path, list[str]], db_session: AsyncSession, ) -> None: """ Test combined task and code context for AI assistant. Expected behavior: - List in-progress tasks - Search code related to task - AI receives comprehensive context - Can provide informed suggestions This test MUST FAIL until T032 (searcher) and T033 (task service) are implemented. """ pytest.skip("Task and search services not implemented yet (T032, T033)") # Future implementation: # from src.services.tasks import list_tasks # from src.services.searcher import search_code # # # Get in-progress tasks # tasks = await list_tasks(status="in-progress", limit=10) # assert len(tasks) >= 1 # # division_task = tasks[0] # assert "division" in division_task.title.lower() # # # Search for related code # code_results = await search_code( # query="calculator division", # limit=5, # ) # # # AI now has both task context and code context # assert division_task.description is not None # assert len(code_results) >= 0 # May be empty if division not implemented yet # # # AI can understand: # # 1. What user is working on (division task) # # 2. Current state of calculator code # # 3. Where to add division function @pytest.mark.integration @pytest.mark.asyncio async def test_get_specific_task_details_for_ai( repository_with_tasks: tuple[Path, list[str]], db_session: AsyncSession, ) -> None: """ Test retrieving specific task details for AI assistant. Expected behavior: - AI queries for specific task by ID - Full task details returned - History and git metadata included - AI can provide context-aware assistance This test MUST FAIL until T033 (task service) is implemented. """ pytest.skip("Task service not implemented yet (T033)") # Future implementation: # from src.services.tasks import get_task # # repo_path, task_ids = repository_with_tasks # task_id = task_ids[0] # First task (division task) # # # AI queries for specific task # task = await get_task(task_id) # # # Verify complete context provided # assert task.id == task_id # assert task.title == "Implement division operation" # assert task.description is not None # assert task.status == "in-progress" # assert len(task.planning_references) > 0 # assert len(task.branches) > 0 # # # AI can reference planning documents # assert any("spec.md" in ref for ref in task.planning_references) @pytest.mark.integration @pytest.mark.asyncio async def test_ai_workflow_create_task_then_search_code( repository_with_tasks: tuple[Path, list[str]], db_session: AsyncSession, ) -> None: """ Test AI workflow: Create task, then search for related code. Expected behavior: - AI creates new task for user - AI searches for related code - AI can suggest where to implement feature This test MUST FAIL until T032 (searcher) and T033 (task service) are implemented. """ pytest.skip("Task and search services not implemented yet (T032, T033)") # Future implementation: # from src.services.tasks import create_task # from src.services.searcher import search_code # # # AI creates task based on user request # new_task = await create_task( # title="Add square root function", # description="Add sqrt() function to calculator.py", # notes="Use math.sqrt for implementation", # ) # # # AI searches for related code # results = await search_code( # query="calculator math functions", # limit=5, # ) # # # AI can suggest implementation location # assert new_task.id is not None # assert len(results) > 0 # # # AI knows: # # 1. Task exists for square root # # 2. Calculator.py has add/multiply functions # # 3. Can suggest adding sqrt() near existing functions @pytest.mark.integration @pytest.mark.asyncio async def test_ai_workflow_search_then_update_task( repository_with_tasks: tuple[Path, list[str]], db_session: AsyncSession, ) -> None: """ Test AI workflow: Search code, then update task status. Expected behavior: - AI searches code to verify implementation - AI updates task status to complete - Task metadata updated with commit info This test MUST FAIL until T032 (searcher) and T033 (task service) are implemented. """ pytest.skip("Task and search services not implemented yet (T032, T033)") # Future implementation: # from src.services.tasks import list_tasks, update_task # from src.services.searcher import search_code # # # AI checks for implementation # results = await search_code( # query="multiply function implementation", # limit=5, # ) # # # Verify multiply exists # assert len(results) > 0 # assert any("multiply" in r.content for r in results) # # # AI finds task related to multiplication # tasks = await list_tasks(limit=100) # multiply_task = next( # (t for t in tasks if "multiply" in t.title.lower()), # None, # ) # # if multiply_task and multiply_task.status != "complete": # # AI marks task complete # updated_task = await update_task( # task_id=multiply_task.id, # status="complete", # commit="test-commit-hash", # ) # assert updated_task.status == "complete" @pytest.mark.integration @pytest.mark.asyncio async def test_ai_context_includes_planning_references( repository_with_tasks: tuple[Path, list[str]], db_session: AsyncSession, ) -> None: """ Test that AI context includes planning document references. Expected behavior: - Query task details - Planning references included (spec.md, plan.md) - AI can reference design decisions from planning docs This test MUST FAIL until T033 (task service) is implemented. """ pytest.skip("Task service not implemented yet (T033)") # Future implementation: # from src.services.tasks import get_task # # repo_path, task_ids = repository_with_tasks # task_id = task_ids[0] # # # AI retrieves task # task = await get_task(task_id) # # # Verify planning references included # assert len(task.planning_references) > 0 # assert any("spec.md" in ref for ref in task.planning_references) # # # AI can: # # 1. Read spec.md to understand requirements # # 2. Read plan.md to understand design # # 3. Provide implementation guidance based on planning docs @pytest.mark.integration @pytest.mark.asyncio async def test_ai_context_includes_git_metadata( repository_with_tasks: tuple[Path, list[str]], db_session: AsyncSession, ) -> None: """ Test that AI context includes git metadata (branches, commits). Expected behavior: - Query task details - Branch names included - Commit hashes included for completed tasks - AI can reference git history This test MUST FAIL until T033 (task service) is implemented. """ pytest.skip("Task service not implemented yet (T033)") # Future implementation: # from src.services.tasks import get_task # # repo_path, task_ids = repository_with_tasks # completed_task_id = task_ids[2] # Third task (completed) # # # AI retrieves completed task # task = await get_task(completed_task_id) # # # Verify git metadata included # assert task.status == "complete" # assert len(task.branches) > 0 # assert len(task.commits) > 0 # # # AI can: # # 1. Know which branch has the implementation # # 2. Reference specific commits # # 3. Suggest git commands (e.g., git checkout <branch>) @pytest.mark.integration @pytest.mark.asyncio async def test_ai_can_filter_tasks_by_multiple_criteria( repository_with_tasks: tuple[Path, list[str]], db_session: AsyncSession, ) -> None: """ Test AI can filter tasks by multiple criteria. Expected behavior: - Filter by status AND branch - Only tasks matching both criteria returned - AI can narrow context to relevant work This test MUST FAIL until T033 (task service) is implemented. """ pytest.skip("Task service with filtering not implemented yet (T033)") # Future implementation: # from src.services.tasks import list_tasks # # # AI filters for in-progress tasks on specific branch # tasks = await list_tasks( # status="in-progress", # branch="feature/division", # limit=10, # ) # # # Verify filtered results # assert len(tasks) >= 1 # for task in tasks: # assert task.status == "in-progress" # assert "feature/division" in task.branches @pytest.mark.integration @pytest.mark.asyncio async def test_search_results_do_not_include_task_references_yet( repository_with_tasks: tuple[Path, list[str]], db_session: AsyncSession, ) -> None: """ Test that search results structure is prepared for task linking. Note: This test validates the basic search structure. Task-code linking is a future enhancement not in current spec. Expected behavior: - Search returns code chunks - Results have standard metadata - Structure allows future task reference enhancement This test MUST FAIL until T032 (searcher) is implemented. """ pytest.skip("Search service not implemented yet (T032)") # Future implementation: # from src.services.searcher import search_code # # results = await search_code( # query="calculator", # limit=5, # ) # # # Verify basic search structure # assert len(results) > 0 # for result in results: # assert result.content is not None # assert result.file_path is not None # assert result.similarity_score is not None # assert 0.0 <= result.similarity_score <= 1.0 # # # Structure is ready for future task reference enhancement # # (Not implemented in current spec, but structure supports it)

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Ravenight13/codebase-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server