"""Unit mirror for ``mgf.fed.cli._mgfcli`` (TS-01).

The vestigial ``mgf-common`` console-script entry point: rich ``--version``
short-circuit, side-effect-free identity, and registry dispatch.
"""

from __future__ import annotations

import pytest
from mgf.common.cli import EXIT_UNKNOWN

from mgf.fed.cli._mgfcli import main


def test_version_flag_short_circuits(capsys: pytest.CaptureFixture[str]) -> None:
    assert main(["--version"]) == 0
    assert main(["-V"]) == 0
    assert capsys.readouterr().out.strip()  # something version-ish was printed


def test_no_subcommand_returns_unknown(capsys: pytest.CaptureFixture[str]) -> None:
    rc = main([])
    assert rc == EXIT_UNKNOWN


def test_sets_identity_without_filesystem_side_effects() -> None:
    """``main`` sets identity via the side-effect-free seam, so after a
    ``--version`` call the active app name reflects the CLI host."""
    main(["--version"])
    from mgf.common import app_name

    assert app_name() == "mgf-common-cli"
