diff --git a/tests/tools/test_transcription_tools.py b/tests/tools/test_transcription_tools.py index c7cf8950239..a424a06e17a 100644 --- a/tests/tools/test_transcription_tools.py +++ b/tests/tools/test_transcription_tools.py @@ -6,13 +6,20 @@ end-to-end dispatch. All external dependencies are mocked. """ import os +import sys import struct import subprocess +import types import wave from unittest.mock import MagicMock, patch import pytest +if "faster_whisper" not in sys.modules: + faster_whisper_stub = types.ModuleType("faster_whisper") + faster_whisper_stub.WhisperModel = MagicMock(name="WhisperModel") + sys.modules["faster_whisper"] = faster_whisper_stub + # ============================================================================ # Fixtures @@ -761,6 +768,23 @@ class TestValidateAudioFileEdgeCases: assert result is not None assert "not a file" in result["error"] + def test_symlink_with_supported_extension_is_rejected(self, tmp_path): + if not hasattr(os, "symlink"): + pytest.skip("symlinks are not supported on this platform") + + target = tmp_path / "target.txt" + target.write_bytes(b"not audio") + link = tmp_path / "linked.wav" + try: + os.symlink(target, link) + except (OSError, NotImplementedError) as exc: + pytest.skip(f"symlink creation unavailable: {exc}") + + from tools.transcription_tools import _validate_audio_file + result = _validate_audio_file(str(link)) + assert result is not None + assert "symbolic link" in result["error"] + def test_stat_oserror(self, tmp_path): f = tmp_path / "test.ogg" f.write_bytes(b"data") diff --git a/tools/transcription_tools.py b/tools/transcription_tools.py index 0a8e6e5054f..91396cca93e 100644 --- a/tools/transcription_tools.py +++ b/tools/transcription_tools.py @@ -998,6 +998,8 @@ def _validate_audio_file(file_path: str) -> Optional[Dict[str, Any]]: """Validate the audio file. Returns an error dict or None if OK.""" audio_path = Path(file_path) + if os.path.islink(audio_path): + return {"success": False, "transcript": "", "error": f"Path is a symbolic link: {file_path}"} if not audio_path.exists(): return {"success": False, "transcript": "", "error": f"Audio file not found: {file_path}"} if not audio_path.is_file():