import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from backend.subtitle_ai import process_subtitles_with_ai class FakeClient: def chat_json(self, system_prompt, user_payload): return { "translations": [ {"index": 1, "zh": "我第一次做投资人是在 24 岁。"} ] } def test_process_subtitles_with_ai_returns_clean_en_and_zh_vtt(): raw = """WEBVTT 00:00:00.872 --> 00:00:04.959 My first job as an investor was when I was 24 years old, 00:00:00.872 --> 00:00:04.959 My first job as an investor was when I was 24 years old, """ result = process_subtitles_with_ai(raw, FakeClient()) assert "My first job as an investor" in result["subtitle_en_content"] assert "我第一次做投资人是在 24 岁。" in result["subtitle_zh_content"] assert result["report"]["duplicate_count"] == 1 assert result["report"]["translation_count"] == 1 if __name__ == "__main__": test_process_subtitles_with_ai_returns_clean_en_and_zh_vtt()