fix: SRT 按 cue 解析并按 ID 回填译文,OCR 空帧分段与失败重试
This commit is contained in:
+6
-6
@@ -485,7 +485,7 @@ def test_llm_translate_lines_via_fake_api(monkeypatch) -> None:
|
||||
"choices": [
|
||||
{
|
||||
"message": {
|
||||
"content": "译文一\n译文二\n译文三\n译文四\n译文五"
|
||||
"content": json.dumps([{"id": i, "text": text} for i, text in enumerate(["译文一", "译文二", "译文三", "译文四", "译文五"], 1)])
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -548,7 +548,7 @@ def test_llm_translate_lines_default_timeout(monkeypatch) -> None:
|
||||
|
||||
def fake_open(request, timeout):
|
||||
captured["timeout"] = timeout
|
||||
return FakeUrlOpenResponse("译文一")
|
||||
return FakeUrlOpenResponse('[{"id": 1, "text": "译文一"}]')
|
||||
|
||||
monkeypatch.setattr("nodes.llm.urllib.request.urlopen", fake_open)
|
||||
monkeypatch.setenv("LLM_API_BASE", "http://fake/v1/chat/completions")
|
||||
@@ -565,7 +565,7 @@ def test_llm_translate_lines_env_timeout(monkeypatch) -> None:
|
||||
|
||||
def fake_open(request, timeout):
|
||||
captured["timeout"] = timeout
|
||||
return FakeUrlOpenResponse("译文一")
|
||||
return FakeUrlOpenResponse('[{"id": 1, "text": "译文一"}]')
|
||||
|
||||
monkeypatch.setattr("nodes.llm.urllib.request.urlopen", fake_open)
|
||||
monkeypatch.setenv("LLM_API_BASE", "http://fake/v1/chat/completions")
|
||||
@@ -598,8 +598,8 @@ def test_llm_invoke_success(tmp_path, monkeypatch) -> None:
|
||||
assert "译文1" in content
|
||||
|
||||
|
||||
def test_llm_invoke_pads_short_translation(tmp_path, monkeypatch) -> None:
|
||||
"""验证译文行数不足时用空行补齐,保持 SRT 结构完整。"""
|
||||
def test_llm_invoke_rejects_short_translation(tmp_path, monkeypatch) -> None:
|
||||
"""防御性校验:译文条数不足时失败,不用空行掩盖不完整结果。"""
|
||||
source = _make_srt(tmp_path, count=3)
|
||||
monkeypatch.setattr(
|
||||
"nodes.llm.translate_lines",
|
||||
@@ -613,7 +613,7 @@ def test_llm_invoke_pads_short_translation(tmp_path, monkeypatch) -> None:
|
||||
output_dir=str(tmp_path / "out2"),
|
||||
)
|
||||
)
|
||||
assert response.status == "completed"
|
||||
assert response.status == "failed"
|
||||
|
||||
|
||||
def test_llm_invoke_missing_input(tmp_path) -> None:
|
||||
|
||||
Reference in New Issue
Block a user