- R1: default AD direction rath_p50_md_parity_v1 (start parity kept as a research profile); full profile config + algorithm version on every Narayana output, cache keys (consult, api chart, probes, long report, synastry) and the rectification run. - R2: one strength profile at the seed, AD start and p.43 (d); selected / equal / unresolved kept apart; unresolved nodes block only what depends on them (seed candidates kept, dated MDs before an unresolved length kept, AD-only loss in rectification keeps the MD). - R3: Neecha Bhanga witness fields (reference, relative_house, self_reference, independent_confirmation_allowed, self_reference_only) from the main detector to the evidence card yogas_detail rows; self-reference-only never counts as support. - Sync her b54812c3 KP clock validation; port her round-5 / round-6 tests. - BUG-1783..1787; golden recaptured with TTL 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
146 lines
7.4 KiB
Python
146 lines
7.4 KiB
Python
"""BUG-1759: rectification uses the product's source-version Narayana and the default PVR functional table.
|
|
|
|
原值:校正打分用旧 Narayana 算法(narayana_dasha.calc_narayana_mahadasha 等,从上升起、一律顺数,年龄 365.2425 天),
|
|
功能吉凶明确选中 bphs_exception_profile。
|
|
新值:Narayana 与报告 / 咨询卡同一个来源版(narayana_rath,出生时刻起、narayana_age 365.25 天),blocked 时这一层不可用、
|
|
不回退旧算法;功能吉凶用默认档 pvr_table_30 并传月亮盈亏。
|
|
原因:产品 2026-11-08 批准;占星师第五轮裁定 1、3;与报告/卡口径一致。
|
|
"""
|
|
import sys
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / "scripts"))
|
|
|
|
import functional_benefics # noqa: E402
|
|
import narayana_dasha # noqa: E402
|
|
import narayana_legacy_label as label # noqa: E402
|
|
|
|
from scripts import active_rectification_event_engine as engine # noqa: E402
|
|
from scripts.chart_choice import astrologer # noqa: E402
|
|
from scripts.chart_choice.boundaries import ChartRequest # noqa: E402
|
|
|
|
SIGNS = ["Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo",
|
|
"Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"]
|
|
|
|
# Public charts (birth time as published): Jobs, Obama, Presley.
|
|
PUBLIC = {
|
|
"jobs": (datetime(1955, 2, 24, 19, 15), 37.7749, -122.4194, -8.0),
|
|
"obama": (datetime(1961, 8, 4, 19, 24), 21.3069, -157.8583, -10.0),
|
|
"presley": (datetime(1935, 1, 8, 4, 35), 34.25, -88.7, -6.0),
|
|
}
|
|
|
|
|
|
def _context(birth: datetime, lat: float, lon: float, tz: float) -> dict:
|
|
request = {
|
|
"birth_date": birth.strftime("%Y-%m-%d"),
|
|
"start_time": birth.strftime("%H:%M"),
|
|
"end_time": birth.strftime("%H:%M"),
|
|
"lat": lat, "lon": lon, "tz": tz,
|
|
"events": [{"id": "e1", "domain": "career", "date": f"{birth.year + 30}-07-01", "precision": "year"}],
|
|
}
|
|
return engine.build_candidate_static_context(request, birth)
|
|
|
|
|
|
def _event_dates(birth: datetime) -> list[datetime]:
|
|
dates = [datetime(birth.year + years, month, 15) for years in range(1, 76) for month in (1, 7)]
|
|
return [at for at in dates if at > birth]
|
|
|
|
|
|
@pytest.mark.parametrize("name", sorted(PUBLIC))
|
|
def test_running_narayana_md_at_event_dates_equals_the_product_layer(name: str) -> None:
|
|
birth, lat, lon, tz = PUBLIC[name]
|
|
context = _context(birth, lat, lon, tz)
|
|
asc = int(context["ascendant_index"])
|
|
lons = context["planet_longitudes"]
|
|
row = astrologer._minute_row(ChartRequest(birth_date=birth.strftime("%Y-%m-%d"), lat=lat, lon=lon, tz=tz), birth)
|
|
assert row["asc"] == asc
|
|
checked = 0
|
|
for event_at in _event_dates(birth):
|
|
age = label.narayana_age(birth, event_at)
|
|
product = label.product_narayana(None, asc, lons, current_age=age, birth_year=birth.year,
|
|
birth_datetime=birth)
|
|
assert product["status"] != "blocked", name
|
|
md = product["current_dasha"]["md"]
|
|
assert md["start_date"] <= event_at.strftime("%Y-%m-%d") <= md["end_date"]
|
|
rect_md, rect_ad = engine._active_narayana(
|
|
asc, lons, birth, event_at, context["narayana_periods"], context["narayana_antardasha_by_md"])
|
|
assert SIGNS[rect_md] == md["sign"], (name, event_at)
|
|
# 原值:每个日期都有小运。新值:小运起点比较 unresolved 的大运里小运为 None,产品同样没有当前小运,大运仍在。
|
|
# 原因:占星师 2026-11-08 第六轮 R2(某 MD 的小运取强未决只阻塞该 MD 的 AD)。
|
|
product_ad = (product["current_dasha"].get("ad") or {}).get("sign")
|
|
assert (None if rect_ad is None else SIGNS[rect_ad]) == product_ad, (name, event_at)
|
|
# The live chart-choice stage reads the same rows from its own minute row.
|
|
stage_md, stage_ad = engine._active_narayana(asc, row["planets"], birth, event_at, *row["narayana"])
|
|
assert (stage_md, stage_ad) == (rect_md, rect_ad), (name, event_at)
|
|
checked += 1
|
|
assert checked >= 140
|
|
|
|
|
|
def test_engine_tables_are_the_product_rows_from_the_birth_moment() -> None:
|
|
birth, lat, lon, tz = PUBLIC["jobs"]
|
|
context = _context(birth, lat, lon, tz)
|
|
product = label.rath_narayana_view(int(context["ascendant_index"]), context["planet_longitudes"],
|
|
birth_datetime=birth)
|
|
periods = context["narayana_periods"]
|
|
assert len(periods) == 24 and [p["sign"] for p in periods] == [p["sign"] for p in product["mahadasha"]]
|
|
assert [round(p["end_age"], 2) for p in periods] == [p["end_age"] for p in product["mahadasha"]]
|
|
assert set(context["narayana_antardasha_by_md"]) == {p["period_key"] for p in periods}
|
|
|
|
|
|
def test_blocked_source_step_is_unavailable_and_never_falls_back(monkeypatch) -> None:
|
|
birth, lat, lon, tz = PUBLIC["obama"]
|
|
context = _context(birth, lat, lon, tz)
|
|
|
|
def legacy(*_args, **_kwargs):
|
|
raise AssertionError("legacy Narayana must not be called")
|
|
|
|
for fn in ("calc_narayana_mahadasha", "calc_narayana_antardasha", "get_current_narayana_dasha"):
|
|
monkeypatch.setattr(narayana_dasha, fn, legacy)
|
|
monkeypatch.setattr(engine.narayana_rath, "calc_narayana_rath",
|
|
lambda *_a, **_k: {"status": "blocked", "blocked_step": "years", "mahadasha": None})
|
|
asc, lons = int(context["ascendant_index"]), context["planet_longitudes"]
|
|
assert engine._narayana_periods(asc, lons) is None
|
|
assert engine._active_narayana(asc, lons, birth, datetime(1990, 1, 1)) == (None, None)
|
|
|
|
# AD step blocked: MD stays, AD is unavailable.
|
|
monkeypatch.undo()
|
|
monkeypatch.setattr(engine.narayana_rath, "antardasha", lambda *_a, **_k: {"status": "blocked", "rows": []})
|
|
md, ad = engine._active_narayana(asc, lons, birth, datetime(1990, 1, 1))
|
|
assert md is not None and ad is None
|
|
|
|
|
|
def test_unavailable_narayana_shrinks_the_stage_maximum_instead_of_counting_a_miss() -> None:
|
|
full = astrologer._dasha_max({})
|
|
assert full == astrologer.DASHA_MAX_PER_EVENT
|
|
assert astrologer._dasha_max({"unavailable": ["narayana_ad"]}) == full - 1
|
|
assert astrologer._dasha_max({"unavailable": ["narayana_md", "narayana_ad"]}) == full - 3
|
|
|
|
|
|
def test_functional_roles_are_the_default_pvr_table_with_paksha() -> None:
|
|
birth, lat, lon, tz = PUBLIC["presley"]
|
|
context = _context(birth, lat, lon, tz)
|
|
chart = context["chart"]
|
|
expected = functional_benefics.derive_functional_benefic_malefic(
|
|
chart["ascendant"].get("sign"),
|
|
moon_paksha=functional_benefics.moon_paksha_from_planets(chart.get("planets")))
|
|
assert context["functional_profile"] == expected
|
|
assert context["functional_profile"]["functional_profile"] == functional_benefics.FUNCTIONAL_PROFILE_PVR
|
|
|
|
|
|
def test_probe_start_dates_use_the_birth_moment_and_reject_date_strings() -> None:
|
|
from scripts.rectification import event_probes
|
|
|
|
birth, lat, lon, tz = PUBLIC["jobs"]
|
|
context = _context(birth, lat, lon, tz)
|
|
asc, lons = int(context["ascendant_index"]), context["planet_longitudes"]
|
|
starts = event_probes._narayana_start_dates(asc, lons, birth, 1900, 2100)
|
|
product = label.rath_narayana_view(asc, lons, birth_datetime=birth)
|
|
assert {row["start_date"] for row in product["mahadasha"]} <= {d.isoformat() for d in starts}
|
|
assert event_probes._narayana_start_dates(asc, lons, None, 1900, 2100) is None
|
|
with pytest.raises(TypeError):
|
|
event_probes._narayana_start_dates(asc, lons, birth.strftime("%Y-%m-%d"), 1900, 2100)
|