ReMe/tests/unit/test_lme_judge.py
jinliyl 54fa3381d7
Some checks failed
CI and Release / Docker / Build and test / amd64 (push) Has been cancelled
CI and Release / Docker / Build and test / arm64 (push) Has been cancelled
Security / CodeQL / Analyze python (push) Has been cancelled
CI / Python quality / Pre-commit (push) Has been cancelled
CI / Python tests / Unit Tests - py3.12 (push) Has been cancelled
CI / Python tests / Unit Tests - py3.13 (push) Has been cancelled
CI / Python tests / Unit Tests - py3.14 (push) Has been cancelled
CI / Python packages / Build and verify distributions (push) Has been cancelled
CI / Python quality / GitHub Actions (push) Has been cancelled
CI / Python tests / Hermes embedded - ubuntu-latest (push) Has been cancelled
CI / Python tests / Hermes embedded - windows-latest (push) Has been cancelled
CI / Python tests / Unit Tests - py3.11 (push) Has been cancelled
CI / ReMe Studio / Studio checks (push) Has been cancelled
Deploy / Documentation / Build documentation (push) Has been cancelled
CI / Windows / CLI smoke - py3.11 (push) Has been cancelled
Security / CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI and Release / Docker / Publish multi-platform tags (push) Has been cancelled
Deploy / Documentation / deploy (push) Has been cancelled
refactor(core): reorganize the ReMe runtime and shared helpers (#769)
* refactor(core): reorganize the ReMe runtime and shared helpers

* test(status): import the base component from its canonical module

* test: remove redundant unit checks

* refactor(core): use canonical runtime imports and shared CLI discovery

Restore evolve behavior to the base branch and update its imports. Use Application as the runtime entry point and encode SSE in the HTTP service.

* fix(cli): honor caller config when service replay is incomplete

Use partial startup overrides for port probes and resolve named configs before requesting the service process working directory.
2026-11-20 22:06:46 +08:00

74 lines
3 KiB
Python

"""LongMemEval judging retries invalid outputs without treating them as scores."""
# pylint: disable=missing-function-docstring
from pathlib import Path
from types import SimpleNamespace
from unittest.mock import AsyncMock
import pytest
from reme.core.context import RuntimeContext
@pytest.fixture(name="judge")
def fixture_judge(monkeypatch):
root = Path(__file__).resolve().parents[2] / "plugins/lme-judge/src"
monkeypatch.syspath_prepend(str(root))
from judge_lme.llm_judge import LmeAnswerJudgeStep
step = LmeAnswerJudgeStep()
step.context = RuntimeContext.from_context(None, query="When?", agent_answer="Today", golden_answer="Today")
step.agent_wrapper = SimpleNamespace(reply=AsyncMock())
return step
@pytest.mark.asyncio
@pytest.mark.parametrize("raw,expected", [("YES", "yes"), (" No, incorrect.", "no")])
async def test_valid_judgement_does_not_retry(judge, raw, expected):
judge.agent_wrapper.reply.return_value = {"result": raw, "status": "completed", "error": None}
response = await judge.execute()
assert response.success
assert response.answer == expected
assert response.metadata["raw_answer_judgement"] == raw.strip()
assert judge.agent_wrapper.reply.await_count == 1
@pytest.mark.asyncio
async def test_invalid_output_retries_once_and_recovers(judge):
judge.agent_wrapper.reply.side_effect = [
{"result": "mostly correct", "status": "completed", "error": None},
{"result": "yes", "status": "completed", "error": None},
]
response = await judge.execute()
assert response.success and response.answer == "yes"
assert response.metadata["raw_answer_judgement"] == "yes"
calls = judge.agent_wrapper.reply.await_args_list
assert len(calls) == 2 and calls[0] == calls[1]
@pytest.mark.asyncio
@pytest.mark.parametrize("raw", ["", "maybe", "yesterday", "correct"])
async def test_two_invalid_outputs_fail_without_a_score(judge, raw):
judge.agent_wrapper.reply.return_value = {"result": raw, "status": "completed", "error": None}
with pytest.raises(ValueError, match="invalid yes/no judgement after 2 attempts"):
await judge.execute()
assert judge.agent_wrapper.reply.await_count == 2
assert "answer_judgement" not in judge.context.response.metadata
@pytest.mark.asyncio
async def test_transport_errors_are_not_invalid_output_retries(judge):
judge.agent_wrapper.reply.side_effect = TimeoutError("provider")
with pytest.raises(TimeoutError):
await judge.execute()
assert judge.agent_wrapper.reply.await_count == 1
@pytest.mark.asyncio
@pytest.mark.parametrize("status", ["failed", "interrupted", "waiting"])
async def test_incomplete_replies_are_neither_scored_nor_retried(judge, status):
judge.agent_wrapper.reply.return_value = {"result": "yes", "status": status, "error": None}
with pytest.raises(RuntimeError, match=status):
await judge.execute()
assert judge.agent_wrapper.reply.await_count == 1
assert "answer_judgement" not in judge.context.response.metadata