"""Integration test: committed zh cache files load cleanly onto real RAGAS metric instances.""" from pathlib import Path from rag_eval.metrics.judge_prompts import CACHE_ROOT, METRIC_PROMPT_ATTRS def test_zh_cache_files_all_present(): """All expected zh cache files are committed and present on disk.""" zh_dir = CACHE_ROOT / "zh" for metric, attrs in METRIC_PROMPT_ATTRS.items(): for attr in attrs: path = zh_dir / f"{metric}__{attr}.json" assert path.exists(), f"Missing committed cache: {path}" def test_zh_cache_loads_onto_real_metrics(): """Localize all registry metrics to zh — zero skips, zero errors.""" from unittest.mock import MagicMock from ragas.llms.base import InstructorBaseRagasLLM from ragas.embeddings.base import BaseRagasEmbedding from rag_eval.metrics.factory import build_metric_registry from rag_eval.metrics.judge_prompts import localize_pipeline_prompts, reset_cache reset_cache() llm = MagicMock(spec=InstructorBaseRagasLLM) emb = MagicMock(spec=BaseRagasEmbedding) registry = build_metric_registry(llm, emb) report = localize_pipeline_prompts(registry, "zh") expected_count = sum(len(attrs) for attrs in METRIC_PROMPT_ATTRS.values()) assert len(report.applied) == expected_count, ( f"Expected {expected_count} applied, got {len(report.applied)}; " f"skipped={report.skipped}, warnings={report.warnings}" ) assert not report.skipped, f"Unexpected skips: {report.skipped}" def test_zh_cache_instructions_are_chinese(): """After localization, faithfulness instruction starts with Chinese characters.""" from unittest.mock import MagicMock from ragas.llms.base import InstructorBaseRagasLLM from ragas.embeddings.base import BaseRagasEmbedding from rag_eval.metrics.factory import build_metric_registry from rag_eval.metrics.judge_prompts import localize_pipeline_prompts, reset_cache reset_cache() llm = MagicMock(spec=InstructorBaseRagasLLM) emb = MagicMock(spec=BaseRagasEmbedding) registry = build_metric_registry(llm, emb) localize_pipeline_prompts(registry, "zh") instr = registry["faithfulness"].statement_generator_prompt.instruction # Chinese instruction should contain at least one CJK character. has_chinese = any("\u4e00" <= ch <= "\u9fff" for ch in instr) assert has_chinese, f"Instruction does not contain Chinese: {instr[:60]}"