from evanescere.schemas import ClipCandidate from evanescere.services.llm import dedupe_and_rank_candidates, parse_clip_response def test_parse_clip_response(): candidates = parse_clip_response( """ { "clips": [ { "start_sec": 10, "end_sec": 60, "title_zh": "标题", "summary_zh": "摘要", "reason": "有趣", "score": 0.9, "tags": ["反应"], "subtitle_priority": "high" } ] } """ ) assert candidates[0].title_zh == "标题" def test_dedupe_and_rank_candidates_filters_short_and_overlapping(): candidates = [ ClipCandidate( start_sec=0, end_sec=20, title_zh="too short", summary_zh="", reason="", score=1, ), ClipCandidate( start_sec=0, end_sec=60, title_zh="best", summary_zh="", reason="", score=0.9, ), ClipCandidate( start_sec=10, end_sec=65, title_zh="overlap", summary_zh="", reason="", score=0.8, ), ClipCandidate( start_sec=120, end_sec=180, title_zh="second", summary_zh="", reason="", score=0.7, ), ] ranked = dedupe_and_rank_candidates(candidates) assert [candidate.title_zh for candidate in ranked] == ["best", "second"]