"""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"