From e1b0b55bc859cf2d35affbf1deef28bee27235e7 Mon Sep 17 00:00:00 2001 From: Brian Krabach Date: Wed, 1 Apr 2026 11:10:07 -0700 Subject: [PATCH] feat: add federation_enabled to instance-info endpoint --- muxplex/main.py | 7 ++++++- muxplex/tests/test_api.py | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/muxplex/main.py b/muxplex/main.py index 0d411df..c3072ff 100644 --- a/muxplex/main.py +++ b/muxplex/main.py @@ -558,7 +558,12 @@ async def instance_info() -> dict: discover peer names and verify reachability. """ settings = load_settings() - return {"name": settings["device_name"], "version": app.version} + fed_key = load_federation_key() + return { + "name": settings["device_name"], + "version": app.version, + "federation_enabled": bool(fed_key), + } # --------------------------------------------------------------------------- diff --git a/muxplex/tests/test_api.py b/muxplex/tests/test_api.py index 224ff68..2c42464 100644 --- a/muxplex/tests/test_api.py +++ b/muxplex/tests/test_api.py @@ -1029,6 +1029,28 @@ def test_instance_info_no_auth_required(tmp_path, monkeypatch): assert "version" in data +def test_instance_info_includes_federation_enabled(client, tmp_path, monkeypatch): + """GET /api/instance-info includes federation_enabled=False when no key file exists.""" + import muxplex.settings as settings_mod + + # Redirect settings path so defaults are used + monkeypatch.setattr(settings_mod, "SETTINGS_PATH", tmp_path / "settings.json") + # Redirect federation key path to a nonexistent file + monkeypatch.setattr( + settings_mod, "FEDERATION_KEY_PATH", tmp_path / "nonexistent_federation_key" + ) + + response = client.get("/api/instance-info") + assert response.status_code == 200 + data = response.json() + assert "federation_enabled" in data, ( + f"Response must include 'federation_enabled' key, got: {data}" + ) + assert data["federation_enabled"] is False, ( + f"federation_enabled must be False when no key file exists, got: {data['federation_enabled']}" + ) + + # --------------------------------------------------------------------------- # CORS middleware # ---------------------------------------------------------------------------