from pathlib import Path

import pytest

FIXTURES = Path(__file__).parent / "fixtures"


@pytest.fixture
def fixtures_dir() -> Path:
    return FIXTURES


@pytest.fixture(autouse=True)
def _bypass_ssrf_guard_in_tests(monkeypatch):
    """Tests use synthetic hosts like `https://x/...` that don't resolve in
    DNS. The production SSRF guard (is_safe_to_fetch) refuses anything it
    can't resolve to a public IP — by design. To keep the rest of the
    pipeline tests independent of network state we downgrade the SSRF
    check to the path-only check (is_public_path) inside the test process.

    is_safe_to_fetch itself has dedicated unit tests in
    `test_compliance_ssrf.py` that DO exercise the DNS / IP / allowlist
    paths against controlled fakes — those are not affected by this
    fixture because they import the real function directly.
    """
    from govcrawler import pipeline as pl
    from govcrawler.compliance import is_public_path

    monkeypatch.setattr(pl, "is_safe_to_fetch", is_public_path, raising=False)
