"""Pins the typed-config surface (CF-01/-02/-08/-10).

These tests are pure: they construct ``HrbSettings`` with explicit
values and inspect its env-var precedence. No real broker, no
filesystem state, fully deterministic.
"""

from __future__ import annotations

from typing import TYPE_CHECKING

from mgf.hrb import HrbSettings

if TYPE_CHECKING:
    import pytest


def test_defaults_match_skeleton_broker() -> None:
    """The default socket_path matches what hrb-code/src/server.zig listens on,
    so out-of-the-box `mgf-hrb scan` works against the skeleton without an
    explicit --socket arg or env-var. Drift detection — if the broker
    changes its default, this test fails and we update both together."""
    s = HrbSettings()
    assert s.socket_path == "/tmp/mgf-hrb.sock"
    assert s.default_deadline_ms == 5_000


def test_constructor_injection_overrides_defaults() -> None:
    """CF-08 — every field is constructor-injectable so tests don't depend
    on env-var leakage from the host."""
    s = HrbSettings(socket_path="/run/custom.sock", default_deadline_ms=10_000)
    assert s.socket_path == "/run/custom.sock"
    assert s.default_deadline_ms == 10_000


def test_env_var_overrides_default(monkeypatch: pytest.MonkeyPatch) -> None:
    """CF-02 precedence: env > defaults."""
    monkeypatch.setenv("MGF_HRB_SOCKET_PATH", "/run/from-env.sock")
    monkeypatch.setenv("MGF_HRB_DEFAULT_DEADLINE_MS", "12345")
    s = HrbSettings()
    assert s.socket_path == "/run/from-env.sock"
    assert s.default_deadline_ms == 12_345


def test_constructor_injection_overrides_env(monkeypatch: pytest.MonkeyPatch) -> None:
    """CF-02 precedence: explicit constructor args beat env."""
    monkeypatch.setenv("MGF_HRB_SOCKET_PATH", "/run/from-env.sock")
    s = HrbSettings(socket_path="/run/explicit.sock")
    assert s.socket_path == "/run/explicit.sock"
