"""步骤 C:QA 第 11 维度 language_consistency 测试。 评审 R1:不可验证(expected_language 为空/auto)→ 维度满分 1.0 通过,不拉低总分, 使既有 test_eval_scorer / test_phase5_scorer 的 total_score==1.0 断言继续成立。 """ from __future__ import annotations from genesis.data_models import ( CellValue, ExcelTable, ParsedTemplate, Provenance, SheetType, StructuredSource, ) from genesis.eval.scorer import ChapterArtifact, ChapterScorer, EvalReport def _dim(report: EvalReport, name: str): for d in report.dimensions: if d.name == name: return d raise AssertionError(f"维度未找到: {name}") def _source() -> StructuredSource: cell = CellValue( value="登録", provenance=Provenance(file_name="f.xlsx", sheet_name="機能一覧", row=3, column="C", column_header="x"), ) table = ExcelTable( name="機能一覧", detected_type=SheetType.FUNCTION, extraction_method="structured", headers=["v"], rows=[{"v": cell}], ) return StructuredSource( tables=[table], template=ParsedTemplate(file_name="t.docx", sections=[], placeholders={}, styles={}), rule_docs=[], image_analyses=[], existing_system=None, comments=[], ) def test_language_dim_unverifiable_is_full_score(): """expected_language 为空(auto/不可验证)→ 维度满分通过,不拉低总分。""" src = _source() artifact = ChapterArtifact( chapter_id="ch3", text="本機能は注文処理を行う画面である。", source_uris=[], template_sections_expected=["ch3"], expected_language="", ) report = ChapterScorer().score([artifact], src) dim = _dim(report, "language_consistency") assert dim.score == 1.0 assert dim.passed is True # 既有总分断言仍成立(全部确定性维度满分) assert report.total_score == 1.0 def test_language_dim_ja_expected_but_chinese_fails(): src = _source() artifact = ChapterArtifact( chapter_id="ch3", text="这是一段纯中文的章节正文内容,应当判定为语言违规。", source_uris=[], template_sections_expected=["ch3"], expected_language="ja", ) report = ChapterScorer().score([artifact], src) dim = _dim(report, "language_consistency") assert dim.score == 0.0 assert dim.passed is False assert report.total_score < 1.0 def test_language_dim_zh_expected_japanese_fails(): src = _source() artifact = ChapterArtifact( chapter_id="ch3", text="本機能は注文処理を行う画面であり、詳細は以下の通り。", source_uris=[], template_sections_expected=["ch3"], expected_language="zh", ) report = ChapterScorer().score([artifact], src) dim = _dim(report, "language_consistency") assert dim.score == 0.0 def test_language_dim_threshold_in_defaults(): assert ChapterScorer().thresholds["language_consistency"] == 1.0 def test_dimension_count_increases_by_one(): src = _source() artifact = ChapterArtifact( chapter_id="ch3", text="正常内容", source_uris=[], template_sections_expected=["ch3"], ) before = len(ChapterScorer(thresholds={}, llm_evaluators={}).score([artifact], src).dimensions) # 默认 scorer 含 language_consistency;对比一个不含该维度的基线不可行, # 此处仅断言维度中包含 language_consistency 名称 report = ChapterScorer().score([artifact], src) assert any(d.name == "language_consistency" for d in report.dimensions)