Forward judge_language through score, async, and session endpoints

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
wangwei
2026-07-01 18:02:13 +08:00
co-authored by Copilot
parent bd5658c3ac
commit 31fe71eb94
4 changed files with 52 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
"""Tests that score endpoints forward the resolved judge_language to the scorer."""
from unittest.mock import MagicMock, patch
from fastapi.testclient import TestClient
import webapp.api.score as score_mod
from webapp.server import create_app
def _client():
return TestClient(create_app())
def test_score_route_forwards_judge_language(monkeypatch):
"""A request with judge_language='zh' reaches inline_scorer.score."""
captured: dict = {}
def fake_score(**kwargs):
captured.update(kwargs)
return {"faithfulness": 0.9}
monkeypatch.setattr(score_mod.inline_scorer, "score", fake_score)
resp = _client().post("/api/score", json={
"question": "q", "answer": "a", "contexts": "c",
"ground_truth": "g", "metrics": ["faithfulness"], "judge_language": "zh",
})
assert resp.status_code == 200
assert captured.get("judge_language") == "zh"
def test_score_route_defaults_language_to_en(monkeypatch):
"""Omitting judge_language falls back to settings default ('en')."""
captured: dict = {}
def fake_score(**kwargs):
captured.update(kwargs)
return {"faithfulness": 0.9}
monkeypatch.setattr(score_mod.inline_scorer, "score", fake_score)
resp = _client().post("/api/score", json={
"question": "q", "answer": "a", "contexts": "c",
"ground_truth": "g", "metrics": ["faithfulness"],
})
assert resp.status_code == 200
assert captured.get("judge_language") == "en"