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
This commit is contained in:
2025-09-25 12:52:30 -06:00
parent 9b3da4b2c8
commit 8fcfac80fa
2 changed files with 14 additions and 6 deletions

View File

@@ -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.db.transcripts import transcripts_controller
from reflector.ws_manager import get_ws_manager 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( async def transcript_events_websocket(
transcript_id: str, transcript_id: str,
websocket: WebSocket, websocket: WebSocket,
session: AsyncSession = Depends(get_session),
# user: Annotated[Optional[auth.UserInfo], Depends(auth.current_user_optional)], # user: Annotated[Optional[auth.UserInfo], Depends(auth.current_user_optional)],
): ):
# user_id = user["sub"] if user else None # user_id = user["sub"] if user else None

View File

@@ -297,6 +297,7 @@ async def mock_summary_processor():
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_pipeline_main_file_process( async def test_pipeline_main_file_process(
db_session,
tmpdir, tmpdir,
mock_transcript_in_db, mock_transcript_in_db,
dummy_file_transcript, dummy_file_transcript,
@@ -377,7 +378,7 @@ async def test_pipeline_main_file_process(
mock_av.side_effect = [mock_container, mock_decode_container] mock_av.side_effect = [mock_container, mock_decode_container]
# Run the pipeline # Run the pipeline
await pipeline.process(upload_path) await pipeline.process(db_session, upload_path)
# Verify audio extraction and writing # Verify audio extraction and writing
assert mock_audio_file_writer.push.called assert mock_audio_file_writer.push.called
@@ -422,6 +423,7 @@ async def test_pipeline_main_file_process(
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_pipeline_main_file_with_video( async def test_pipeline_main_file_with_video(
db_session,
tmpdir, tmpdir,
mock_transcript_in_db, mock_transcript_in_db,
dummy_file_transcript, dummy_file_transcript,
@@ -468,7 +470,7 @@ async def test_pipeline_main_file_with_video(
mock_av.side_effect = [mock_container, mock_decode_container] mock_av.side_effect = [mock_container, mock_decode_container]
# Run the pipeline # Run the pipeline
await pipeline.process(upload_path) await pipeline.process(db_session, upload_path)
# Verify audio extraction from video # Verify audio extraction from video
assert mock_audio_file_writer.push.called assert mock_audio_file_writer.push.called
@@ -486,6 +488,7 @@ async def test_pipeline_main_file_with_video(
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_pipeline_main_file_no_diarization( async def test_pipeline_main_file_no_diarization(
db_session,
tmpdir, tmpdir,
mock_transcript_in_db, mock_transcript_in_db,
dummy_file_transcript, dummy_file_transcript,
@@ -533,7 +536,7 @@ async def test_pipeline_main_file_no_diarization(
mock_av.side_effect = [mock_container, mock_decode_container] mock_av.side_effect = [mock_container, mock_decode_container]
# Run the pipeline # Run the pipeline
await pipeline.process(upload_path) await pipeline.process(db_session, upload_path)
# Verify the pipeline completed without diarization # Verify the pipeline completed without diarization
assert mock_storage._put_file.called assert mock_storage._put_file.called
@@ -547,6 +550,7 @@ async def test_pipeline_main_file_no_diarization(
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_task_pipeline_file_process( async def test_task_pipeline_file_process(
db_session,
tmpdir, tmpdir,
mock_transcript_in_db, mock_transcript_in_db,
dummy_file_transcript, dummy_file_transcript,
@@ -593,7 +597,7 @@ async def test_task_pipeline_file_process(
from reflector.pipelines.main_file_pipeline import PipelineMainFile from reflector.pipelines.main_file_pipeline import PipelineMainFile
pipeline = PipelineMainFile(transcript_id=mock_transcript_in_db.id) 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 # Verify the pipeline was executed through the task
assert mock_audio_file_writer.push.called assert mock_audio_file_writer.push.called
@@ -633,6 +637,7 @@ async def test_pipeline_file_process_no_transcript():
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_pipeline_file_process_no_audio_file( async def test_pipeline_file_process_no_audio_file(
db_session,
mock_transcript_in_db, 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 # This should fail when trying to open the file with av
with pytest.raises(Exception): with pytest.raises(Exception):
await pipeline.process(non_existent_path) await pipeline.process(db_session, non_existent_path)