From 2f61bd7747268674af8977dc8cabbab222d3620a Mon Sep 17 00:00:00 2001 From: GitHub Copilot Date: Sat, 24 Jan 2026 16:09:53 +0000 Subject: [PATCH] Don't resize terminal on session disconnect Rename DISCONNECT_RESIZE to DEFAULT_TERMINAL_SIZE Update tests for removed _resize_on_disconnect and stricter available check Bump version to 0.2.7 --- pyproject.toml | 2 +- src/textual_webterm/local_server.py | 19 +++++-------------- tests/test_docker_stats.py | 7 +++++-- tests/test_local_server_unit.py | 11 ----------- 4 files changed, 11 insertions(+), 28 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index aff947c..595643c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "textual-webterm" -version = "0.2.6" +version = "0.2.7" description = "Serve terminal sessions over the web" authors = ["Will McGugan "] license = "MIT" diff --git a/src/textual_webterm/local_server.py b/src/textual_webterm/local_server.py index 7c038cb..c5e8b20 100644 --- a/src/textual_webterm/local_server.py +++ b/src/textual_webterm/local_server.py @@ -33,7 +33,7 @@ if TYPE_CHECKING: log = logging.getLogger("textual-web") -DISCONNECT_RESIZE = (132, 45) +DEFAULT_TERMINAL_SIZE = (132, 45) SCREENSHOT_CACHE_SECONDS = 1.0 SCREENSHOT_MAX_CACHE_SECONDS = 60.0 @@ -431,14 +431,6 @@ class LocalServer: return session_created - async def _resize_on_disconnect(self, route_key: str) -> None: - session_process = self.session_manager.get_session_by_route_key(RouteKey(route_key)) - if session_process is None or not hasattr(session_process, "set_terminal_size"): - return - width, height = DISCONNECT_RESIZE - with contextlib.suppress(OSError): - await session_process.set_terminal_size(width, height) - async def _handle_websocket(self, request: web.Request) -> web.WebSocketResponse: route_key = request.match_info["route_key"] ws = web.WebSocketResponse(heartbeat=30.0, max_msg_size=64 * 1024) @@ -478,7 +470,6 @@ class LocalServer: finally: log.info("WebSocket connection closed for route %s", route_key) self._websocket_connections.pop(route_key, None) - await self._resize_on_disconnect(route_key) return ws @@ -535,15 +526,15 @@ class LocalServer: # Parse requested dimensions (used when creating new sessions) try: - req_width = int(request.query.get("width", str(DISCONNECT_RESIZE[0]))) + req_width = int(request.query.get("width", str(DEFAULT_TERMINAL_SIZE[0]))) except ValueError: - req_width = DISCONNECT_RESIZE[0] + req_width = DEFAULT_TERMINAL_SIZE[0] req_width = max(10, min(400, req_width)) try: - req_height = int(request.query.get("height", str(DISCONNECT_RESIZE[1]))) + req_height = int(request.query.get("height", str(DEFAULT_TERMINAL_SIZE[1]))) except ValueError: - req_height = DISCONNECT_RESIZE[1] + req_height = DEFAULT_TERMINAL_SIZE[1] req_height = max(5, min(200, req_height)) session_process = self.session_manager.get_session_by_route_key(RouteKey(route_key)) diff --git a/tests/test_docker_stats.py b/tests/test_docker_stats.py index 0a07f82..596407c 100644 --- a/tests/test_docker_stats.py +++ b/tests/test_docker_stats.py @@ -67,13 +67,16 @@ class TestDockerStatsCollector: """Tests for Docker stats collector.""" def test_available_checks_socket(self, tmp_path): - """available property checks socket existence.""" + """available property checks socket existence and connectivity.""" socket_path = tmp_path / "docker.sock" collector = DockerStatsCollector(str(socket_path)) assert collector.available is False + # Just touching the file isn't enough - need actual socket connectivity + # Since we can't easily create a real Unix socket in tests, + # verify that a non-socket file returns False socket_path.touch() - assert collector.available is True + assert collector.available is False # File exists but can't connect def test_get_cpu_history_empty(self): """Empty history returns empty list.""" diff --git a/tests/test_local_server_unit.py b/tests/test_local_server_unit.py index 3f77368..79cc228 100644 --- a/tests/test_local_server_unit.py +++ b/tests/test_local_server_unit.py @@ -167,17 +167,6 @@ class TestLocalServerHelpers: assert session_created is True ws.send_json.assert_awaited_once_with(["error", "No app configured"]) - @pytest.mark.asyncio - async def test_resize_on_disconnect_calls_set_terminal_size(self, server, monkeypatch): - session = MagicMock() - session.set_terminal_size = AsyncMock() - - monkeypatch.setattr(server.session_manager, "get_session_by_route_key", lambda _rk: session) - - await server._resize_on_disconnect("rk") - - session.set_terminal_size.assert_called_once_with(132, 45) - @pytest.mark.asyncio async def test_create_terminal_session_sends_error_if_no_apps(self, server): ws = MagicMock()