From 8fcfac80face2143f5e0a7487324c2ff6bc1b211 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Thu, 25 Sep 2025 12:52:30 -0600 Subject: [PATCH] fix: resolve session management issues in tests and WebSocket endpoints - Add missing db_session parameter to test_pipeline_main_file.py tests - Fix WebSocket endpoint missing session dependency injection - Update test fixtures to pass session as first argument to pipeline.process() - Add required imports (Depends, AsyncSession, get_session) to transcripts_websocket.py Note: 2 WebRTC tests still failing due to known asyncio event loop issues with SQLAlchemy --- server/reflector/views/transcripts_websocket.py | 5 ++++- server/tests/test_pipeline_main_file.py | 15 ++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/server/reflector/views/transcripts_websocket.py b/server/reflector/views/transcripts_websocket.py index 6bf36f69..480b27d0 100644 --- a/server/reflector/views/transcripts_websocket.py +++ b/server/reflector/views/transcripts_websocket.py @@ -4,8 +4,10 @@ Transcripts websocket API """ -from fastapi import APIRouter, HTTPException, WebSocket, WebSocketDisconnect +from fastapi import APIRouter, Depends, HTTPException, WebSocket, WebSocketDisconnect +from sqlalchemy.ext.asyncio import AsyncSession +from reflector.db import get_session from reflector.db.transcripts import transcripts_controller from reflector.ws_manager import get_ws_manager @@ -21,6 +23,7 @@ async def transcript_get_websocket_events(transcript_id: str): async def transcript_events_websocket( transcript_id: str, websocket: WebSocket, + session: AsyncSession = Depends(get_session), # user: Annotated[Optional[auth.UserInfo], Depends(auth.current_user_optional)], ): # user_id = user["sub"] if user else None diff --git a/server/tests/test_pipeline_main_file.py b/server/tests/test_pipeline_main_file.py index 1d7f1ade..305912e4 100644 --- a/server/tests/test_pipeline_main_file.py +++ b/server/tests/test_pipeline_main_file.py @@ -297,6 +297,7 @@ async def mock_summary_processor(): @pytest.mark.asyncio async def test_pipeline_main_file_process( + db_session, tmpdir, mock_transcript_in_db, dummy_file_transcript, @@ -377,7 +378,7 @@ async def test_pipeline_main_file_process( mock_av.side_effect = [mock_container, mock_decode_container] # Run the pipeline - await pipeline.process(upload_path) + await pipeline.process(db_session, upload_path) # Verify audio extraction and writing assert mock_audio_file_writer.push.called @@ -422,6 +423,7 @@ async def test_pipeline_main_file_process( @pytest.mark.asyncio async def test_pipeline_main_file_with_video( + db_session, tmpdir, mock_transcript_in_db, dummy_file_transcript, @@ -468,7 +470,7 @@ async def test_pipeline_main_file_with_video( mock_av.side_effect = [mock_container, mock_decode_container] # Run the pipeline - await pipeline.process(upload_path) + await pipeline.process(db_session, upload_path) # Verify audio extraction from video assert mock_audio_file_writer.push.called @@ -486,6 +488,7 @@ async def test_pipeline_main_file_with_video( @pytest.mark.asyncio async def test_pipeline_main_file_no_diarization( + db_session, tmpdir, mock_transcript_in_db, dummy_file_transcript, @@ -533,7 +536,7 @@ async def test_pipeline_main_file_no_diarization( mock_av.side_effect = [mock_container, mock_decode_container] # Run the pipeline - await pipeline.process(upload_path) + await pipeline.process(db_session, upload_path) # Verify the pipeline completed without diarization assert mock_storage._put_file.called @@ -547,6 +550,7 @@ async def test_pipeline_main_file_no_diarization( @pytest.mark.asyncio async def test_task_pipeline_file_process( + db_session, tmpdir, mock_transcript_in_db, dummy_file_transcript, @@ -593,7 +597,7 @@ async def test_task_pipeline_file_process( from reflector.pipelines.main_file_pipeline import PipelineMainFile pipeline = PipelineMainFile(transcript_id=mock_transcript_in_db.id) - await pipeline.process(upload_path) + await pipeline.process(db_session, upload_path) # Verify the pipeline was executed through the task assert mock_audio_file_writer.push.called @@ -633,6 +637,7 @@ async def test_pipeline_file_process_no_transcript(): @pytest.mark.asyncio async def test_pipeline_file_process_no_audio_file( + db_session, mock_transcript_in_db, ): """ @@ -650,4 +655,4 @@ async def test_pipeline_file_process_no_audio_file( # This should fail when trying to open the file with av with pytest.raises(Exception): - await pipeline.process(non_existent_path) + await pipeline.process(db_session, non_existent_path)