"""Chinese appendix facts for issue #91 section A. Dosha, friendship, and yoga cells come from structured fields. The Chinese appendix is not an English render with the short-word sanitizer applied. """ from __future__ import annotations from scripts.pl9_full_data_export import ( _render_pl9_ai_density_raw_data_markdown_zh, render_full_data_markdown, ) from scripts.report_render.appendix_language import ( chinese_prose_gates, dosha_row, friendship_table, ) from tests.test_report_full_data_fix import _packet def test_dosha_rows_use_structured_fields() -> None: # 原值: 缺字段印「未判定」/ "Not determined" # 新值: 「未判断」/ "Not assessed",摘要写明缺什么 # 原因: BUG-2089(占星师 2026-11-20 问题 3)附录与逐项页同一套三态:检出 / 按本规则未检出 / 未判断 missing = dosha_row("mangal_dosha", {}, "zh") assert missing is not None assert missing[1] == "未判断" and "缺少火星的宫位资料" in missing[2] assert dosha_row("mangal_dosha", {}, "en")[1] == "Not assessed" # 原值: {"has_dosha": False} 印「无」/ "No",摘要「火星不在煞宫」 # 新值: 没有火星宫位时是「未判断」;有宫位且规则未命中才是「按本规则未检出」,摘要写火星实际所在宫 # 原因: BUG-2089 检测器在缺输入时也返回 has_dosha=False,未知不能印成「无」 assert dosha_row("mangal_dosha", {"has_dosha": False}, "zh")[1] == "未判断" clear = dosha_row("mangal_dosha", {"has_dosha": False, "mars_house": 3}, "zh") assert clear is not None and clear[1] == "按本规则未检出" assert "火星在第 3 宫,不在本规则所列的宫位" in clear[2] english = dosha_row("mangal_dosha", {"has_dosha": False, "mars_house": 3}, "en") assert english is not None and english[1] == "Not detected by this rule" assert "not one of the houses this rule lists" in english[2] partial = dosha_row("kaal_sarp_dosha", { "has_dosha": True, "type": "partial", "planets_in_axis": ["Sun", "Moon", "Mars", "Mercury", "Jupiter"], "planets_outside": ["Venus", "Saturn"], "rahu_house": 1, "ketu_house": 7, }, "zh") assert partial is not None # 原值: 「部分」 # 新值: 「按本规则检出(部分型,宫位近似筛查)」 # 原因: BUG-2089 时蛇煞是宫位近似筛查,不能只印「部分」,更不能称确认 # 原值: 「按本规则检出(部分型,宫位近似筛查)」 # 新值: 「近似筛查发现候选结构(部分型)」 # 原因: BUG-2110, the astrologer's 11-21 review: a structure found by approximate screening is a candidate, never 「检出」 assert partial[1] == "近似筛查发现候选结构(部分型)" assert "7 颗中 5 颗" in partial[2] # BUG-2019(占星师 2026-11-19 第 16 条): 原值 北交点 / 南交点(附录里是 北交点/罗睺、南交点/计都);新值 罗睺 / 计都。 assert "罗睺(北交点)在第 1 宫,计都(南交点)在第 7 宫" in partial[2] partial_en = dosha_row("kaal_sarp_dosha", { "has_dosha": True, "type": "partial", "planets_in_axis": ["Sun", "Moon", "Mars", "Mercury", "Jupiter"], "planets_outside": ["Venus", "Saturn"], "rahu_house": 1, "ketu_house": 7, }, "en") assert partial_en is not None and "5 of 7" in partial_en[2] # 原值: assert "approximate house-based screening" in partial_en[1] # 新值: the English cell reads as a candidate found by approximate screening # 原因: BUG-2110, same review as the Chinese cell above assert "Candidate structure found by approximate screening" in partial_en[1] def test_friendship_reads_rows_not_snapshot_keys() -> None: snapshot = { "status": "parameter_sensitive", "rows": [ { "planet": "Sun", "natural": {"friends": ["Moon", "Mars"], "enemies": ["Venus"], "neutral": ["Mercury"]}, "temporary": {"friends": ["Jupiter"], "enemies": ["Saturn"]}, "compound": {"great_friends": ["Moon"], "friends": [], "neutral": [], "enemies": [], "great_enemies": ["Saturn"]}, } ], } headers, rows = friendship_table(snapshot, "zh") assert headers[0] == "行星" assert headers[-1] == "复合关系" assert rows[0][0] == "太阳" assert "月亮" in rows[0][1] assert "极友:月亮" in rows[0][-1] assert "GREAT_FRIEND" not in rows[0][-1] _, english_rows = friendship_table(snapshot, "en") assert english_rows[0][0] == "Sun" assert "Great friend: Moon" in english_rows[0][-1] def test_chinese_appendix_is_not_back_translated() -> None: packet = _packet("zh") packet["worksheets"]["strengths_and_scores"]["planetary_friendship"] = { "rows": [{ "planet": "Sun", "natural": {"friends": ["Moon"], "enemies": [], "neutral": ["Mars"]}, "temporary": {"friends": ["Jupiter"], "enemies": ["Venus"]}, "compound": {"great_friends": ["Moon"], "friends": [], "neutral": [], "enemies": [], "great_enemies": []}, }], } appendix = _render_pl9_ai_density_raw_data_markdown_zh(packet) assert "## 行星友敌关系矩阵" in appendix assert "## Planetary Friendship Matrix" not in appendix assert "Natural friends" not in appendix assert "极友:月亮" in appendix assert "Aries" not in appendix assert "白羊座" in appendix assert "第 1 宫宫主" in appendix assert "house " not in appendix gates = chinese_prose_gates(appendix) assert gates == {"english_signs": 0, "han_function_glue": 0} rendered = render_full_data_markdown(packet) rendered_gates = chinese_prose_gates(rendered) assert rendered_gates["english_signs"] == 0 assert rendered_gates["han_function_glue"] == 0 assert "Raja Yoga" not in rendered assert "blocked" not in rendered.lower() def test_chinese_prose_gates_catch_sign_names_and_glue() -> None: sample = "```jyotish-chart\nAries\n```\n正文 Aries。火星 in 12,in ),, :" gates = chinese_prose_gates(sample) assert gates["english_signs"] == 1 assert gates["han_function_glue"] == 3