@@ -76,6 +76,7 @@ def save_file(file, path):
7676 assert _get_response_status (response ) == 200
7777 assert [task ["upload_index" ] for task in payload ["tasks" ]] == [0 , 2 ]
7878 assert payload ["errors" ][0 ]["upload_index" ] == 1
79+ assert payload ["errors" ][0 ]["error" ] == "Failed to process file"
7980
8081 @patch ("application.api.user.tasks.store_attachment.delay" )
8182 @patch ("application.stt.upload_limits.settings" )
@@ -380,3 +381,57 @@ def test_live_stt_chunk_rejects_missing_session(
380381
381382 assert _get_response_status (response ) == 404
382383 assert _get_response_json (response )["message" ] == "Live transcription session not found"
384+
385+ @patch ("application.api.user.attachments.routes.STTCreator.create_stt" )
386+ @patch ("application.api.user.attachments.routes.get_redis_instance" )
387+ def test_live_stt_chunk_hides_internal_value_errors (
388+ self , mock_get_redis , mock_create_stt , flask_app , mock_mongo_db
389+ ):
390+ from application .api .user .attachments .routes import (
391+ LiveSpeechToTextChunk ,
392+ LiveSpeechToTextStart ,
393+ )
394+
395+ app = Flask (__name__ )
396+ fake_redis = FakeRedis ()
397+ mock_get_redis .return_value = fake_redis
398+
399+ start_resource = LiveSpeechToTextStart ()
400+ with app .test_request_context (
401+ "/api/stt/live/start" ,
402+ method = "POST" ,
403+ json = {"language" : "ru" },
404+ ):
405+ request .decoded_token = {"sub" : "test_user" }
406+ start_response = start_resource .post ()
407+ session_id = _get_response_json (start_response )["session_id" ]
408+
409+ mock_stt = MagicMock ()
410+ mock_stt .transcribe .return_value = {
411+ "text" : "hello there" ,
412+ "language" : "ru" ,
413+ "duration_s" : 1.0 ,
414+ "segments" : [],
415+ "provider" : "openai" ,
416+ }
417+ mock_create_stt .return_value = mock_stt
418+
419+ chunk_resource = LiveSpeechToTextChunk ()
420+ with app .test_request_context (
421+ "/api/stt/live/chunk" ,
422+ method = "POST" ,
423+ data = {
424+ "session_id" : session_id ,
425+ "chunk_index" : "-1" ,
426+ "file" : (io .BytesIO (b"chunk-neg" ), "chunk-neg.wav" ),
427+ },
428+ content_type = "multipart/form-data" ,
429+ ):
430+ request .decoded_token = {"sub" : "test_user" }
431+ response = chunk_resource .post ()
432+
433+ assert _get_response_status (response ) == 409
434+ assert (
435+ _get_response_json (response )["message" ]
436+ == "Invalid live transcription chunk"
437+ )
0 commit comments