fix: address pre-merge review findings — stale identity strings, pyright error, fragile test path, formatting, README accuracy

Required fixes:
- main.py: update module docstring, startup comment, and FastAPI title from
  'tmux-web coordinator' / 'coordinator service' → 'muxplex' (4 locations)
- test_api.py: replace hasattr/BaseRoute pattern with isinstance(r, (APIRoute,
  APIWebSocketRoute)) to satisfy pyright (union-attr error eliminated)

Recommendations applied:
- test_api.py + test_cli.py: auto-formatted with ruff (blank-line normalisation)
- test_cli.py: replace exec(Path('muxplex/__main__.py').read_text()) with
  importlib.util.find_spec() to obtain the absolute path — no longer assumes
  pytest is invoked from a specific working directory
- README.md: fix architecture table — WebSocket proxy moved from ttyd.py
  description to main.py; ttyd.py now correctly described as lifecycle only

All 178 tests pass; python_check clean (0 errors, 0 warnings).
This commit is contained in:
Brian Krabach
2026-03-28 02:47:18 -07:00
parent 110a503df0
commit 82ec323aaa
4 changed files with 22 additions and 23 deletions
+2 -2
View File
@@ -171,10 +171,10 @@ muxplex/
├── __init__.py ├── __init__.py
├── __main__.py # `python -m muxplex` entry point ├── __main__.py # `python -m muxplex` entry point
├── cli.py # CLI argument parsing and `install-service` subcommand ├── cli.py # CLI argument parsing and `install-service` subcommand
├── main.py # FastAPI app factory and route registration ├── main.py # FastAPI app: session API, bell hooks, WebSocket proxy to ttyd, static frontend
├── sessions.py # tmux session discovery and snapshot capture ├── sessions.py # tmux session discovery and snapshot capture
├── bells.py # Bell/activity notification tracking ├── bells.py # Bell/activity notification tracking
├── ttyd.py # ttyd process lifecycle management and WebSocket proxy ├── ttyd.py # ttyd process lifecycle management (spawn, kill, PID tracking)
├── state.py # Shared in-process state (sessions, bells, ttyd) ├── state.py # Shared in-process state (sessions, bells, ttyd)
├── frontend/ # Static frontend assets (served as package data) ├── frontend/ # Static frontend assets (served as package data)
│ ├── index.html │ ├── index.html
+4 -4
View File
@@ -1,7 +1,7 @@
""" """
FastAPI coordinator application for tmux-web. muxplex — FastAPI application for the tmux session dashboard.
Entry point for the coordinator service. Exposes: Entry point for the muxplex server. Exposes:
GET /health → {"status": "ok"} GET /health → {"status": "ok"}
Background poll loop reconciles tmux session state every POLL_INTERVAL seconds. Background poll loop reconciles tmux session state every POLL_INTERVAL seconds.
@@ -138,7 +138,7 @@ async def _poll_loop() -> None:
async def lifespan(app: FastAPI): async def lifespan(app: FastAPI):
global _poll_task global _poll_task
# Startup: kill any orphaned ttyd from a previous coordinator run, then # Startup: kill any orphaned ttyd from a previous muxplex run, then
# start the background poll loop. # start the background poll loop.
await kill_orphan_ttyd() await kill_orphan_ttyd()
_poll_task = asyncio.create_task(_poll_loop()) _poll_task = asyncio.create_task(_poll_loop())
@@ -170,7 +170,7 @@ async def lifespan(app: FastAPI):
# App # App
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
app = FastAPI(title="tmux-web coordinator", version="0.1.0", lifespan=lifespan) app = FastAPI(title="muxplex", version="0.1.0", lifespan=lifespan)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
+9 -9
View File
@@ -1,5 +1,5 @@
""" """
Tests for coordinator/main.py — FastAPI skeleton, lifespan, /health endpoint. Tests for muxplex/main.py — FastAPI skeleton, lifespan, /health endpoint.
""" """
import pytest import pytest
@@ -149,9 +149,7 @@ def test_patch_state_ignores_unknown_fields(client):
def test_get_sessions_returns_list(client, monkeypatch): def test_get_sessions_returns_list(client, monkeypatch):
"""GET /api/sessions must return a JSON list.""" """GET /api/sessions must return a JSON list."""
monkeypatch.setattr("muxplex.main.get_session_list", lambda: ["alpha"]) monkeypatch.setattr("muxplex.main.get_session_list", lambda: ["alpha"])
monkeypatch.setattr( monkeypatch.setattr("muxplex.main.get_snapshots", lambda: {"alpha": "some text"})
"muxplex.main.get_snapshots", lambda: {"alpha": "some text"}
)
response = client.get("/api/sessions") response = client.get("/api/sessions")
assert response.status_code == 200 assert response.status_code == 200
@@ -210,9 +208,7 @@ def test_get_sessions_includes_bell_state(client, monkeypatch):
from muxplex.state import save_state from muxplex.state import save_state
monkeypatch.setattr("muxplex.main.get_session_list", lambda: ["delta"]) monkeypatch.setattr("muxplex.main.get_session_list", lambda: ["delta"])
monkeypatch.setattr( monkeypatch.setattr("muxplex.main.get_snapshots", lambda: {"delta": "pane text"})
"muxplex.main.get_snapshots", lambda: {"delta": "pane text"}
)
save_state( save_state(
{ {
"active_session": None, "active_session": None,
@@ -647,9 +643,13 @@ def test_api_routes_not_shadowed(client):
def test_terminal_ws_route_exists(): def test_terminal_ws_route_exists():
"""The app must have a WebSocket route registered at /terminal/ws.""" """The app must have a WebSocket route registered at /terminal/ws."""
from fastapi.routing import APIRoute, APIWebSocketRoute
from muxplex.main import app from muxplex.main import app
ws_routes = [ ws_routes = [
r for r in app.routes r
if hasattr(r, "path") and r.path == "/terminal/ws" for r in app.routes
if isinstance(r, (APIRoute, APIWebSocketRoute)) and r.path == "/terminal/ws"
] ]
assert len(ws_routes) == 1, "Expected exactly one /terminal/ws route" assert len(ws_routes) == 1, "Expected exactly one /terminal/ws route"
+7 -8
View File
@@ -4,7 +4,6 @@ from pathlib import Path
from unittest.mock import patch from unittest.mock import patch
def test_cli_module_importable(): def test_cli_module_importable():
"""muxplex.cli must be importable.""" """muxplex.cli must be importable."""
from muxplex.cli import main # noqa: F401 from muxplex.cli import main # noqa: F401
@@ -87,12 +86,12 @@ def test_install_service_system_mode_target(tmp_path, monkeypatch):
def test_dunder_main_calls_main(): def test_dunder_main_calls_main():
"""python -m muxplex must call cli.main().""" """python -m muxplex must call cli.main()."""
with patch("muxplex.cli.main") as mock_main: import importlib.util
# Simulate `python -m muxplex` by exec'ing __main__.py
import muxplex.__main__ # noqa: F401
# The import itself calls main() at module level # Locate __main__.py without executing it (find_spec does not import)
# Re-exec to test: spec = importlib.util.find_spec("muxplex.__main__")
mock_main.reset_mock() assert spec is not None and spec.origin is not None
exec(Path("muxplex/__main__.py").read_text())
with patch("muxplex.cli.main") as mock_main:
exec(Path(spec.origin).read_text()) # noqa: S102
mock_main.assert_called_once() mock_main.assert_called_once()