"""modules/registry.py auto-discovery — no per-module registration required."""
from fastapi import APIRouter

from modules.registry import ROUTERS


def test_discovers_every_module_with_a_router():
    prefixes = sorted(r.prefix for r in ROUTERS)
    assert prefixes == ["/mail", "/network"]
    assert all(isinstance(r, APIRouter) for r in ROUTERS)


def test_folder_without_router_py_is_skipped(tmp_path, monkeypatch):
    # A module folder that hasn't grown a router.py yet (e.g. mid-scaffold)
    # must not blow up discovery.
    import modules.registry as registry
    (tmp_path / "not_a_module").mkdir()
    (tmp_path / "not_a_module" / "__init__.py").touch()
    monkeypatch.setattr(registry, "_MODULES_DIR", tmp_path)
    # No router.py in the folder, so discovery must skip it without raising
    # (it never even attempts the import).
    assert registry._discover() == []
