Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
77 lines
3.7 KiB
Python
77 lines
3.7 KiB
Python
"""BUG-2113: rules that hit one chart fact stay one fact in the reading facts, each rule's meaning kept.
|
|
|
|
占星师 2026-11-21: two rules sharing a placement must not lose one interpretation; count it as one fact.
|
|
Public AA fixture (Barack Obama: Surya Yoga, Sun in Kendra / Sun in 7th House) and synthetic dicts only.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from functools import lru_cache
|
|
|
|
from scripts.jyotish_engine import build_professional_report_reference_packet, cmd_full_reading
|
|
from scripts.pl9_full_data_export import render_full_data_markdown
|
|
from scripts.professional_report_reference import _export_args
|
|
from scripts.report_render import reading_facts as rf
|
|
from scripts.report_render.reading_facts import build_report_reading_facts
|
|
from tests.test_consult_card_full_source import _public_body
|
|
|
|
|
|
@lru_cache(maxsize=2)
|
|
def _facts(rendered: bool) -> dict:
|
|
args = _export_args({**_public_body("barack_obama_1961_aa"), "today": "2026-11-11", "target_year": 2026})
|
|
reading = cmd_full_reading(args)
|
|
packet = dict(build_professional_report_reference_packet(reading, args, []))
|
|
packet["report_version"] = "pl9_personal_long_report.v3"
|
|
if rendered:
|
|
render_full_data_markdown(packet)
|
|
return build_report_reading_facts(packet, reading, minute_confirmed=True, today="2026-11-11")
|
|
|
|
|
|
def _surya(facts: dict) -> dict:
|
|
return next(row for row in facts["yogas"] if row.get("evidence_id") == "ev:yoga:surya_yoga_kendra@D1")
|
|
|
|
|
|
def test_both_rules_of_one_fact_reach_the_facts_with_or_without_rendering() -> None:
|
|
for rendered in (False, True):
|
|
block = _surya(_facts(rendered))["same_fact"]
|
|
assert block["counts_as"] == "one_fact"
|
|
assert block["shared_fact_zh"] == "太阳在第7宫"
|
|
rules = {rule["rule_id"]: rule for rule in block["rules"]}
|
|
assert set(rules) == {"surya_yoga_kendra", "surya_yoga_7"}
|
|
assert rules["surya_yoga_kendra"]["name_cn"] == "太阳瑜伽(太阳入角宫)"
|
|
assert rules["surya_yoga_7"]["name_cn"] == "太阳瑜伽(太阳入7宫)"
|
|
assert rules["surya_yoga_7"]["effects_zh"] == ["婚姻显赫", "配偶强势"]
|
|
assert block["text_zh"].startswith("共同的星盘事实:太阳在第7宫。")
|
|
assert "只算一个事实" in block["text_zh"]
|
|
|
|
|
|
def test_the_merged_rule_gets_no_evidence_id_of_its_own() -> None:
|
|
facts = _facts(False)
|
|
ids = [row.get("evidence_id") for row in facts["yogas"]]
|
|
assert "ev:yoga:surya_yoga_7@D1" not in ids
|
|
assert len(ids) == len(set(ids))
|
|
assert all("evidence_id" not in rule for rule in _surya(facts)["same_fact"]["rules"])
|
|
|
|
|
|
def test_a_row_without_merged_rules_has_no_block() -> None:
|
|
row = {"name": "X", "combination": "太阳Sun在第7宫"}
|
|
assert "same_fact" not in {k for k in row}
|
|
block = rf._same_fact_block({"rule_id": "a"}, {**row, "rule_id": "a", "same_fact": [{"rule_id": "b", "name_cn": "乙", "combination": "太阳Sun在第7宫"}]}, [])
|
|
assert block["shared_fact_zh"] == "太阳在第7宫"
|
|
assert [rule["rule_id"] for rule in block["rules"]] == ["a", "b"]
|
|
|
|
|
|
def test_merged_rules_carry_their_own_condition_text() -> None:
|
|
"""BUG-2113 follow-up: each rule's own condition (rule_condition_text), never the report's gap line."""
|
|
from tests.test_reading_facts_2106 import _facts as built
|
|
|
|
facts = built("barack_obama_1961_aa")
|
|
pairs = {}
|
|
for entry in facts.get("yogas") or []:
|
|
block = entry.get("same_fact") if isinstance(entry, dict) else None
|
|
for rule in (block or {}).get("rules") or []:
|
|
pairs[rule.get("rule_id")] = rule.get("conditions")
|
|
assert pairs.get("surya_yoga_kendra") == "太阳在第1、4、7、10宫之一"
|
|
assert pairs.get("surya_yoga_7") == "太阳在第7宫"
|
|
assert all(value != "条件没有随报告列出" for value in pairs.values())
|