"""BUG-2089: report batch 2 — information that is computed but was not delivered. After the astrologer's 2026-11-20 reply (B9, answers 3, 4, 12, A6) and two owner decisions of the same day: 1. Sade Sati prints every dated segment, with retrograde re-entries and the settings. 2. A Neecha Bhanga row has two roles: the fallen planet and the cancellation witnesses. 3. The birth Tithi lord is in the report packet; dignity and cancellation stay apart. 4. The remaining dosha summaries use the three states of the dosha pages. 5. The functional benefic / malefic table shows reader words, not stored keys. 7. Yoga explanation pages: one page per instance (name + object planets). 8. Candidate table: rules that hit the same fact share one row and both names stay. Charts are synthetic, or the repository's two public fixture charts. """ from __future__ import annotations import re import pytest from scripts.pl9_interpretation_packs import build_dosha_remedy_pack, build_yoga_interpretation_pack, dosha_summary_cells from scripts.pl9_reader_export import _sade_sati_summary_row from scripts.report_render.appendix_language import dosha_row from scripts.report_render.functional_layer_table import functional_layer_rows from scripts.report_render.neecha_witness import ( attach_neecha_witness_roles, neecha_participant_row, neecha_roles, participant_cells, ) from scripts.report_render.sade_sati_intervals import build_sade_sati_intervals, sade_sati_interval_lines from scripts.report_render.tithi_lord_report import build_tithi_lord, tithi_lord_lines from scripts.report_render.yoga_status_words import ( _engine_variant_keys, _report_yoga_rows, join_same_fact, report_yoga_table, ) from scripts.yogas_doshas import calc_kaal_sarp_dosha, calc_mangal_dosha, calc_pitra_dosha from tests.public_chart_reports import PUBLIC_REPORT_CASES, public_chart_reports FIELD_NAME = re.compile(r"\b[a-z]+_[a-z_]+\b") def _planets(**houses: tuple[int, str]) -> dict: return {name: {"house": house, "sign": sign} for name, (house, sign) in houses.items()} def _chart_packet(planets: dict, **birth) -> dict: return { "birth_info": {"date": "1960-01-01", "tz": "UTC+5.5", "ayanamsa_name": "lahiri", "node_mode": "mean", **birth}, "calculation_profile": {"ayanamsa": "lahiri", "node_mode": "mean", "position_mode": "apparent"}, "worksheets": { "d1_rasi_bhava": {"planets": planets, "ascendant": {"sign": "Aries"}}, "advanced_systems": {"yogas_doshas": {"sade_sati": {"is_active": False, "moon_sign": "Pisces"}}}, }, } # --- 1. Sade Sati dated intervals --------------------------------------------- def test_sade_sati_lists_every_dated_segment_with_retrograde_reentries() -> None: intervals = build_sade_sati_intervals(_chart_packet(_planets(Moon=(12, "Pisces")))) assert intervals["status"] == "computed" segments = intervals["segments"] assert {item["phase"] for item in segments} == {"rising", "peak", "setting"} # Saturn's retrograde return gives several segments for one phase of one round. per_phase: dict[tuple, list[dict]] = {} for item in segments: per_phase.setdefault((item["round"], item["phase"]), []).append(item) repeated = [rows for rows in per_phase.values() if len(rows) > 1] assert repeated, "no phase has more than one segment" for rows in per_phase.values(): assert [item["entry"] for item in rows] == ["first"] + ["re_entry"] * (len(rows) - 1) # Every segment carries both boundaries, in time order, to the minute unless it is the scan edge. assert [item["start"] for item in segments] == sorted(item["start"] for item in segments) for item in segments: assert item["start"] < item["end"] if not item["start_is_scan_edge"]: assert re.fullmatch(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}", item["start"]) assert intervals["parameters"]["ayanamsa"] == "lahiri" assert intervals["parameters"]["chart_node_mode"] == "mean" assert intervals["parameters"]["clock_utc_offset_hours"] == 5.5 zh, en = ("\n".join(sade_sati_interval_lines(intervals, language)) for language in ("zh", "en")) assert zh.count("\n| 第 ") == len(segments) and len(re.findall(r"(?m)^\| \d+ \| ", en)) == len(segments) assert "逆行回返后再次进入" in zh and "Re-entry after a retrograde return" in en assert "岁差:Lahiri" in zh and "UTC+5:30" in zh and "平交点" in zh and "视位置" in zh assert "Ayanamsa: Lahiri" in en and "UTC+5:30" in en and "mean node" in en # 原值:英文词检查放过 Swiss Ephemeris / Moshier # 新值:不再放过,星历说明只写「高精度星历文件」或「内置近似星历」 # 原因:BUG-2115 负责人 2026-11-21:报告里不给读者出现库名 assert not FIELD_NAME.search(zh) and not re.search(r"[A-Za-z]{3,}", zh.replace("Sade Sati", "").replace("Lahiri", "").replace("UTC", "")) def test_sade_sati_without_a_time_zone_says_not_computed_and_invents_nothing() -> None: intervals = build_sade_sati_intervals(_chart_packet(_planets(Moon=(12, "Pisces")), tz=None)) assert intervals == {"status": "blocked", "missing": ["timezone_offset"], "segments": []} for language, words in (("zh", "没有算出各段起止日期"), ("en", "were not computed")): text = "\n".join(sade_sati_interval_lines(intervals, language)) assert words in text and not re.search(r"\d{4}-\d{2}-\d{2}", text) # --- 2. Neecha Bhanga witnesses ------------------------------------------------ NEECHA_ROW = { "name": "Neecha Bhanga", "category": "neecha_bhanga", "planets": ["Jupiter"], "combination": "木星落陷于摩羯座;成立条件:落陷星座主星土星在上升起第1宫(角宫)", "combination_en": "Jupiter debilitated in Capricorn; conditions met: dispositor Saturn in house 1 from the Lagna (kendra)", "formation_evidence": {"cancellation_reasons": [ {"condition": "dispositor_kendra_from_lagna", "planet": "Saturn", "reference": "Lagna", "relative_house": 1, "self_reference": False}, {"condition": "dispositor_kendra_from_moon", "planet": "Saturn", "reference": "Moon", "relative_house": 4, "self_reference": False}, {"condition": "exaltation_sign_lord_kendra_from_moon", "planet": "Moon", "reference": "Moon", "relative_house": 1, "self_reference": True}, ]}, } def _neecha_page(active: set[str], language: str) -> dict: pack = build_yoga_interpretation_pack({"detected_yogas": [NEECHA_ROW]}, {}, active, language=language) assert len(pack["pages"]) == 1 return pack["pages"][0] def test_neecha_bhanga_has_a_fallen_planet_and_witnesses_as_separate_roles() -> None: roles = neecha_roles(NEECHA_ROW) assert roles["fallen"] == ["Jupiter"] # Saturn meets two conditions and is still one planet; the Moon is a self-reference. assert roles["witnesses"] == ["Saturn", "Moon"] assert roles["independent_witnesses"] == ["Saturn"] and roles["self_reference_witnesses"] == ["Moon"] assert neecha_roles({"name": "Gajakesari Yoga", "planets": ["Moon", "Jupiter"]}) is None cells = participant_cells(NEECHA_ROW, ["Rahu", "Saturn", "Mercury"], "zh") assert cells["witness_cell"] == "土星;月亮(自我参照,不作独立印证)" and cells["witness_overlap_cell"] == "土星" assert cells["witness_status"] == "当前周期关联到该化解条件的见证星:土星" assert participant_cells(NEECHA_ROW, ["Rahu"], "en")["witness_overlap_cell"] == "None" # The participants table (rendered by the other branch) gets both roles in two cells. assert neecha_participant_row(NEECHA_ROW, "木星", "未与当前主星重叠", ["Saturn"], "zh") == ( "木星(落陷星);化解条件的见证星:土星;月亮(自我参照,不作独立印证)", "未与当前主星重叠;当前周期关联到该化解条件的见证星:土星", ) assert neecha_participant_row({"name": "Gajakesari Yoga", "planets": ["Moon"]}, "Moon", "x", ["Moon"], "en") == ("Moon", "x") packet = {"worksheets": {"advanced_systems": {"yoga": {"detected_yogas": [dict(NEECHA_ROW)]}}}} assert attach_neecha_witness_roles(packet) == 1 row = packet["worksheets"]["advanced_systems"]["yoga"]["detected_yogas"][0] assert row["planets"] == ["Jupiter"] and row["cancellation_witnesses"] == ["Saturn", "Moon"] assert row["self_reference_witnesses"] == ["Moon"] def test_current_lord_that_is_a_witness_is_a_link_and_never_an_activation() -> None: zh, en = _neecha_page({"Saturn"}, "zh")["sections"], _neecha_page({"Saturn"}, "en")["sections"] assert "当前周期关联到该化解条件的见证星:土星" in zh["activation"] assert "The current period is linked to a witness of this cancellation condition: Saturn" in en["activation"] assert "落陷星:木星。化解条件的见证星:土星;月亮(自我参照,不作独立印证)" in zh["roles"] assert "Fallen planet: Jupiter. Witnesses of the cancellation conditions: Saturn; Moon (self-reference, not independent support)" in en["roles"] for sections in (zh, en): text = " ".join(sections.values()) assert not re.search(r"激活|兑现|activated|delivered", text) # A self-reference witness that is the current lord is recorded, not counted. moon = _neecha_page({"Moon"}, "zh")["sections"]["activation"] assert "自我参照" in moon and "不作独立印证" in moon and "关联到该化解条件的见证星" not in moon # The fallen planet keeps its own overlap line; neither role is confused with the other. assert "当前大运重叠(落陷星):木星" in _neecha_page({"Jupiter"}, "zh")["sections"]["activation"] assert "没有与落陷星或见证星直接重叠" in _neecha_page({"Venus"}, "zh")["sections"]["activation"] # --- 3. Tithi lord ------------------------------------------------------------- def _tithi_packet(sun: float, moon: float, **planets: dict) -> dict: rows = {"Sun": {"lon": sun, "sign": "Taurus", "house": 2}, "Moon": {"lon": moon, "sign": "Sagittarius", "house": 9}, **planets} return {"worksheets": {"d1_rasi_bhava": {"planets": rows}}} def test_full_moon_and_new_moon_have_different_tithi_lords() -> None: full = build_tithi_lord(_tithi_packet(10.0, 185.0)) new = build_tithi_lord(_tithi_packet(10.0, 5.0)) assert (full["tithi_number"], full["paksha"], full["name"], full["lord"]) == (15, "Shukla", "Purnima", "Saturn") assert (new["tithi_number"], new["paksha"], new["name"], new["lord"]) == (30, "Krishna", "Amavasya", "Rahu") assert full["source_profile"] == new["source_profile"] == "pvr_integrated_approach_table_3" # No position for the lord: the dignity stays unknown and nothing is assessed. assert full["lord_original_dignity"] is None and full["cancellation"] == {"status": "not_assessed"} zh = "\n".join(tithi_lord_lines(full, "zh")) assert "| 主星 | 土星 |" in zh and "星盘没有给出这颗星的尊贵状态" in zh and "未判断:缺少主星的星座位置" in zh assert "不是 Tithi 之神,也不是月亮所在星宿的主星" in zh assert "| 名称 | 满月日 |" in zh and "| Name | Amavasya |" in "\n".join(tithi_lord_lines(new, "en")) blocked = build_tithi_lord({"worksheets": {"d1_rasi_bhava": {"planets": {"Sun": {"sign": "Aries"}}}}}) assert blocked == {"status": "blocked", "missing": ["birth_tithi"]} assert "没有算出" in "\n".join(tithi_lord_lines(blocked, "zh")) def test_tithi_lord_cancellation_never_overwrites_the_original_dignity() -> None: # Full Moon → lord Saturn, debilitated in Aries; its dispositor Mars is in a kendra from the Lagna. packet = _tithi_packet( 10.0, 185.0, Saturn={"sign": "Aries", "house": 1, "status": "落陷(Debilitated)"}, Mars={"sign": "Cancer", "house": 4}, ) module = build_tithi_lord(packet) assert module["lord"] == "Saturn" and module["lord_original_dignity"] == "落陷(Debilitated)" assert module["cancellation"]["status"] == "conditions_met" assert [item["planet"] for item in module["cancellation"]["conditions"]] == ["Mars"] assert "见证星:火星。" in "\n".join(tithi_lord_lines(module, "zh")) for language, dignity_row, cancel_words in ( ("zh", "| 主星的原始尊贵 | 落陷 |", "原始尊贵仍是落陷,化解条件不改写它"), ("en", "| Lord's original dignity | Debilitated |", "The original dignity is still debilitated"), ): text = "\n".join(tithi_lord_lines(module, language)) assert dignity_row in text and cancel_words in text # Debilitated with no witness: said so, still two separate fields. alone = build_tithi_lord(_tithi_packet(10.0, 185.0, Saturn={"sign": "Aries", "house": 2, "status": "落陷(Debilitated)"}, Mars={"sign": "Taurus", "house": 2})) assert alone["cancellation"]["status"] == "none_met" and alone["lord_original_dignity"] == "落陷(Debilitated)" # Not debilitated: the cancellation field says it does not apply. assert build_tithi_lord(_tithi_packet(10.0, 185.0, Saturn={"sign": "Libra", "house": 7, "status": "入旺(Exalted)"}))["cancellation"] == {"status": "not_applicable"} # --- 4. Dosha summaries -------------------------------------------------------- DETECTED = _planets(Sun=(5, "Leo"), Moon=(2, "Taurus"), Mars=(7, "Libra"), Mercury=(5, "Leo"), Jupiter=(3, "Gemini"), Venus=(4, "Cancer"), Saturn=(6, "Virgo"), Rahu=(1, "Aries"), Ketu=(7, "Libra")) CLEAR = _planets(Sun=(9, "Sagittarius"), Moon=(2, "Taurus"), Mars=(3, "Gemini"), Mercury=(9, "Sagittarius"), Jupiter=(11, "Aquarius"), Venus=(10, "Capricorn"), Saturn=(5, "Leo"), Rahu=(12, "Pisces"), Ketu=(6, "Virgo")) def _detector(planets: dict) -> dict: return { "mangal_dosha": calc_mangal_dosha(planets, planets.get("Mars", {}).get("house", 0)), "kaal_sarp_dosha": calc_kaal_sarp_dosha(planets), "pitra_dosha": calc_pitra_dosha(planets, 0), } def test_dosha_summary_rows_have_three_states_and_no_field_names() -> None: detected, clear = _detector(DETECTED), _detector(CLEAR) for key in ("mangal_dosha", "kaal_sarp_dosha", "pitra_dosha"): for language, hit, miss, unknown in (("zh", "按本规则检出", "按本规则未检出", "未判断"), ("en", "Detected by this rule", "Not detected by this rule", "Not assessed")): # 原值: 三种 Dosha 的检出行都以「按本规则检出」开头 # 新值: 时蛇煞写「近似筛查发现候选结构」/ "Candidate structure found by approximate screening" # 原因: BUG-2110 占星师 2026-11-21:宫位近似筛查只发现候选结构 if key == "kaal_sarp_dosha": hit = "近似筛查发现候选结构" if language == "zh" else "Candidate structure found by approximate screening" assert dosha_row(key, detected[key], language, DETECTED)[1].startswith(hit) assert dosha_row(key, clear[key], language, CLEAR)[1].startswith(miss) # An unknown is never a "no": a row without its inputs is not assessed, and says what is missing. for empty in ({}, {"has_dosha": False}, None): row = dosha_row(key, empty, language) assert row[1] == unknown and ("缺少" in row[2] or "missing" in row[2] or "incomplete" in row[2]) for item in (detected[key], clear[key], {}): cells = dosha_summary_cells(key, item, CLEAR if item is clear[key] else None, language) text = " ".join(cells.values()) assert not FIELD_NAME.search(text.replace("not_detected", "").replace("not_assessed", "")), text assert "这段时期" not in text and "这段时间" not in text and "this period" not in text.lower() # A row that is not detected or not assessed carries no interpretation. # 原值: state != "detected" 时 note 为「—」 # 新值: 候选结构(candidate)也带使用限制 # 原因: BUG-2110 时蛇煞候选结构保留「只按宫位筛查」等限制说明 if cells["state"] not in ("detected", "candidate"): assert cells["note"] == "—" kaal_zh, kaal_en = dosha_row("kaal_sarp_dosha", detected["kaal_sarp_dosha"], "zh"), dosha_row("kaal_sarp_dosha", detected["kaal_sarp_dosha"], "en") # 原值: assert "宫位近似筛查" in kaal_zh[1] and "approximate house-based screening" in kaal_en[1] # 新值: the Kaal Sarp cell reads as a candidate found by approximate screening, never as detected # 原因: BUG-2110, the astrologer's 11-21 review: 「近似筛查发现候选结构」, not listed as formed assert "近似筛查发现候选结构" in kaal_zh[1] and "Candidate structure found by approximate screening" in kaal_en[1] assert "确认" not in "".join(kaal_zh) and "confirm" not in " ".join(kaal_en).lower() assert "宫位近似筛查" in dosha_row("kaal_sarp_dosha", clear["kaal_sarp_dosha"], "zh", CLEAR)[1] assert "不等于婚姻失败" in dosha_row("mangal_dosha", detected["mangal_dosha"], "zh", DETECTED)[2] assert "家庭" not in dosha_row("pitra_dosha", clear["pitra_dosha"], "zh", CLEAR)[2] sade = _sade_sati_summary_row({"is_active": True, "phase": "peak", "moon_sign": "Pisces"}, "zh") assert sade[1] == "进行中,高峰期" and "moon_sign" not in " ".join(sade) assert _sade_sati_summary_row({"moon_sign": "Pisces"}, "en")[1] == "Not assessed" # The appendix summary row says the phase in words too (was 「进行中,peak」). peak = {"is_active": True, "phase": "peak", "phases": {"rising": "Aquarius", "peak": "Pisces", "setting": "Aries"}} assert dosha_row("sade_sati", peak, "zh")[1] == "进行中,高峰期" assert dosha_row("sade_sati", peak, "en")[1] == "Active, peak phase" def test_practices_are_listed_only_for_a_dosha_this_rule_detected() -> None: remedies = {"recommendations": { "mantras": [{"planet": "Rahu", "mantra": "Om Rahave Namaha", "repetitions": 108}], "dosha_remedies": [ {"dosha": "Mangal Dosha", "actions": ["Mangal Chandika Path"], "gem": "红珊瑚 (Red Coral)"}, {"dosha": "Kaal Sarp Dosha", "actions": ["Rahu-Ketu Shanti Puja"], "gem": "天河石+猫眼石组合"}, {"dosha": "Pitra Dosha", "actions": ["Amavasya祖先祭拜"]}, ], }} def listed(detector: dict, planets: dict, language: str = "zh") -> list: pack = build_dosha_remedy_pack(detector, planets, remedy_snapshot=remedies, language=language) return [row.get("dosha") or row.get("planet") for row in pack["supportive_practices"]["recommendations"]] # 原值: ["Rahu", "Mangal Dosha", "Kaal Sarp Dosha", "Pitra Dosha"] # 新值: 时蛇煞不列做法 # 原因: BUG-2110 占星师 2026-11-21:近似筛查的候选结构不列传统做法 # BUG-2221 原值: 还有 "Rahu"(当前大运主星的咒语);新值: 只列检出 Dosha 的做法;原因: 占星师 2026-11-22 不按大运主星自动推荐 assert listed(_detector(DETECTED), DETECTED) == ["Mangal Dosha", "Pitra Dosha"] assert listed(_detector(CLEAR), CLEAR) == [] # The remedies module's own detection fired, but the inputs are missing here: not assessed, so no practice. unknown = {"mangal_dosha": {"has_dosha": True}, "kaal_sarp_dosha": {"has_dosha": True, "type": "partial"}} assert listed(unknown, {}) == [] english = build_dosha_remedy_pack(_detector(DETECTED), DETECTED, remedy_snapshot=remedies, language="en") # 原值: 英文版时蛇煞一行的 gem 为 None(中文宝石名不留「+」) # 新值: 时蛇煞是候选结构,不再列做法;Mangal 一行照旧 # 原因: BUG-2110 近似筛查的候选结构不列传统做法 assert not [row for row in english["supportive_practices"]["recommendations"] if row.get("dosha") == "Kaal Sarp Dosha"] # --- 5. Functional benefic / malefic table --------------------------------------- FUNCTIONAL = { "status": "used", "ascendant": "Capricorn", "functional_profile": "pvr_table30_v1", "functional_profile_ruling": "internal ruling note", "blocked_planets": [], "functional_benefics": ["Mercury", "Saturn", "Venus"], "functional_malefics": ["Jupiter", "Mars"], "functional_neutrals": ["Moon", "Sun"], "yogakarakas": ["Venus"], "owned_houses": {"Jupiter": [3, 12], "Sun": [8]}, "effect_on_confidence": "x", "source": "strict_functional_benefic_malefic_v2", "profile": "pvr_integrated_approach_13_2_table_30", "lagna_lord": "Saturn", "yogakaraka_definition": "distinct lordships: one of 4/7/10 and one of 5/9", "rule_reference": "references/product_functional_profile_bphs_v3_166q4.md", "profile_is_not": "bphs_ch34_general_with_sign_exceptions_v3_166q4", "assertion_label": "parameter_sensitive", "role_basis": {"Sun": "PVR §13.2 Table 30", "Moon": "PVR §13.2 Table 30 note: movable-lagna Moon by paksha"}, "profile_divergence": {"status": "differs", "selected_profile": "pvr_table30_v1", "other_profile": "bphs_exception_profile", "other_profile_scored": False, "cells": [{"planet": "Moon", "pvr_table30_v1": "neutral", "bphs_exception_profile": "malefic"}]}, "prior_rulings": [{"planet": "Saturn", "ruling": "BUG-1590(#166 Q4)"}], } def test_functional_table_uses_reader_words_in_both_editions() -> None: zh = dict(functional_layer_rows(FUNCTIONAL, "zh")) en = dict(functional_layer_rows(FUNCTIONAL, "en")) assert zh["状态"] == "已使用" and en["Status"] == "Used" assert zh["上升星座"] == "摩羯座" and en["Ascendant sign"] == "Capricorn" assert zh["上升主星"] == "土星" and en["Ascendant lord"] == "Saturn" # The profile keeps its name and version, in words. assert zh["功能吉凶口径"] == "PVR 表 30(第 1 版)" and en["Functional profile"] == "PVR Table 30 (version 1)" assert zh["各行星所管宫位"] == "太阳:第 8 宫;木星:第 3、12 宫" and en["Houses owned by each planet"] == "Sun: house 8; Jupiter: houses 3, 12" assert zh["与另一套口径对照"].startswith("两套口径有差异:月亮:PVR 表 30 为中性,BPHS 例外表 为凶星") assert zh["结论性质"] == "参数敏感" and en["Kind of statement"] == "parameter-sensitive" for rows in (zh, en): text = " ".join([*rows, *rows.values()]) assert not FIELD_NAME.search(text), FIELD_NAME.search(text) assert "BUG-" not in text and "references/" not in text and "internal ruling note" not in text assert not re.search(r"\b(used|ascendant|profile)\b", " ".join([*zh, *zh.values()])) # An unlisted profile is said to be unlisted; its key is not printed. other = dict(functional_layer_rows({"functional_profile": "some_new_profile_v9"}, "zh")) assert other["功能吉凶口径"] == "口径不在本报告的名称表内" # --- 7. One explanation page per instance ---------------------------------------- def _row(name: str, planets: list | None, combination: str | None, **extra) -> dict: row = {"name": name, "name_cn": extra.pop("name_cn", None) or name, **extra} if planets is not None: row["planets"] = planets if combination: row["combination"] = combination row["combination_en"] = extra.get("combination_en") or f"en:{name}" return row def test_yoga_pages_are_one_per_instance_and_never_print_an_empty_combination() -> None: engine = [ _row("Neecha Bhanga", ["Mars"], "火星落陷于巨蟹座;成立条件:落陷星座主星月亮在上升起第1宫(角宫)", name_cn="落陷取消", category="neecha_bhanga"), _row("Neecha Bhanga", ["Venus"], "金星落陷于处女座;成立条件:落陷星座主星水星在上升起第4宫(角宫)", name_cn="落陷取消", category="neecha_bhanga"), _row("Surya Yoga", ["Sun"], "太阳在第7宫", name_cn="太阳瑜伽", rule_id="rule_a"), _row("Surya Yoga", ["Sun"], "太阳在角宫", name_cn="太阳瑜伽", rule_id="rule_b"), _row("Kalatra Yoga", ["Moon"], "月亮在第7宫", name_cn="婚姻瑜伽"), _row("Kalatra Yoga", ["Venus"], "金星在第7宫", name_cn="婚姻瑜伽"), _row("Amala Yoga", None, "自定义条件满足", name_cn="无瑕格局", combination_en="Custom condition met"), _row("Amala Yoga", None, "第10宫只有吉星", name_cn="无瑕格局"), ] # The older detector returns the same Mars instance without planets list or combination, # and one more fallen planet whose row has neither combination nor condition. legacy = {"nicha_bhanga_raj": {"yogas": [ {"type": "Neecha Bhanga", "planet": "Mars", "cancellation_conditions": [ {"code": "A", "condition": "dispositor_kendra_from_lagna", "planet": "Moon", "house": 1, "frame": "lagna"}]}, {"type": "Neecha Bhanga", "planet": "Saturn"}, ]}} for language in ("zh", "en"): # `detected_yogas` and `yogas` are the same list in the packet; it must not double the pages. pack = build_yoga_interpretation_pack({"detected_yogas": engine, "yogas": engine}, legacy, set(), language=language) titles = [page["name"] for page in pack["pages"]] # 原值: 7 pages (the two Surya Yoga rules shared one page by name + planet) # 新值: 8 pages (rule_a and rule_b each keep their own page) # 原因: BUG-2105 pages are keyed by rule_id; same-name rules were merged in the English edition assert len(titles) == len(set(titles)) == 8, titles text = "\n".join(" ".join(page["sections"].values()) for page in pack["pages"]) assert "未判定" not in text and "未列出" not in text and "not listed" not in text assert "组合:。" not in text and "Combination: ." not in text zh = build_yoga_interpretation_pack({"detected_yogas": engine, "yogas": engine}, legacy, set(), language="zh")["pages"] # 原值: [..., "太阳瑜伽", ...] (one page for both rules) # 新值: "太阳瑜伽(太阳在第7宫)", "太阳瑜伽(太阳在角宫)" (one page per rule, titled by its own condition) # 原因: BUG-2105 pages are keyed by rule_id; same-name titles carry the rule's condition assert [page["name"] for page in zh] == [ "落陷取消(火星)", "落陷取消(金星)", "太阳瑜伽(太阳在第7宫)", "太阳瑜伽(太阳在角宫)", "婚姻瑜伽(月亮)", "婚姻瑜伽(金星)", "无瑕格局", "落陷取消(土星)", ] by_title = {page["name"]: page["sections"] for page in zh} assert "火星落陷于巨蟹座" in by_title["落陷取消(火星)"]["detected"] and "金星" not in by_title["落陷取消(火星)"]["detected"] assert "金星落陷于处女座" in by_title["落陷取消(金星)"]["detected"] # Same name, same planet, two rules: one page per rule, each with its own combination sentence. # 原值: by_title["太阳瑜伽"]["detected"] == "本案检出:太阳瑜伽。组合:太阳在第7宫;太阳在角宫。" # 新值: two pages, "组合:太阳在第7宫。" and "组合:太阳在角宫。" # 原因: BUG-2105 pages are keyed by rule_id (rule_a / rule_b are different rules) assert by_title["太阳瑜伽(太阳在第7宫)"]["detected"] == "本案检出:太阳瑜伽。组合:太阳在第7宫。" assert by_title["太阳瑜伽(太阳在角宫)"]["detected"] == "本案检出:太阳瑜伽。组合:太阳在角宫。" # A placeholder sentence gives way to a real one. assert by_title["无瑕格局"]["detected"] == "本案检出:无瑕格局。组合:第10宫只有吉星。" # An instance with neither combination nor condition gets its page without a combination clause. # 原值: "本案检出:落陷取消(Neecha Bhanga,不是王者格)。" # 新值: 后面加「原始落陷位置:本次未返回。」(这一行没有返回落陷星座,不编) # 原因: BUG-2110 占星师 2026-11-21 B:落陷取消页先列原始落陷位置 assert by_title["落陷取消(土星)"]["detected"] == "本案检出:落陷取消(Neecha Bhanga,不是王者格)。原始落陷位置:本次未返回。" en = [page["name"] for page in build_yoga_interpretation_pack({"detected_yogas": engine}, legacy, set(), language="en")["pages"]] assert en[:2] == ["Neecha Bhanga (Mars)", "Neecha Bhanga (Venus)"] and "Kalatra Yoga (Moon)" in en # --- 8. Same fact, two rule names, one row ---------------------------------------- def test_two_rules_on_one_fact_share_a_row_and_both_names_stay() -> None: engine_rows = [ {"rule_id": "surya_yoga_kendra", "name": "Surya Yoga (Sun in Kendra)", "name_cn": "太阳瑜伽(太阳入角宫)", "planets": ["Sun"], "combination": "太阳在第7宫", "effects": ["甲"], "effects_en": ["effect A"]}, {"rule_id": "surya_yoga_7", "name": "Surya Yoga (Sun in 7th House)", "name_cn": "太阳瑜伽(太阳入7宫)", "planets": ["Sun"], "combination": "太阳在第7宫", "effects": ["乙"], "effects_en": ["effect B"]}, {"rule_id": "chandra_yoga_1", "name": "Chandra Yoga (Moon in 1st House)", "planets": ["Moon"], "combination": "月亮在第1宫"}, ] layer_rows = [{"rule_id": item["rule_id"], "name": item["name"], "planets": {item["planets"][0]: {}}, "status": "computed"} for item in engine_rows] merged: list = [] kept = _report_yoga_rows(layer_rows, variant_keys=_engine_variant_keys(engine_rows), merged=merged) # One row per underlying fact: the 30-row cap is not consumed twice … assert [item["rule_id"] for item in kept] == ["surya_yoga_kendra", "chandra_yoga_1"] # … and the second rule is recorded against the row it shares. assert [(keeper["rule_id"], row["rule_id"]) for keeper, row in merged] == [("surya_yoga_kendra", "surya_yoga_7")] packet = { "worksheets": {"advanced_systems": {"yoga": {"detected_yogas": engine_rows}}}, "report_yoga_conditions": {"status": "executed", "reference_date": "2026-01-01", "rows": kept, "not_evaluated": [], "same_fact_rows": [{"into": 0, "row": layer_rows[1]}]}, } _layer, named, _observations = report_yoga_table(packet) assert len(named) == 2 display = named[0][1] assert [other["name"] for other in display["same_fact"]] == ["Surya Yoga (Sun in 7th House)"] # Each name keeps its own effect text. assert display["effects"] == ["甲"] and display["same_fact"][0]["effects"] == ["乙"] assert "same_fact" not in named[1][1] assert join_same_fact(["太阳瑜伽(太阳入角宫)", "太阳瑜伽(太阳入7宫)"], "zh") == "太阳瑜伽(太阳入角宫)/太阳瑜伽(太阳入7宫)" assert join_same_fact(["Surya Yoga (Sun in Kendra)", "Surya Yoga (Sun in 7th House)"], "en") == "Surya Yoga (Sun in Kendra) / Surya Yoga (Sun in 7th House)" assert join_same_fact(["甲", "甲", "-", "乙"], "zh") == "甲/乙" and "·" not in join_same_fact(["a", "b"], "zh") # --- The two public charts, end to end --------------------------------------------- def _section(text: str, heading: str) -> str: match = re.search(rf"(?m)^(#+) {re.escape(heading)}\s*$", text) assert match, heading tail = text[match.end():] return re.split(rf"(?m)^#{{1,{len(match[1])}}} ", tail, maxsplit=1)[0] @pytest.mark.parametrize("case_id", PUBLIC_REPORT_CASES) def test_public_report_carries_the_new_information_in_both_editions(case_id: str) -> None: packet, chinese, english = public_chart_reports(case_id) # 1. dated Sade Sati segments, with at least one retrograde re-entry, and the settings. intervals = packet["worksheets"]["advanced_systems"]["yogas_doshas"]["sade_sati"]["dated_intervals"] assert intervals["status"] == "computed" and any(item["entry"] == "re_entry" for item in intervals["segments"]) zh_sade, en_sade = _section(chinese, "Sade Sati 各段起止日期"), _section(english, "Sade Sati dated intervals") assert zh_sade.count("\n| 第 ") == len(intervals["segments"]) == len(re.findall(r"(?m)^\| \d+ \| ", en_sade)) assert "岁差:Raman" in zh_sade and "Ayanamsa: Raman" in en_sade stamps = re.compile(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}") assert stamps.findall(zh_sade) == stamps.findall(en_sade) != [] # 3. Tithi lord in the packet and on the birth page. module = packet["worksheets"]["birth_and_parameters"]["tithi_lord"] assert module["status"] == "computed" and module["lord"] in ("Sun", "Moon", "Mars", "Mercury", "Jupiter", "Venus", "Saturn", "Rahu") assert "| 主星的原始尊贵 |" in _section(chinese, "出生 Tithi 的主星") assert "| Lord's original dignity |" in _section(english, "Lord of the birth Tithi") # 4. no raw detector fields or True/False in the dosha summary. for text in (chinese, english): for needle in ("mars_house=", "sun_house=", "rahu_house=", "moon_sign="): assert needle not in text, needle zh_dosha, en_dosha = _section(chinese, "火星婚姻煞 / Sade Sati / Dosha 结果"), _section(english, "Mangala / Sade Sati / Dosha Results") assert zh_dosha.count("按本规则") >= 3 and en_dosha.count("by this rule") >= 3 for text in (zh_dosha, en_dosha): assert not re.search(r"\| (True|False|是|否) \|", text) and not FIELD_NAME.search(text) # 原值: "宫位近似筛查" / "approximate house-based screening"(检出或未检出的时蛇煞行都带) # 新值: "近似筛查" / "approximate"(Jobs 的时蛇煞是「近似筛查发现候选结构」) # 原因: BUG-2110 占星师 2026-11-21:宫位近似筛查的结果写成候选结构 assert "近似筛查" in zh_dosha and "approximate" in en_dosha # 5. functional table without stored keys. zh_functional = _section(chinese, "功能性吉凶星层") assert "| 上升星座 |" in zh_functional and "| 功能吉凶口径 | PVR 表 30(第 1 版) |" in zh_functional and "| 状态 | 已使用 |" in zh_functional assert not re.search(r"(?m)^\| [a-z_]+ \|", zh_functional) and "pvr_table30_v1" not in zh_functional en_functional = _section(english, "Functional Benefic / Malefic Layer") assert "| Ascendant sign |" in en_functional and "pvr_table30_v1" not in en_functional assert not re.search(r"(?m)^\| [a-z]+_[a-z_]+ \|", en_functional) # 7. yoga pages: unique titles, no empty combination. pages = packet["worksheets"]["advanced_systems"]["yoga_interpretation_pack"]["pages"] assert len({page["name"] for page in pages}) == len(pages) assert "组合:未判定" not in chinese and "组合:未列出" not in chinese def test_parity_chapters_wire_the_tithi_lord_and_the_witness_roles(): """BUG-2089:资料章节的 Tithi 一节和瑜伽参与行星表接上同一批数据,不再自相矛盾。""" import inspect from scripts.report_render import parity_chapters as chapters tithi = inspect.getsource(chapters._tithi) assert 'tithi_lord_lines(lord, language)' in tithi participants = inspect.getsource(chapters._yoga_participants) assert "neecha_participant_row(item, _yoga_planets_cell(item, language), status, active, language)" in participants