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)
79 lines
2.6 KiB
Python
79 lines
2.6 KiB
Python
"""Contract tests for list_relationships 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 TestListRelationshipsContract:
|
|
"""Contract tests verifying list_relationships tool interface."""
|
|
|
|
async def test_list_relationships_returns_paginated_results(
|
|
self, sample_xer_single_project: Path
|
|
) -> None:
|
|
"""list_relationships returns relationships with pagination metadata."""
|
|
from xer_mcp.tools.list_relationships import list_relationships
|
|
from xer_mcp.tools.load_xer import load_xer
|
|
|
|
await load_xer(file_path=str(sample_xer_single_project))
|
|
|
|
result = await list_relationships()
|
|
|
|
assert "relationships" in result
|
|
assert "pagination" in result
|
|
assert len(result["relationships"]) == 5
|
|
assert result["pagination"]["total_count"] == 5
|
|
|
|
async def test_list_relationships_with_pagination(
|
|
self, sample_xer_single_project: Path
|
|
) -> None:
|
|
"""list_relationships respects limit and offset parameters."""
|
|
from xer_mcp.tools.list_relationships import list_relationships
|
|
from xer_mcp.tools.load_xer import load_xer
|
|
|
|
await load_xer(file_path=str(sample_xer_single_project))
|
|
|
|
result = await list_relationships(limit=2, offset=0)
|
|
|
|
assert len(result["relationships"]) == 2
|
|
assert result["pagination"]["has_more"] is True
|
|
|
|
async def test_list_relationships_includes_expected_fields(
|
|
self, sample_xer_single_project: Path
|
|
) -> None:
|
|
"""list_relationships returns relationships with all expected fields."""
|
|
from xer_mcp.tools.list_relationships import list_relationships
|
|
from xer_mcp.tools.load_xer import load_xer
|
|
|
|
await load_xer(file_path=str(sample_xer_single_project))
|
|
|
|
result = await list_relationships()
|
|
|
|
rel = result["relationships"][0]
|
|
assert "task_pred_id" in rel
|
|
assert "task_id" in rel
|
|
assert "pred_task_id" in rel
|
|
assert "pred_type" in rel
|
|
assert "lag_hr_cnt" in rel
|
|
|
|
async def test_list_relationships_no_file_loaded_returns_error(self) -> None:
|
|
"""list_relationships without loaded file returns NO_FILE_LOADED error."""
|
|
from xer_mcp.server import set_file_loaded
|
|
from xer_mcp.tools.list_relationships import list_relationships
|
|
|
|
set_file_loaded(False)
|
|
result = await list_relationships()
|
|
|
|
assert "error" in result
|
|
assert result["error"]["code"] == "NO_FILE_LOADED"
|