From 5f0fcf3e7141af00d48a7f5b7180a6145996502e Mon Sep 17 00:00:00 2001 From: Brian Krabach Date: Wed, 1 Apr 2026 11:23:04 -0700 Subject: [PATCH] test: add True-path coverage and clean up TestClient binding for instance-info MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add test_instance_info_federation_enabled_true_when_key_exists: writes a key file to tmp_path, patches FEDERATION_KEY_PATH, and asserts that federation_enabled is True — completing the positive/negative pair for task-9's coverage gap (suggested by code quality review). - Replace 'with TestClient(app) as _:' with 'with TestClient(app):' — the discard binding was unnecessary (ruff-clean but stylistically noisy). --- muxplex/tests/test_api.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/muxplex/tests/test_api.py b/muxplex/tests/test_api.py index b7e7185..003d676 100644 --- a/muxplex/tests/test_api.py +++ b/muxplex/tests/test_api.py @@ -606,8 +606,8 @@ def test_lifespan_alert_bell_hook_discards_response(monkeypatch): mock_run_tmux = AsyncMock(return_value="") monkeypatch.setattr("muxplex.main.run_tmux", mock_run_tmux) - # Trigger lifespan by creating a TestClient - with TestClient(app) as _: + # Trigger lifespan by entering/exiting TestClient context + with TestClient(app): pass # Verify run_tmux was called during lifespan startup @@ -1051,6 +1051,32 @@ def test_instance_info_includes_federation_enabled(client, tmp_path, monkeypatch ) +def test_instance_info_federation_enabled_true_when_key_exists( + client, tmp_path, monkeypatch +): + """GET /api/instance-info returns federation_enabled=True when a key file is present.""" + import muxplex.settings as settings_mod + + # Write a federation key file to tmp_path + key_file = tmp_path / "federation_key" + key_file.write_text("test-federation-secret") + + # Redirect settings path so defaults are used + monkeypatch.setattr(settings_mod, "SETTINGS_PATH", tmp_path / "settings.json") + # Redirect federation key path to the file we just wrote + monkeypatch.setattr(settings_mod, "FEDERATION_KEY_PATH", key_file) + + 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 True, ( + f"federation_enabled must be True when a key file exists, got: {data['federation_enabled']}" + ) + + # --------------------------------------------------------------------------- # CORS middleware # ---------------------------------------------------------------------------