"""Smoke: the SDK imports cleanly and its `__all__` is consistent.

The fastest possible "is the build broken?" signal. Runs in <100ms;
in CI this is the FIRST test so a broken import fails the run in
seconds rather than minutes.

Marker: `smoke` (see `docs/testing/TAXONOMY.md` §6). Default suite
includes it; CI runs `pytest -m smoke` first as the build-ok gate.
"""

from __future__ import annotations

import pytest

pytestmark = pytest.mark.smoke


def test_top_level_imports_all_public_names() -> None:
    """Every name in `mgf.hrb.__all__` is actually importable.
    Catches a stale `__all__` entry pointing at a removed/renamed
    public name — would be a wire-contract regression at the next
    release."""
    import mgf.hrb as pkg

    missing: list[str] = []
    for name in pkg.__all__:
        if not hasattr(pkg, name):
            missing.append(name)
    assert not missing, f"__all__ names not actually exported: {missing}"


def test_no_private_names_leaked_into_all() -> None:
    """`__all__` should not include any single-underscore-prefixed
    name (dunders like `__version__` are public-by-convention and
    excluded). A leaked private name is a footgun for consumers
    (they import it, AP-14 violation cascades). Pin to catch the
    next leak at review time."""
    import mgf.hrb as pkg

    leaked = [
        n
        for n in pkg.__all__
        if n.startswith("_") and not (n.startswith("__") and n.endswith("__"))
    ]
    assert not leaked, f"private names in __all__: {leaked}"


def test_every_exception_class_descends_from_root() -> None:
    """EH-01 (federation): every wire-error-mapped exception
    descends from `MgfHrbError`. A consumer doing `except
    MgfHrbError:` catches ALL broker failures, never just some."""
    from mgf.hrb import MgfHrbError
    from mgf.hrb import exceptions as exc_mod

    non_compliant: list[str] = []
    for name in dir(exc_mod):
        obj = getattr(exc_mod, name)
        if (
            isinstance(obj, type)
            and issubclass(obj, Exception)
            and obj is not Exception
            and not name.startswith("_")
            and name != "MgfHrbError"
            and "Error" in name
        ):
            if not issubclass(obj, MgfHrbError):
                non_compliant.append(name)
    assert not non_compliant, f"exception classes not descending from MgfHrbError: {non_compliant}"
