"""Session-level pytest configuration for the dual-agent test suite.

Browser test enforcement
------------------------
Browser tests are marked with ``@pytest.mark.browser``.  They skip automatically
when Playwright is not installed unless the env var
``DUAL_AGENT_REQUIRE_BROWSER_TESTS=1`` is set, in which case a missing Playwright
installation is a hard failure rather than a skip.

To run the full browser suite with enforcement::

    pip install playwright pytest-playwright
    playwright install chromium webkit
    DUAL_AGENT_REQUIRE_BROWSER_TESTS=1 pytest -m browser

To run only pure-Python tests (no browser)::

    pytest -m "not browser"
"""
import os

import pytest


def pytest_configure(config):
    config.addinivalue_line(
        "markers",
        "browser: tests that require Playwright and browser binaries",
    )


def pytest_collection_modifyitems(config, items):
    """If DUAL_AGENT_REQUIRE_BROWSER_TESTS is set, fail fast when Playwright is absent."""
    if not os.environ.get("DUAL_AGENT_REQUIRE_BROWSER_TESTS"):
        return
    try:
        import playwright  # noqa: F401
    except ImportError:
        for item in items:
            if item.get_closest_marker("browser"):
                item.add_marker(
                    pytest.mark.xfail(
                        reason=(
                            "DUAL_AGENT_REQUIRE_BROWSER_TESTS=1 is set but playwright "
                            "is not installed. Run: pip install playwright pytest-playwright "
                            "&& playwright install chromium webkit"
                        ),
                        strict=True,
                    )
                )
