From d9c35ee95d69b9d60d9e225265a1e0429e45edf9 Mon Sep 17 00:00:00 2001 From: GitHub Copilot Date: Fri, 30 Jan 2026 10:56:39 +0000 Subject: [PATCH] Refresh docker watch tiles on new containers --- src/webterm/docker_watcher.py | 7 ++----- tests/test_docker_watcher.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/webterm/docker_watcher.py b/src/webterm/docker_watcher.py index 014b310..23b92fc 100644 --- a/src/webterm/docker_watcher.py +++ b/src/webterm/docker_watcher.py @@ -281,10 +281,6 @@ class DockerWatcher: container_id = actor.get("ID", "") attributes = actor.get("Attributes", {}) - # Only handle containers with any webterm label - if not _has_webterm_label(attributes): - return - if action == "start": # Get full container info status, body = await self._docker_request("GET", f"/containers/{container_id}/json") @@ -296,7 +292,8 @@ class DockerWatcher: "Names": ["/" + container_info.get("Name", "").lstrip("/")], "Labels": container_info.get("Config", {}).get("Labels", {}), } - await self._add_container(container) + if _has_webterm_label(container.get("Labels", {})): + await self._add_container(container) elif action == "die": await self._remove_container(container_id) diff --git a/tests/test_docker_watcher.py b/tests/test_docker_watcher.py index 4b1a48d..d9bb398 100644 --- a/tests/test_docker_watcher.py +++ b/tests/test_docker_watcher.py @@ -221,6 +221,7 @@ class TestDockerWatcherIntegration: async def test_handle_event_without_label(self, session_manager): """Test that events without our label are ignored.""" watcher = DockerWatcher(session_manager) + watcher._docker_request = AsyncMock(return_value=(404, "")) event = { "Action": "start", @@ -235,6 +236,33 @@ class TestDockerWatcherIntegration: # Should not add container session_manager.add_app.assert_not_called() + @pytest.mark.asyncio + async def test_handle_start_event_label_added_after_start(self, session_manager): + """Container that gains label after start is picked up.""" + watcher = DockerWatcher(session_manager) + + async def mock_request(method, path): + if "/containers/" in path and "/json" in path: + return ( + 200, + '{"Name": "/test-service", "Config": {"Labels": {"webterm-command": "auto"}}}', + ) + return 404, "" + + watcher._docker_request = mock_request + + event = { + "Action": "start", + "Actor": { + "ID": "container123", + "Attributes": {}, # Labels not present on event + }, + } + + await watcher._handle_event(event) + + session_manager.add_app.assert_called_once() + @pytest.mark.parametrize( ("labels", "expected"),