from app.services.consumable_vision_algorithm import PredictionCandidate from app.services.video.session_manager import _rank_topk_for_candidates def test_rank_respects_candidate_order() -> None: topk = [ PredictionCandidate(label="缝线", confidence=0.9), PredictionCandidate(label="纱布", confidence=0.5), ] ordered = ["纱布", "缝线"] ranked = _rank_topk_for_candidates(topk, ordered) assert [c.label for c in ranked] == ["纱布", "缝线"] def test_rank_without_candidates_keeps_model_order() -> None: topk = [ PredictionCandidate(label="a", confidence=0.9), PredictionCandidate(label="b", confidence=0.5), ] ranked = _rank_topk_for_candidates(topk, []) assert [c.label for c in ranked] == ["a", "b"]