"""CF-02 — config source precedence pin for MgfSettings.

The standard mandates: CLI/kwargs → env → **.env file → on-disk config file**
→ defaults. A 2026-06-07 depth audit found MgfSettings ranked the on-disk
`[tool.mgf]` (PyprojectSource) ABOVE `.env` (dotenv) — inverting CF-02. This
pins the corrected order so it can't regress.
"""

from __future__ import annotations

from mgf.common.settings import MgfSettings


def test_cf02_dotenv_outranks_on_disk_pyproject_config() -> None:
    sentinel_dotenv = object()
    srcs = MgfSettings.settings_customise_sources(
        MgfSettings,
        init_settings=object(),
        env_settings=object(),
        dotenv_settings=sentinel_dotenv,
        file_secret_settings=object(),
    )
    dotenv_i = srcs.index(sentinel_dotenv)
    pyproject_i = next(i for i, s in enumerate(srcs) if type(s).__name__ == "PyprojectSource")
    assert dotenv_i < pyproject_i, (
        "CF-02: the `.env` source MUST outrank the on-disk `[tool.mgf]` "
        f"config source; got order {[type(s).__name__ for s in srcs]}"
    )
