Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp2U3BH1SxwAGyhhbe1
212 lines
12 KiB
Python
212 lines
12 KiB
Python
"""BUG-2165 (占星师 2026-11-22 §4, E): the debilitation state follows the yoga table's verification.
|
||
|
||
1. 「已核实」 only when the Neecha Bhanga row the yoga table prints has the verified status
|
||
(formed_under_source); a detector-only row (「检测器检出,待核实」) is a candidate.
|
||
2. Long repeating period lists (the AD / PD paragraphs of a Dasha page) print 「落陷¹」 and one
|
||
footnote under the page; the planet / dignity summary tables keep the short sentence.
|
||
|
||
Obama (public fixture): Jupiter debilitated, detector-only. Jobs: no debilitated planet. The verified
|
||
state is synthetic: with today's rule library no Neecha Bhanga row reaches formed_under_source.
|
||
"""
|
||
# BUG-2217 原值含「来源」的读者文字;新值改为「规则」等说法;原因:用户看到的文字不写「来源」(负责人规则 BUG-2115/2129)。
|
||
|
||
from __future__ import annotations
|
||
|
||
import re
|
||
|
||
import pytest
|
||
|
||
from scripts.pl9_interpretation_packs import build_dasha_interpretation_pack
|
||
from scripts.report_render.neecha_witness import (
|
||
neecha_marker_cell,
|
||
neecha_marker_note,
|
||
neecha_reason,
|
||
neecha_reasons,
|
||
neecha_state,
|
||
neecha_states,
|
||
neecha_table_notes,
|
||
)
|
||
from tests.public_chart_reports import public_chart_reports
|
||
|
||
NB = "落陷取消(Neecha Bhanga)"
|
||
|
||
|
||
def _snapshot(**lists) -> dict:
|
||
return {"nicha_bhanga_raj": {"yogas": [], "variant_only": [], "literal_only": [], **lists}}
|
||
|
||
|
||
def _layer(*rows) -> dict:
|
||
return {"status": "executed", "rows": list(rows)}
|
||
|
||
|
||
def _nb_row(planet: str, **extra) -> dict:
|
||
return {"rule_id": "main_detector:neecha_bhanga", "name": "Neecha Bhanga", "planets": {planet: {}}, **extra}
|
||
|
||
|
||
def test_state_follows_the_yoga_rows_verification() -> None:
|
||
snap = _snapshot(yogas=[{"planet": "Jupiter"}, {"planet": "Mars"}])
|
||
verified = _layer(_nb_row("Jupiter", status="computed", formation={"status": "formed_under_source"}),
|
||
_nb_row("Mars", status="computed"))
|
||
assert neecha_state("Jupiter", snap, verified) == "verified"
|
||
assert neecha_reason("Jupiter", snap, verified) == "source_verified"
|
||
# The table prints 「检测器检出,待核实」 for a computed row: candidate, detector only.
|
||
assert neecha_state("Mars", snap, verified) == "candidate"
|
||
assert neecha_reason("Mars", snap, verified) == "detector_only"
|
||
# A candidate or blocked row, a row of another planet, or no layer at all is not verification.
|
||
assert neecha_state("Jupiter", snap, _layer(_nb_row("Jupiter", status="candidate"))) == "candidate"
|
||
assert neecha_state("Jupiter", snap, _layer(_nb_row("Jupiter", status="blocked"))) == "candidate"
|
||
assert neecha_state("Jupiter", snap, _layer(_nb_row("Mars", formation={"status": "formed_under_source"}))) == "candidate"
|
||
assert neecha_state("Jupiter", snap, {}) == "candidate"
|
||
# A formed row of another yoga for the same planet does not verify the cancellation.
|
||
hamsa = {"rule_id": "mahapurusha_jupiter", "name": "Hamsa Yoga", "planets": ["Jupiter"],
|
||
"formation": {"status": "formed_under_source"}}
|
||
# BUG-2303 原值 candidate(检测器清单说木星有化解)/ 新值 not_met:已执行的格局层里既没有她的 Neecha 规则行、
|
||
# 也没有旧主检测器行时,由她的规则决定——没有化解 / 原因:负责人 2026-11-24 同意 Neecha 由她的规则判定
|
||
assert neecha_state("Jupiter", snap, _layer(hamsa)) == "not_met"
|
||
# A row merged into another as the same fact still counts as that row.
|
||
merged = {"status": "executed", "rows": [hamsa], "same_fact_rows": [
|
||
{"into": 0, "row": _nb_row("Jupiter", formation={"status": "formed_under_source"})}]}
|
||
assert neecha_state("Jupiter", snap, merged) == "verified"
|
||
|
||
|
||
def test_states_read_the_layer_cached_on_the_packet() -> None:
|
||
packet = {"worksheets": {"advanced_systems": {"yogas_doshas": _snapshot(
|
||
yogas=[{"planet": "Jupiter"}], variant_only=[{"planet": "Mars"}], literal_only=[{"planet": "Venus"}])}}}
|
||
assert neecha_states(packet)["Jupiter"] == "candidate"
|
||
packet["report_yoga_conditions"] = _layer(_nb_row("Jupiter", status="computed", formation={"status": "formed_under_source"}))
|
||
states = neecha_states(packet)
|
||
assert states["Jupiter"] == "verified"
|
||
# Variant-only, self-reference-only and not-computed stay as they were (BUG-2155).
|
||
assert states["Mars"] == "candidate" and states["Venus"] == "self_reference_only" and states["Saturn"] == "not_met"
|
||
assert neecha_reasons(packet)["Mars"] == "variant_only"
|
||
assert neecha_states({})["Jupiter"] == "not_computed"
|
||
|
||
|
||
def test_notes_tell_detector_only_from_variant_only() -> None:
|
||
states = {"Jupiter": "candidate", "Mars": "candidate"}
|
||
statuses = {"Jupiter": NB, "Mars": "落陷(Debilitated)"}
|
||
zh = neecha_table_notes(list(statuses), statuses, states, "zh")
|
||
# BUG-2280 原值「木星「缓解条件待核」:检测器找到了化解条件,还没有…核实」/ 新值见下 / 原因:负责人 11-23,有缓解就写有缓解
|
||
assert zh[0].startswith("木星有缓解:化解条件和见证星见")
|
||
assert "「落陷取消(木星)」" in zh[0]
|
||
assert zh[1] == "火星有缓解:按另一种读法,化解条件成立;原始的落陷不变。"
|
||
en = neecha_table_notes(list(statuses), statuses, states, "en")
|
||
assert en[0].startswith("Jupiter is mitigated: the conditions and witnesses are on")
|
||
|
||
|
||
def test_marker_and_its_one_footnote() -> None:
|
||
states = {"Jupiter": "candidate", "Saturn": "verified", "Mars": "candidate", "Venus": "not_computed"}
|
||
assert neecha_marker_cell(NB, "zh", "Jupiter", states) == "落陷¹"
|
||
assert neecha_marker_cell(NB, "en", "Saturn", states) == "Debilitated¹"
|
||
assert neecha_marker_cell("落陷(Debilitated)", "zh", "Mars", states) == "落陷¹"
|
||
# Not computed / no mitigation / other dignities: no marker, the usual text stays.
|
||
assert neecha_marker_cell("落陷(Debilitated)", "zh", "Venus", states) is None
|
||
assert neecha_marker_cell("入旺(Exalted)", "zh", "Jupiter", states) is None
|
||
assert neecha_marker_note("Jupiter", NB, "zh", states) == (
|
||
"¹ 木星:落陷;有缓解。缓解条件和见证星见「瑜伽解释」里的「落陷取消(木星)」;缓解不是新的尊贵等级,原始的落陷不变。")
|
||
assert neecha_marker_note("Saturn", NB, "en", states).startswith("¹ Saturn: Debilitated; mitigated. ")
|
||
assert neecha_marker_note("Mars", "落陷(Debilitated)", "zh", states) == (
|
||
"¹ 火星:落陷;有缓解。按另一种读法,化解条件成立;原始的落陷不变。") # BUG-2280
|
||
assert neecha_marker_note("Venus", "落陷(Debilitated)", "zh", states) is None
|
||
|
||
|
||
def _master(language: str) -> dict:
|
||
pds = [{"lord": lord, "start": f"2030-0{index + 1}-01", "end": f"2030-0{index + 2}-01"}
|
||
for index, lord in enumerate(("Jupiter", "Saturn", "Jupiter"))]
|
||
return {
|
||
"language": language,
|
||
"families": {"vimshottari": {"periods": [{
|
||
"lord": "Jupiter", "start": "2030-01-01", "end": "2046-01-01",
|
||
"raw_period": {"is_current": True, "antardasha_timeline": [
|
||
{"lord": "Jupiter", "start": "2030-01-01", "end": "2032-01-01", "is_current": True,
|
||
"pratyantar_dasha_timeline": pds},
|
||
{"lord": "Saturn", "start": "2032-01-01", "end": "2035-01-01", "pratyantar_dasha_timeline": pds},
|
||
]},
|
||
}]}},
|
||
"interpretation_triggers": {"planet_lord_items": [
|
||
{"lord": "Jupiter", "facts": {"house": 1, "ownership": [3, 12], "dignity": NB, "nakshatra": "Uttara Ashadha"}},
|
||
{"lord": "Saturn", "facts": {"house": 1, "ownership": [1, 2], "dignity": "入庙(Own Sign)", "nakshatra": "Uttara Ashadha"}},
|
||
]},
|
||
}
|
||
|
||
|
||
@pytest.mark.parametrize("language", ["zh", "en"])
|
||
def test_period_list_prints_the_marker_and_one_footnote(language: str) -> None:
|
||
states = {"Jupiter": "candidate"}
|
||
pack = build_dasha_interpretation_pack(_master(language), {"language": language, "neecha_states": states})
|
||
page = pack["page_series"][0]
|
||
short = "落陷;有缓解" if language == "zh" else "Debilitated; mitigated" # BUG-2280 原值「落陷;缓解条件待核」
|
||
marker = "尊贵落陷¹与星宿" if language == "zh" else "dignity Debilitated¹, and nakshatra"
|
||
paragraphs = [text for block in page["flow_blocks"] for kind, text in block["sections"] if kind in ("Antar", "Pratyantar")]
|
||
jupiter = [text for text in paragraphs if ("/ 木星(" if language == "zh" else "/ Jupiter (") in text]
|
||
assert len(jupiter) == 5 # 1 AD + 4 PD
|
||
assert all(marker in text and short not in text for text in jupiter)
|
||
# One footnote under the page for Jupiter, none for Saturn (not debilitated).
|
||
assert page["footnotes"] == [neecha_marker_note("Jupiter", NB, language, states)]
|
||
# The MD summary keeps the short sentence.
|
||
assert short in page["sections"]["natal_context"]
|
||
|
||
|
||
def test_period_list_without_states_never_reads_as_verified() -> None:
|
||
page = build_dasha_interpretation_pack(_master("zh"), {"language": "zh"})["page_series"][0]
|
||
text = " ".join(text for block in page["flow_blocks"] for _kind, text in block["sections"])
|
||
# BUG-2280: 已核、待核同一句,测试改成不出现任何待核说法
|
||
assert "缓解条件待核" not in text and "落陷¹" in text
|
||
assert page["footnotes"][0].startswith("¹ 木星:落陷;有缓解。")
|
||
|
||
|
||
def _section_counts(text: str, needle: str) -> dict[str, int]:
|
||
counts: dict[str, int] = {}
|
||
heading = ""
|
||
for line in text.splitlines():
|
||
if line.startswith("#"):
|
||
heading = line
|
||
elif needle in line:
|
||
counts[heading] = counts.get(heading, 0) + 1
|
||
return counts
|
||
|
||
|
||
@pytest.mark.parametrize("language", ["zh", "en"])
|
||
def test_public_chart_period_lists_use_the_marker(language: str) -> None:
|
||
_packet, chinese, english = public_chart_reports("barack_obama_1961_aa")
|
||
text = chinese if language == "zh" else english
|
||
short = "落陷;有缓解" if language == "zh" else "Debilitated; mitigated" # BUG-2280 原值「落陷;缓解条件待核」
|
||
pd_heading = "#### 木星 PD" if language == "zh" else "#### Pratyantar Dasha of Jupiter"
|
||
# 原值:中英各 97 处短句(木星 PD 段 72、AD 段 9);新值:PD 段 0,AD 段只剩每页脚注 9 条
|
||
# 原因:BUG-2165(占星师 2026-11-22 §4:避免九次复制同一句)
|
||
counts = _section_counts(text, short)
|
||
assert counts.get(pd_heading, 0) == 0
|
||
footnote = neecha_marker_note("Jupiter", NB, language, {"Jupiter": "candidate"})
|
||
pages = len(re.findall(r"^### .*(大运(MD)|Maha Dasha \(MD\))", text, flags=re.M))
|
||
assert pages == 9 and text.count(footnote) == pages
|
||
marker = "尊贵落陷¹与星宿" if language == "zh" else "dignity Debilitated¹, and nakshatra"
|
||
assert text.count(marker) == 81
|
||
assert text.count(short) <= 30
|
||
# Summary tables keep the short sentence (planet table row).
|
||
row = "| 木星 | 土星 | 太阳 | 金星 | 木星 | 落陷;有缓解 | 0.96 |" if language == "zh" else \
|
||
"| Jupiter | Saturn | Sun | Venus | Jupiter | Debilitated; mitigated | 0.96 |" # BUG-2280
|
||
assert row in text
|
||
|
||
|
||
def test_a_chart_without_debilitation_gets_no_marker() -> None:
|
||
_packet, chinese, english = public_chart_reports("steve_jobs_1955_aa")
|
||
assert "落陷¹" not in chinese and "Debilitated¹" not in english
|
||
|
||
|
||
def test_her_rule_rows_decide_the_state() -> None:
|
||
# BUG-2303 (负责人 2026-11-24 同意): her neechabhanga_* rows in the yoga layer decide, by the debilitated
|
||
# planet in formation_evidence.planet (her rows also list the witnesses as participants).
|
||
snap = _snapshot(yogas=[{"planet": "Mars"}])
|
||
|
||
def her(rule_id, status, **evidence):
|
||
return {"rule_id": rule_id, "name": "Neecha Bhanga", "planets": {"Moon": {}, "Jupiter": {}, "Saturn": {}},
|
||
"formation": {"status": status}, "formation_evidence": {"planet": "Jupiter", **evidence}}
|
||
|
||
assert neecha_reason("Jupiter", snap, _layer(her("neechabhanga_basic", "formed_under_source"))) == "source_verified"
|
||
assert neecha_reason("Jupiter", snap, _layer(her("neechabhanga_parivartana", "candidate"))) == "detector_only"
|
||
assert neecha_reason("Jupiter", snap, _layer(her("neechabhanga_basic", "formed_under_source",
|
||
self_reference_only=True))) == "self_reference_only"
|
||
# The witnesses Moon and Saturn are not debilitated planets of that row; Mars has no row of hers.
|
||
assert neecha_reason("Saturn", snap, _layer(her("neechabhanga_basic", "formed_under_source"))) == "not_met"
|
||
assert neecha_reason("Mars", snap, _layer(her("neechabhanga_basic", "formed_under_source"))) == "not_met"
|