"""Сравнение качества модели champion vs candidate — money-safety вердикта (без сети, стаб ask_fn).""" import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) import model_eval as me # noqa: E402 _Q = [ {"id": 1, "question": "НР по какому приказу?", "markers": ["812/пр"]}, {"id": 2, "question": "Ставка НР на землю?", "markers": ["95"]}, ] def _fixed(answers: dict): """ask_fn(model_id, question) → заранее заданный ответ по model_id.""" return lambda model_id, q: answers.get(model_id, "") def test_equal_quality_ok(): ans = {"champ": "по приказу 812/пр и 95%", "cand": "812/пр, ставка 95%"} r = me.eval_candidate("cand", "champ", _Q, _fixed(ans)) assert r["verdict"] == "OK" and r["candidate_pass"] == 2 == r["champion_pass"] def test_candidate_marker_regression_reject(): """Кандидат теряет факт (95%) → REJECT (регресс маркеров).""" ans = {"champ": "812/пр, 95%", "cand": "812/пр, но ставку не помню"} r = me.eval_candidate("cand", "champ", _Q, _fixed(ans)) assert r["verdict"] == "REJECT" and r["candidate_pass"] < r["champion_pass"] def test_candidate_hard_fail_reject(): """Кандидат даёт ошибку/пусто там, где champion ответил → REJECT (жёсткий сигнал).""" def ask(model_id, q): if model_id == "cand" and "земл" in q: return "error: 500" return {"champ": "812/пр 95%", "cand": "812/пр 95%"}[model_id] r = me.eval_candidate("cand", "champ", _Q, ask) assert r["verdict"] == "REJECT" and r["new_hard_fails"] == 1 def test_candidate_better_ok(): """Кандидат отвечает верно там, где champion ошибся → OK (не хуже).""" ans = {"champ": "812/пр, ставку забыл", "cand": "812/пр, 95%"} r = me.eval_candidate("cand", "champ", _Q, _fixed(ans)) assert r["verdict"] == "OK" and r["candidate_pass"] > r["champion_pass"] def test_error_detection(): assert me._is_error("") and me._is_error(" ") and me._is_error("error: 429") assert not me._is_error("НР по приказу 812/пр составляет 95%")