From 84aa988dd96bda481fd4a2d1d9981dc18adfd91d Mon Sep 17 00:00:00 2001 From: leo <260626284+cameledev@users.noreply.github.com> Date: Wed, 9 Sep 2026 14:29:47 +0200 Subject: [PATCH] wip --- .../recording/services/recording_events.py | 4 +-- .../tests/services/test_livekit_events.py | 29 +++++++++++-------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/backend/core/recording/services/recording_events.py b/src/backend/core/recording/services/recording_events.py index fc7b76f2..7dea0c76 100644 --- a/src/backend/core/recording/services/recording_events.py +++ b/src/backend/core/recording/services/recording_events.py @@ -86,8 +86,8 @@ class RecordingEventsService: def handle_update(recording: Recording, egress_status): """Handle egress status updates and sync recording state to room metadata. - Egress updates only updates statuses to EGRESS_ACTIVE and EGRESS_ENDING. - Other statuses are sent through egress ending. + LiveKit only sends EGRESS_ACTIVE and EGRESS_ENDING here. Terminal statuses + arrive through 'egress_ended'. """ room_name = str(recording.room.id) diff --git a/src/backend/core/tests/services/test_livekit_events.py b/src/backend/core/tests/services/test_livekit_events.py index 6b45fb50..39f735e4 100644 --- a/src/backend/core/tests/services/test_livekit_events.py +++ b/src/backend/core/tests/services/test_livekit_events.py @@ -158,33 +158,38 @@ def test_handle_egress_ended_metadata_update_fails( # pylint: disable=too-many- assert recording.status == "saved" +@mock.patch( + "core.recording.services.recording_events.notification_service." + "notify_external_services" +) @mock.patch("core.utils.notify_participants") @mock.patch("core.services.room_management.RoomManagement.update_metadata") def test_handle_egress_ended_notification_fails( - mock_update_metadata, mock_notify, service + mock_update_metadata, mock_notify, mock_notify_external_services, service ): - """Should raise ActionFailedError when notification fails but still stop recording.""" + """Should still stop and save the recording when notifying participants fails.""" + + mock_notify_external_services.return_value = False + mock_notify.side_effect = NotificationError("Error notifying") recording = RecordingFactory(worker_id="worker-1", status="active") mock_data = mock.MagicMock() mock_data.egress_info.egress_id = recording.worker_id mock_data.egress_info.status = EgressStatus.EGRESS_LIMIT_REACHED - mock_notify.side_effect = NotificationError("Error notifying") - - with pytest.raises( - ActionFailedError, - match=r"Failed to process limit reached event for recording .+", - ): - service._handle_egress_ended(mock_data) - - recording.refresh_from_db() - assert recording.status == "stopped" + service._handle_egress_ended(mock_data) + mock_notify.assert_called_once_with( + room_name=str(recording.room.id), + notification_data={"type": "screenRecordingLimitReached"}, + ) mock_update_metadata.assert_called_once_with( str(recording.room.id), remove_keys=["recording_mode", "recording_status"] ) + recording.refresh_from_db() + assert recording.status == "saved" + @mock.patch("core.utils.notify_participants") @mock.patch("core.services.room_management.RoomManagement.update_metadata")