Files
Jyotisha/tests/test_report_reader_wording_2104.py
ClaudeandClaude Opus 5.5 4153043e49
Independent Staging Quality Gate / validate-frontend (push) Successful in 5m47s
Independent Staging Quality Gate / validate-python (push) Successful in 7m40s
Independent Staging Quality Gate / publish (push) Successful in 3m30s
fix(report): yoga status 「检出组合」 instead of 「检测器检出,待核实」, the basis line budgets what readers see; 战死瑜伽 shown by its Sanskrit name; annual role headers, affliction words and the Mitigated status from batches 1–3 (BUG-2311, BUG-2312)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXp2U3BH1SxwAGyhhbe1
2026-11-24 13:51:24 +08:00

197 lines
11 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""BUG-2104: reader words for the leftovers found after BUG-2095.
Owner rule (2026-11-20): technique names stay; internal codes, raw status keys, English field
names in the Chinese edition and backstage lines are not shown to readers.
Charts are synthetic, or the repository's two public fixture charts.
"""
from __future__ import annotations
import re
import pytest
from scripts.pl9_language_terms import soften_lifespan_wording
from scripts.report_render.reader_keys import aspect_type_en, house_lord_text_en, reader_point_name
from scripts.report_render.upstream_sync_chapters import _domain_contract_section
from scripts.report_render.yoga_status_words import YOGA_STATUS_MAPPING, YOGA_STATUS_TEXT_EN, yoga_status_cell
from tests.public_chart_reports import PUBLIC_REPORT_CASES, public_chart_reports
# Raw status keys that have a reader word (Chinese edition: 已列出 / 本命 / 当前运行 / 背景 / 小运 /
# the yoga status texts). A table cell that is exactly one of these is a leaked key.
RAW_STATUS_WORDS = {
*YOGA_STATUS_MAPPING, "support_only_candidate", "not_available_yet", "not_returned",
"listed", "partial_verified", "native", "active", "background", "antardasha",
}
UNDERSCORED = re.compile(r"[A-Za-z0-9]+_[一-鿿A-Za-z]")
BARE_LOWERCASE = re.compile(r"[a-z]+")
MATRUNASA_ZH = "母亲不利瑜伽"
LIFESPAN_SENTENCE_ZH = "传统上与体质和恢复力有关,不用来推断寿命"
def _reader_text(markdown: str) -> str:
"""Reader text: code fences, code spans, link targets and bare URLs are skipped."""
text = re.sub(r"```.*?```", "", markdown, flags=re.S)
text = re.sub(r"`[^`\n]*`", "", text)
text = re.sub(r"\]\([^)]*\)", "]", text)
return re.sub(r"https?://\S+", "", text)
def _cells(line: str) -> list[str]:
return [cell.strip() for cell in line.strip().strip("|").split("|")]
def _tables(markdown: str):
"""(header cells, body rows) for every Markdown table."""
lines = markdown.splitlines()
for index in range(len(lines) - 1):
if lines[index].startswith("|") and re.match(r"^\|\s*:?-{3,}", lines[index + 1]):
body = []
for line in lines[index + 2:]:
if not line.startswith("|"):
break
body.append(_cells(line))
yield _cells(lines[index]), body
def _status_column(markdown: str, header_start: str) -> list[str]:
return [row[1] for header, body in _tables(markdown) if " | ".join(header).startswith(header_start) for row in body]
@pytest.mark.parametrize("case", PUBLIC_REPORT_CASES)
def test_english_yoga_status_column_prints_reader_words(case):
_packet, chinese, english = public_chart_reports(case)
english_states = _status_column(english, "Yoga candidate | Status")
chinese_states = _status_column(chinese, "瑜伽 | 状态")
assert english_states and len(english_states) == len(chinese_states)
assert not set(english_states) & set(YOGA_STATUS_MAPPING), sorted(set(english_states))
# BUG-2303: a Neecha Bhanga row now sits in the table (her rules decide it); its status is BUG-2280's
# 「有缓解」 / "Mitigated". 原值:只允许 YOGA_STATUS_TEXT_EN 的词。
from scripts.report_render.yoga_status_words import NEECHA_MITIGATED_TEXT
assert set(english_states) <= set(YOGA_STATUS_TEXT_EN.values()) | {NEECHA_MITIGATED_TEXT["en"]}
# Each English word is the counterpart of the Chinese text on the same row.
by_zh = {entry["text"]: YOGA_STATUS_TEXT_EN[key] for key, entry in YOGA_STATUS_MAPPING.items()}
by_zh[NEECHA_MITIGATED_TEXT["zh"]] = NEECHA_MITIGATED_TEXT["en"]
assert [by_zh.get(state) for state in chinese_states] == english_states
def test_yoga_status_cell_keeps_chinese_and_names_every_key_in_english():
assert set(YOGA_STATUS_TEXT_EN) == set(YOGA_STATUS_MAPPING)
assert yoga_status_cell("candidate", "命中候选规则,尚未完整确认", "zh") == "命中候选规则,尚未完整确认"
assert yoga_status_cell("candidate", "命中候选规则,尚未完整确认", "en") == "Rule matched, not fully confirmed"
# BUG-2311 原值:「检测器检出,待核实」/ "Detected, to be verified"。
assert yoga_status_cell("computed", "检出组合", "en") == "Combination detected"
assert yoga_status_cell("blocked", "当前无法确认,缺:卡上没有这条格局的状态记录", "en") == "Cannot be confirmed yet"
@pytest.mark.parametrize("case", PUBLIC_REPORT_CASES)
def test_mudda_rows_end_with_reader_words_in_both_editions(case):
_packet, chinese, english = public_chart_reports(case)
en_rows = [row for header, body in _tables(english) if header[:2] == ["Balance profile", "Lord"] for row in body]
zh_rows = [row for header, body in _tables(chinese) if header[:2] == ["余额口径", "主星"] for row in body]
assert en_rows and zh_rows
en_status = {row[-1] for row in en_rows}
assert "Listed" in en_status and not en_status & RAW_STATUS_WORDS, sorted(en_status)
assert "已列出" in {row[-1] for row in zh_rows}
# Sub-period rows name their level instead of the key `antardasha`.
assert {row[0] for row in en_rows} >= {"Antardasha"} and {row[0] for row in zh_rows} >= {"小运"}
@pytest.mark.parametrize("case", PUBLIC_REPORT_CASES)
def test_english_table_cells_carry_no_raw_status_keys(case):
_packet, _chinese, english = public_chart_reports(case)
leaked = sorted({cell for _header, body in _tables(_reader_text(english)) for row in body for cell in row
if cell in RAW_STATUS_WORDS})
assert leaked == []
@pytest.mark.parametrize("case", PUBLIC_REPORT_CASES)
def test_chinese_table_headers_have_no_lowercase_english_words(case):
_packet, chinese, english = public_chart_reports(case)
zh_bad = sorted({cell for header, _body in _tables(_reader_text(chinese)) for cell in header
if BARE_LOWERCASE.fullmatch(cell)})
assert zh_bad == []
# The English edition capitalises the same generic headers.
en_bad = sorted({cell for header, _body in _tables(_reader_text(english)) for cell in header
if cell in {"name", "label", "degree", "role", "strength", "main", "sub", "boundary", "planet", "field"}})
assert en_bad == []
assert "| 行星 | 角色 | 数值 | 星座 | 宫位 |" in chinese and "| Planet | Role | Value | Sign | House |" in english
assert "| 主段 | 子段 | 边界 | 边界状态 |" in chinese
@pytest.mark.parametrize("case", PUBLIC_REPORT_CASES)
def test_kp_basis_lines_use_reader_words(case):
_packet, chinese, english = public_chart_reports(case)
assert "- 宫位依据:按实际宫头度数" in chinese and "- 落宫依据:宫头到下一宫头" in chinese
assert "basis:" not in chinese and "basis:" not in chinese
assert "- House basis: Explicit cusp degrees" in english
assert "- House occupancy basis: Cusp to next cusp" in english
@pytest.mark.parametrize("case", PUBLIC_REPORT_CASES)
def test_no_underscored_keys_outside_code_in_either_edition(case):
_packet, chinese, english = public_chart_reports(case)
for language, markdown in (("zh", chinese), ("en", english)):
hits = sorted({match for line in _reader_text(markdown).splitlines() for match in UNDERSCORED.findall(line)})
assert hits == [], (case, language, hits[:20])
assert "| Arudha 上升(AL) |" in chinese and "| A10(Karma Pada) |" in chinese
assert "| Arudha Lagna (AL) |" in english and "| A10 (Karma Pada) |" in english
def test_point_aspect_and_house_lord_keys_read_as_names():
assert reader_point_name("Arudha_Lagna", "zh") == "Arudha 上升(AL)"
assert reader_point_name("Upapada_Lagna", "en") == "Upapada Lagna (UL)"
assert reader_point_name("A10_Karma_Pada", "zh") == "A10(Karma Pada)"
assert reader_point_name("Artha_Praharaka", "en") == "Artha Praharaka"
assert reader_point_name("D2_Hora", "zh") == "D2 Hora"
assert reader_point_name("Kaala", "en") == "Kaala"
assert aspect_type_en("Mars_aspect_8") == "Mars special 8th-house aspect"
assert aspect_type_en("opposition") == "opposition"
assert house_lord_text_en("H12_Lord(Sun) in H6") == "12th lord Sun in H6"
@pytest.mark.parametrize("case", PUBLIC_REPORT_CASES)
def test_rectification_gate_line_is_a_plain_reader_limit(case):
_packet, chinese, english = public_chart_reports(case)
for text in ("labels frozen", "decision power", "标签先冻结", "决策权", "全局门"):
assert text not in chinese and text not in english
assert "- 全局边界:每个领域至少要有 2 个相互独立的支持层;D60 不用来下结论;D40/D45 只用于研究性的交叉对照。" in chinese
assert ("- Global boundary: each domain needs at least 2 independent supporting layers; D60 is never used "
"to decide; D40/D45 are read for research cross-checks only.") in english
def test_gate_line_prints_only_the_limits_it_has():
contract = {"domains": [{"domain_id": "career", "label": "事业"}], "global_rules": {"minimum_independent_support_layers": 3}}
zh = "\n".join(_domain_contract_section(contract, "zh"))
assert "- 全局边界:每个领域至少要有 3 个相互独立的支持层。" in zh.splitlines()
contract["global_rules"] = {"freeze_event_labels_before_candidate_comparison": True}
assert "- 全局边界" not in "\n".join(_domain_contract_section(contract, "zh"))
@pytest.mark.parametrize("case", PUBLIC_REPORT_CASES)
def test_matrunasa_keeps_its_own_effect_in_chinese(case):
_packet, chinese, _english = public_chart_reports(case)
rows = [row for header, body in _tables(chinese) if header[:2] == ["瑜伽", "状态"] for row in body
if row[0] == MATRUNASA_ZH]
if not rows:
pytest.skip("Matrunasa Yoga is not a candidate in this chart")
for row in rows:
assert row[-1] != LIFESPAN_SENTENCE_ZH
# 原值:作用格以「母亲相关的结构特征」开头,带「不作母亲健康或寿命判断」
# 新值:取法待核(她的 method_review: pending,BUG-2299),作用格只写闸门的句子
# 原因:BUG-2300 被挡下的传统作用不回到读者文字
# BUG-2304 原值「取法尚待核定,保留候选结构,不据此写传统作用。」/ 新值:不写待核的一句 / 原因:负责人 BUG-2280
assert row[-1] == "这一条只列出结构,不按传统说法下结论。"
def test_lifespan_softening_applies_only_to_lifespan_claims():
denial = "母亲相关的结构特征(月亮受凶星影响),只作参考,不作母亲健康或寿命判断"
assert soften_lifespan_wording(denial, "zh") == "母亲相关的结构特征(月亮受凶星影响),不作母亲健康或寿命判断"
assert soften_lifespan_wording("长寿;健康良好", "zh") == LIFESPAN_SENTENCE_ZH
assert soften_lifespan_wording("健康隐患;寿命挑战", "zh") == LIFESPAN_SENTENCE_ZH
assert soften_lifespan_wording(LIFESPAN_SENTENCE_ZH, "zh") == LIFESPAN_SENTENCE_ZH
assert soften_lifespan_wording("Longevity; Good health", "en").startswith("Traditionally associated")