fixes
This commit is contained in:
+59
-1
@@ -1,5 +1,11 @@
|
||||
from evanescere.schemas import ClipCandidate
|
||||
from evanescere.services.llm import dedupe_and_rank_candidates, parse_clip_response
|
||||
from evanescere.services.llm import (
|
||||
TranscriptChunk,
|
||||
candidate_quota_per_chunk,
|
||||
dedupe_and_rank_candidates,
|
||||
parse_clip_response,
|
||||
render_user_prompt,
|
||||
)
|
||||
|
||||
|
||||
def test_parse_clip_response():
|
||||
@@ -62,3 +68,55 @@ def test_dedupe_and_rank_candidates_filters_short_and_overlapping():
|
||||
ranked = dedupe_and_rank_candidates(candidates)
|
||||
assert [candidate.title_zh for candidate in ranked] == ["best", "second"]
|
||||
|
||||
|
||||
def test_candidate_quota_uses_total_budget_across_chunks():
|
||||
assert candidate_quota_per_chunk(1, 20) == 20
|
||||
assert candidate_quota_per_chunk(4, 20) == 5
|
||||
assert candidate_quota_per_chunk(0, 20) == 0
|
||||
|
||||
|
||||
def test_dedupe_respects_configured_duration_and_total_cap():
|
||||
candidates = [
|
||||
ClipCandidate(
|
||||
start_sec=index * 240,
|
||||
end_sec=index * 240 + duration,
|
||||
title_zh=f"clip-{index}",
|
||||
summary_zh="",
|
||||
reason="",
|
||||
score=1 - index / 100,
|
||||
)
|
||||
for index, duration in enumerate([60, 180, 181, 90])
|
||||
]
|
||||
ranked = dedupe_and_rank_candidates(
|
||||
candidates,
|
||||
min_clip_seconds=30,
|
||||
max_clip_seconds=180,
|
||||
max_candidates_total=2,
|
||||
)
|
||||
assert [candidate.title_zh for candidate in ranked] == ["clip-0", "clip-1"]
|
||||
|
||||
|
||||
def test_render_user_prompt_inserts_configured_values():
|
||||
prompt = render_user_prompt(
|
||||
"{max_candidates}|{min_clip_seconds}|{max_clip_seconds}|{chunk_start_sec}|{chunk_end_sec}|{transcript}",
|
||||
chunk=TranscriptChunk(12.25, 42.75, "hello"),
|
||||
max_candidates=20,
|
||||
min_clip_seconds=30,
|
||||
max_clip_seconds=180,
|
||||
)
|
||||
assert prompt == "20|30|180|12.2|42.8|hello"
|
||||
|
||||
|
||||
def test_render_user_prompt_rejects_unknown_placeholder():
|
||||
try:
|
||||
render_user_prompt(
|
||||
"{unknown}",
|
||||
chunk=TranscriptChunk(0, 1, "hello"),
|
||||
max_candidates=20,
|
||||
min_clip_seconds=30,
|
||||
max_clip_seconds=180,
|
||||
)
|
||||
except ValueError as exc:
|
||||
assert "Unknown placeholder" in str(exc)
|
||||
else:
|
||||
raise AssertionError("Expected unknown placeholder to fail")
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from evanescere.services.thumbnail import select_character_overlay
|
||||
|
||||
|
||||
def test_select_character_overlay_returns_none_for_empty_directory(tmp_path: Path):
|
||||
assert select_character_overlay(str(tmp_path)) is None
|
||||
|
||||
|
||||
def test_select_character_overlay_filters_png_files(tmp_path: Path):
|
||||
first = tmp_path / "first.PNG"
|
||||
second = tmp_path / "second.png"
|
||||
first.write_bytes(b"")
|
||||
second.write_bytes(b"")
|
||||
(tmp_path / "notes.txt").write_text("ignore me")
|
||||
|
||||
with patch("evanescere.services.thumbnail.random.choice", return_value=second) as choice:
|
||||
assert select_character_overlay(str(tmp_path)) == second
|
||||
|
||||
assert choice.call_args.args[0] == [first, second]
|
||||
|
||||
@@ -33,3 +33,20 @@ def test_parse_propfind_response_filters_video_files():
|
||||
WebDavFile("https://host/webdav/recordings/stream.flv", "stream.flv", 123, None)
|
||||
]
|
||||
|
||||
|
||||
def test_parse_propfind_response_preserves_encoded_chinese_filename():
|
||||
xml = """<?xml version="1.0"?>
|
||||
<D:multistatus xmlns:D="DAV:">
|
||||
<D:response>
|
||||
<D:href>/Hirumi/hirumi-2-06%E6%9C%8801%E6%97%A501%E6%97%B602%E5%88%8641%E7%A7%92.flv</D:href>
|
||||
<D:propstat><D:prop><D:getcontentlength>123</D:getcontentlength></D:prop></D:propstat>
|
||||
</D:response>
|
||||
</D:multistatus>"""
|
||||
assert parse_propfind_response(xml, "http://recording.home.arpa/Hirumi") == [
|
||||
WebDavFile(
|
||||
"http://recording.home.arpa/Hirumi/hirumi-2-06%E6%9C%8801%E6%97%A501%E6%97%B602%E5%88%8641%E7%A7%92.flv",
|
||||
"hirumi-2-06月01日01时02分41秒.flv",
|
||||
123,
|
||||
None,
|
||||
)
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user