from app.engine.summary_consensus import character_f1, select_consensus def test_medoid_prefers_agreed_event_over_outlier(): candidates = ["김씨는 학교를 세웠다.", "김씨는 학교를 세웠다.", "김씨는 미국으로 이민했다."] assert select_consensus(candidates) == 0 def test_overlength_consensus_cannot_win(): long = "긴" * 51 assert select_consensus([long, long, "학교를 세웠다."]) == 2 assert select_consensus([long, ""]) == -1 def test_empty_outputs_do_not_change_candidate_choice(): assert select_consensus(["", "학교를 세웠다.", "학교를 세웠다."]) == 1 assert character_f1("", "") == 0 def test_bigram_overlap_keeps_multiplicity(): assert character_f1("가가가", "가가") == 2 / 3 def test_word_overlap_and_invalid_weight(): import pytest from app.engine.summary_consensus import word_f1 assert word_f1("a b c", "a b") == 2 / 3 assert word_f1("a", "a") == 0 with pytest.raises(ValueError): select_consensus(["요약"], word_weight=1.5) def test_public_summary_reports_invalid_when_every_candidate_fails(monkeypatch): from app.engine import summary_consensus monkeypatch.setattr(summary_consensus, "generate_candidates", lambda client, text: [ {"summary": "", "finish_reason": "length"}, {"summary": "긴" * 51, "finish_reason": "stop"}]) result = summary_consensus.summarize_short(None, "원문") assert result["valid"] is False assert result["summary"] == "" assert result["selected_index"] == -1