from types import SimpleNamespace import pytest from application import services from mcp_api.auth import MCPError from mcp_api.server import check_import_health @pytest.mark.parametrize("status,manager,ok", [ ("stop", None, False), ("active", None, False), ("active", SimpleNamespace(active=False), False), ("active", SimpleNamespace(active=True), True), ("stop", SimpleNamespace(active=False), True), ]) def test_import_never_reports_success_for_uninitialized_services(monkeypatch, status, manager, ok): monkeypatch.setattr(services.db, "query", lambda *args: [{"service_id": "s", "status": status}]) monkeypatch.setattr(services.firewall, "services", {"s": manager} if manager else {}) if ok: check_import_health() else: with pytest.raises(MCPError) as error: check_import_health() assert error.value.data["code"] == "APPLY_FAILED" assert error.value.data["service_id"] == "s"