"""Tests for the self-diagnostic (OP-02)."""

from __future__ import annotations

from pathlib import Path

import pytest

from mgf.fed._doctor import run_doctor


def _std(tmp_path: Path) -> None:
    std = tmp_path / "mgf-standard"
    (std / "templates").mkdir(parents=True)
    (std / "MGF_LIBRARIES.json").write_text("{}", encoding="utf-8")
    (std / "templates" / "policy.toml").write_text("schema = 1\n", encoding="utf-8")


def test_doctor_pass(tmp_path: Path, capsys: pytest.CaptureFixture[str]) -> None:
    _std(tmp_path)
    assert run_doctor(root=tmp_path) == 0
    assert "OK" in capsys.readouterr().out


def test_doctor_fail_missing_registry(tmp_path: Path, capsys: pytest.CaptureFixture[str]) -> None:
    assert run_doctor(root=tmp_path) == 1  # no mgf-standard registry
    assert "FAIL" in capsys.readouterr().out
