Refresh docker watch tiles on new containers

This commit is contained in:
GitHub Copilot
2026-01-30 10:56:39 +00:00
parent 6eaeeb624e
commit d9c35ee95d
2 changed files with 30 additions and 5 deletions
+1 -4
View File
@@ -281,10 +281,6 @@ class DockerWatcher:
container_id = actor.get("ID", "") container_id = actor.get("ID", "")
attributes = actor.get("Attributes", {}) attributes = actor.get("Attributes", {})
# Only handle containers with any webterm label
if not _has_webterm_label(attributes):
return
if action == "start": if action == "start":
# Get full container info # Get full container info
status, body = await self._docker_request("GET", f"/containers/{container_id}/json") status, body = await self._docker_request("GET", f"/containers/{container_id}/json")
@@ -296,6 +292,7 @@ class DockerWatcher:
"Names": ["/" + container_info.get("Name", "").lstrip("/")], "Names": ["/" + container_info.get("Name", "").lstrip("/")],
"Labels": container_info.get("Config", {}).get("Labels", {}), "Labels": container_info.get("Config", {}).get("Labels", {}),
} }
if _has_webterm_label(container.get("Labels", {})):
await self._add_container(container) await self._add_container(container)
elif action == "die": elif action == "die":
await self._remove_container(container_id) await self._remove_container(container_id)
+28
View File
@@ -221,6 +221,7 @@ class TestDockerWatcherIntegration:
async def test_handle_event_without_label(self, session_manager): async def test_handle_event_without_label(self, session_manager):
"""Test that events without our label are ignored.""" """Test that events without our label are ignored."""
watcher = DockerWatcher(session_manager) watcher = DockerWatcher(session_manager)
watcher._docker_request = AsyncMock(return_value=(404, ""))
event = { event = {
"Action": "start", "Action": "start",
@@ -235,6 +236,33 @@ class TestDockerWatcherIntegration:
# Should not add container # Should not add container
session_manager.add_app.assert_not_called() 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( @pytest.mark.parametrize(
("labels", "expected"), ("labels", "expected"),