"""Requirement-to-test traceability checks for MVP in-scope requirements."""

from pathlib import Path

import pytest

MVP_REQUIREMENT_TEST_MAP: dict[str, list[str]] = {
    "REQ-0": [
        "tests/integration/test_pipeline_flow.py",
    ],
    "REQ-1": [
        "tests/integration/test_pipeline_flow.py",
        "tests/ui/test_upload_page.py",
    ],
    "REQ-2": [
        "tests/services/test_workflows_reliability.py",
        "tests/integration/test_pipeline_flow.py",
    ],
    "REQ-3": [
        "tests/services/test_job_service.py",
        "tests/ui/test_jobs_page.py",
    ],
    "REQ-4": [
        "tests/services/test_workflows_reliability.py",
        "tests/integration/test_pipeline_flow.py",
    ],
    "REQ-5": [
        "tests/ui/test_jobs_page.py",
        "tests/ui/test_pages_registration.py",
    ],
    "REQ-6": [
        "tests/test_app.py",
        "tests/services/test_workflows_reliability.py",
    ],
    "REQ-8": [
        "tests/test_app.py",
        "tests/test_config.py",
    ],
    "REQ-12": [
        "tests/test_prompts.py",
        "tests/services/test_transcription_external.py",
    ],
}


@pytest.mark.integration
class TestMvpRequirementTraceability:
    """Verify MVP in-scope requirements are mapped to executable tests."""

    def test_mvp_requirements_have_mapped_test_targets(self):
        """Each MVP in-scope REQ id maps to at least one existing test path."""
        project_root = Path(__file__).resolve().parents[1]

        assert MVP_REQUIREMENT_TEST_MAP
        for requirement_id, mapped_tests in MVP_REQUIREMENT_TEST_MAP.items():
            assert requirement_id.startswith("REQ-")
            assert mapped_tests, f"No mapped tests for {requirement_id}"

            for relative_path in mapped_tests:
                test_path = project_root / relative_path
                assert test_path.exists(), f"Missing mapped test file for {requirement_id}: {relative_path}"
