fix: progress broadcasts now use correct WebSocket room names

- Fixed room name mismatch: ProgressService was broadcasting to
  'download_progress' but JS clients join 'downloads' room
- Added _get_room_for_progress_type() mapping function
- Updated all progress methods to use correct room names
- Added 13 new tests for room name mapping and broadcast verification
- Updated existing tests to expect correct room names
- Fixed JS clients to join valid rooms (downloads, queue, scan)
This commit is contained in:
2025-12-16 19:21:30 +01:00
parent 4c9bf6b982
commit 700f491ef9
7 changed files with 490 additions and 17 deletions

View File

@@ -133,6 +133,30 @@ class ProgressServiceError(Exception):
"""Service-level exception for progress operations."""
# Mapping from ProgressType to WebSocket room names
# This ensures compatibility with the valid rooms defined in the WebSocket API:
# "downloads", "queue", "scan", "system", "errors"
_PROGRESS_TYPE_TO_ROOM: Dict[ProgressType, str] = {
ProgressType.DOWNLOAD: "downloads",
ProgressType.SCAN: "scan",
ProgressType.QUEUE: "queue",
ProgressType.SYSTEM: "system",
ProgressType.ERROR: "errors",
}
def _get_room_for_progress_type(progress_type: ProgressType) -> str:
"""Get the WebSocket room name for a progress type.
Args:
progress_type: The type of progress update
Returns:
The WebSocket room name to broadcast to
"""
return _PROGRESS_TYPE_TO_ROOM.get(progress_type, "system")
class ProgressService:
"""Manages real-time progress updates and broadcasting.
@@ -293,7 +317,7 @@ class ProgressService:
)
# Emit event to subscribers
room = f"{progress_type.value}_progress"
room = _get_room_for_progress_type(progress_type)
event = ProgressEvent(
event_type=f"{progress_type.value}_progress",
progress_id=progress_id,
@@ -370,7 +394,7 @@ class ProgressService:
should_broadcast = force_broadcast or percent_change >= 1.0
if should_broadcast:
room = f"{update.type.value}_progress"
room = _get_room_for_progress_type(update.type)
event = ProgressEvent(
event_type=f"{update.type.value}_progress",
progress_id=progress_id,
@@ -427,7 +451,7 @@ class ProgressService:
)
# Emit completion event
room = f"{update.type.value}_progress"
room = _get_room_for_progress_type(update.type)
event = ProgressEvent(
event_type=f"{update.type.value}_progress",
progress_id=progress_id,
@@ -483,7 +507,7 @@ class ProgressService:
)
# Emit failure event
room = f"{update.type.value}_progress"
room = _get_room_for_progress_type(update.type)
event = ProgressEvent(
event_type=f"{update.type.value}_progress",
progress_id=progress_id,
@@ -533,7 +557,7 @@ class ProgressService:
)
# Emit cancellation event
room = f"{update.type.value}_progress"
room = _get_room_for_progress_type(update.type)
event = ProgressEvent(
event_type=f"{update.type.value}_progress",
progress_id=progress_id,