Add AI-powered issue metadata parser using Anthropic Sonnet model. - Parse issue markdown to extract: estimated_context, difficulty, assigned_agent, blocks, blocked_by - Implement in-memory caching to avoid duplicate API calls - Graceful fallback to defaults on parse failures - Add comprehensive test suite (9 test cases) - 95% test coverage (exceeds 85% requirement) - Add ANTHROPIC_API_KEY to config - Update documentation and add .env.example Fixes #158 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
122 lines
3.2 KiB
Python
122 lines
3.2 KiB
Python
"""Pytest fixtures for coordinator tests."""
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
|
@pytest.fixture
|
|
def webhook_secret() -> str:
|
|
"""Return a test webhook secret."""
|
|
return "test-webhook-secret-12345"
|
|
|
|
|
|
@pytest.fixture
|
|
def gitea_url() -> str:
|
|
"""Return a test Gitea URL."""
|
|
return "https://git.mosaicstack.dev"
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_assigned_payload() -> dict[str, object]:
|
|
"""Return a sample Gitea 'assigned' issue webhook payload."""
|
|
return {
|
|
"action": "assigned",
|
|
"number": 157,
|
|
"issue": {
|
|
"id": 157,
|
|
"number": 157,
|
|
"title": "[COORD-001] Set up webhook receiver endpoint",
|
|
"state": "open",
|
|
"assignee": {
|
|
"id": 1,
|
|
"login": "mosaic",
|
|
"full_name": "Mosaic Bot",
|
|
},
|
|
},
|
|
"repository": {
|
|
"name": "stack",
|
|
"full_name": "mosaic/stack",
|
|
"owner": {"login": "mosaic"},
|
|
},
|
|
"sender": {
|
|
"id": 2,
|
|
"login": "admin",
|
|
"full_name": "Admin User",
|
|
},
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_unassigned_payload() -> dict[str, object]:
|
|
"""Return a sample Gitea 'unassigned' issue webhook payload."""
|
|
return {
|
|
"action": "unassigned",
|
|
"number": 157,
|
|
"issue": {
|
|
"id": 157,
|
|
"number": 157,
|
|
"title": "[COORD-001] Set up webhook receiver endpoint",
|
|
"state": "open",
|
|
"assignee": None,
|
|
},
|
|
"repository": {
|
|
"name": "stack",
|
|
"full_name": "mosaic/stack",
|
|
"owner": {"login": "mosaic"},
|
|
},
|
|
"sender": {
|
|
"id": 2,
|
|
"login": "admin",
|
|
"full_name": "Admin User",
|
|
},
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_closed_payload() -> dict[str, object]:
|
|
"""Return a sample Gitea 'closed' issue webhook payload."""
|
|
return {
|
|
"action": "closed",
|
|
"number": 157,
|
|
"issue": {
|
|
"id": 157,
|
|
"number": 157,
|
|
"title": "[COORD-001] Set up webhook receiver endpoint",
|
|
"state": "closed",
|
|
"assignee": {
|
|
"id": 1,
|
|
"login": "mosaic",
|
|
"full_name": "Mosaic Bot",
|
|
},
|
|
},
|
|
"repository": {
|
|
"name": "stack",
|
|
"full_name": "mosaic/stack",
|
|
"owner": {"login": "mosaic"},
|
|
},
|
|
"sender": {
|
|
"id": 2,
|
|
"login": "admin",
|
|
"full_name": "Admin User",
|
|
},
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def client(webhook_secret: str, gitea_url: str, monkeypatch: pytest.MonkeyPatch) -> TestClient:
|
|
"""Create a FastAPI test client with test configuration."""
|
|
# Set test environment variables
|
|
monkeypatch.setenv("GITEA_WEBHOOK_SECRET", webhook_secret)
|
|
monkeypatch.setenv("GITEA_URL", gitea_url)
|
|
monkeypatch.setenv("ANTHROPIC_API_KEY", "test-anthropic-api-key")
|
|
monkeypatch.setenv("LOG_LEVEL", "debug")
|
|
|
|
# Force reload of settings
|
|
from src import config
|
|
import importlib
|
|
importlib.reload(config)
|
|
|
|
# Import app after settings are configured
|
|
from src.main import app
|
|
return TestClient(app)
|