Implement complete MCP server for parsing Primavera P6 XER files and exposing schedule data through MCP tools. All 4 user stories complete. Tools implemented: - load_xer: Parse XER files into SQLite database - list_activities: Query activities with pagination and filtering - get_activity: Get activity details by ID - list_relationships: Query activity dependencies - get_predecessors/get_successors: Query activity relationships - get_project_summary: Project overview with counts - list_milestones: Query milestone activities - get_critical_path: Query driving path activities Features: - Tab-delimited XER format parsing with pluggable table handlers - In-memory SQLite database for fast queries - Pagination with 100-item default limit - Multi-project file support with project selection - ISO8601 date formatting - NO_FILE_LOADED error handling for all query tools Test coverage: 81 tests (contract, integration, unit)
77 lines
2.6 KiB
Python
77 lines
2.6 KiB
Python
"""Contract tests for get_successors MCP tool."""
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from xer_mcp.db import db
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def setup_db():
|
|
"""Initialize and clear database for each test."""
|
|
db.initialize()
|
|
yield
|
|
db.clear()
|
|
|
|
|
|
class TestGetSuccessorsContract:
|
|
"""Contract tests verifying get_successors tool interface."""
|
|
|
|
async def test_get_successors_returns_list(self, sample_xer_single_project: Path) -> None:
|
|
"""get_successors returns successor activities."""
|
|
from xer_mcp.tools.get_successors import get_successors
|
|
from xer_mcp.tools.load_xer import load_xer
|
|
|
|
await load_xer(file_path=str(sample_xer_single_project))
|
|
|
|
# A1010 (2002) has two successors: A1020 (2003) and A1030 (2004)
|
|
result = await get_successors(activity_id="2002")
|
|
|
|
assert "activity_id" in result
|
|
assert result["activity_id"] == "2002"
|
|
assert "successors" in result
|
|
assert len(result["successors"]) == 2
|
|
|
|
async def test_get_successors_includes_relationship_details(
|
|
self, sample_xer_single_project: Path
|
|
) -> None:
|
|
"""get_successors includes relationship type and lag."""
|
|
from xer_mcp.tools.get_successors import get_successors
|
|
from xer_mcp.tools.load_xer import load_xer
|
|
|
|
await load_xer(file_path=str(sample_xer_single_project))
|
|
|
|
result = await get_successors(activity_id="2001")
|
|
|
|
succ = result["successors"][0]
|
|
assert "relationship_type" in succ
|
|
assert "lag_hr_cnt" in succ
|
|
assert succ["relationship_type"] in ["FS", "SS", "FF", "SF"]
|
|
|
|
async def test_get_successors_empty_list_for_no_successors(
|
|
self, sample_xer_single_project: Path
|
|
) -> None:
|
|
"""get_successors returns empty list when no successors exist."""
|
|
from xer_mcp.tools.get_successors import get_successors
|
|
from xer_mcp.tools.load_xer import load_xer
|
|
|
|
await load_xer(file_path=str(sample_xer_single_project))
|
|
|
|
# A1040 (2005) has no successors
|
|
result = await get_successors(activity_id="2005")
|
|
|
|
assert "successors" in result
|
|
assert len(result["successors"]) == 0
|
|
|
|
async def test_get_successors_no_file_loaded_returns_error(self) -> None:
|
|
"""get_successors without loaded file returns NO_FILE_LOADED error."""
|
|
from xer_mcp.server import set_file_loaded
|
|
from xer_mcp.tools.get_successors import get_successors
|
|
|
|
set_file_loaded(False)
|
|
result = await get_successors(activity_id="2002")
|
|
|
|
assert "error" in result
|
|
assert result["error"]["code"] == "NO_FILE_LOADED"
|