Part 2 of #144. - The varga-segments scan gains opt-in stability_items: lagna degree, Sripati cusp signs, Moon sign / nakshatra / pada / house per minute, plus a historical-timezone check. The precheck requests D1/D9/D10 with it. - Chart page shows nine computed items (一致 / 有变化) only for a range the user gave, the verbatim comparison sentence, a verify-first block for the conditions stored data can show, and the verbatim Dasha boundary sentence. - Precheck sends the chart's ayanamsa and node mode and drops replies with other settings; the endpoint honours node_mode. candidate_time_sensitivity_scan and flexible_birth_time_profile take no defaults (BUG-1515). - 只记得时辰 third question, stored in birth_time_clue; no migration. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXoyeZrYn6ryNcSe5Y2Y
99 lines
5.3 KiB
Python
99 lines
5.3 KiB
Python
from scripts import candidate_time_sensitivity_scan as scanner
|
|
|
|
|
|
def test_scanner_reports_real_divisional_transitions(monkeypatch):
|
|
def fake_engine(command, payload, timeout=20):
|
|
minute = payload["minute"]
|
|
if command == "chart":
|
|
return {"ascendant": {"sign": "Leo", "degree_in_sign": 10 + minute / 100, "lon": 130 + minute / 100}}
|
|
ascendant = "Aries" if minute % 2 else "Taurus"
|
|
return {
|
|
"D4_Turyamsa": {"Ascendant": {"sign": ascendant, "degree_in_sign": minute / 10, "lon": minute}},
|
|
"D9_Navamsa": {"Ascendant": {"sign": ascendant, "degree_in_sign": minute / 10, "lon": minute}},
|
|
"D10_Dasamsa": {"Ascendant": {"sign": ascendant, "degree_in_sign": minute / 10, "lon": minute}},
|
|
"D24_Siddhamsa": {"Ascendant": {"sign": ascendant, "degree_in_sign": minute / 10, "lon": minute}},
|
|
"D30_Trimsamsa": {"Ascendant": {"sign": ascendant, "degree_in_sign": minute / 10, "lon": minute}},
|
|
}
|
|
|
|
monkeypatch.setattr(scanner, "_engine_json", fake_engine)
|
|
report = scanner.scan_candidate_times(
|
|
# 原值:载荷不带 ayanamsa / node_mode。新值:显式 raman / mean。
|
|
# 原因:issue #165 §4 起扫描不再自取默认设置,缺了直接报错(见下方 missing 用例)。
|
|
{"year": 2000, "month": 1, "day": 1, "hour": 12, "minute": 1, "lat": 1, "lon": 1, "tz": 0,
|
|
"ayanamsa": "raman", "node_mode": "mean"},
|
|
uncertainty_minutes=1,
|
|
)
|
|
|
|
assert report["candidate_count"] == 3
|
|
assert report["transitions"]
|
|
assert report["pending_layers"] == ["UL", "A7", "A10", "KP_cusp"]
|
|
assert report["rows"][0]["d1_longitude"] is not None
|
|
assert report["rows"][0]["divisional_ascendants"]["D9"]["sign"] in {"Aries", "Taurus"}
|
|
assert "D1" not in scanner._VARGAS
|
|
assert report["input_contract"]["settings"]["node_mode"] == "mean"
|
|
assert report["rows"][0]["input_fingerprint"] != report["rows"][1]["input_fingerprint"]
|
|
assert report["stability_contract"]["minute_confirmation_allowed"] is False
|
|
|
|
|
|
# 原值:test_scanner_keeps_raman_default_and_applies_explicit_lahiri,不传岁差时断言回执为 raman。
|
|
# 新值:两次都显式传岁差(raman / lahiri),断言回执与传入一致。
|
|
# 原因:issue #165 §4 起扫描没有默认岁差;默认值只留给没有档案的调用方(命令行、无设置的 API 请求),由它们自己填。
|
|
def test_scanner_applies_the_explicit_ayanamsa_it_is_given() -> None:
|
|
birth = {
|
|
"year": 2000,
|
|
"month": 1,
|
|
"day": 1,
|
|
"hour": 12,
|
|
"minute": 1,
|
|
"lat": 25.04,
|
|
"lon": 121.56,
|
|
"tz": 8,
|
|
}
|
|
|
|
default_report = scanner.scan_candidate_times({**birth, "ayanamsa": "raman", "node_mode": "mean"}, uncertainty_minutes=1)
|
|
lahiri_report = scanner.scan_candidate_times(
|
|
{**birth, "ayanamsa": "lahiri", "node_mode": "mean"},
|
|
uncertainty_minutes=1,
|
|
)
|
|
default_center = next(row for row in default_report["rows"] if row["offset_minutes"] == 0)
|
|
lahiri_center = next(row for row in lahiri_report["rows"] if row["offset_minutes"] == 0)
|
|
|
|
assert default_report["input_contract"]["settings"]["ayanamsa"] == "raman"
|
|
assert lahiri_report["input_contract"]["settings"]["ayanamsa"] == "lahiri"
|
|
assert abs(default_center["d1_longitude"] - lahiri_center["d1_longitude"]) > 1
|
|
|
|
|
|
def test_scanner_refuses_a_call_without_explicit_settings(monkeypatch) -> None:
|
|
"""Issue #165 §4: no Raman / mean default inside the scan."""
|
|
calls: list[str] = []
|
|
monkeypatch.setattr(scanner, "_engine_json", lambda command, payload, timeout=20: calls.append(command) or {})
|
|
birth = {"year": 2000, "month": 1, "day": 1, "hour": 12, "minute": 1, "lat": 1, "lon": 1, "tz": 0}
|
|
for partial, missing in (({}, "ayanamsa, node_mode"), ({"ayanamsa": "raman"}, "node_mode"), ({"node_mode": "mean"}, "ayanamsa")):
|
|
try:
|
|
scanner.scan_candidate_times({**birth, **partial}, uncertainty_minutes=1)
|
|
except ValueError as exc:
|
|
assert str(exc) == f"missing calculation settings: {missing}"
|
|
else: # pragma: no cover - the assertion is the failure
|
|
raise AssertionError("a scan without settings must not run")
|
|
assert calls == []
|
|
|
|
|
|
def test_scanner_passes_true_nodes_and_the_same_settings_to_every_fingerprint(monkeypatch) -> None:
|
|
seen: list[tuple[str, str]] = []
|
|
|
|
def fake_engine(command, payload, timeout=20):
|
|
settings = scanner.calculation_settings(payload)
|
|
seen.append((settings["ayanamsa"], settings["node_mode"]))
|
|
if command == "chart":
|
|
return {"ascendant": {"sign": "Leo", "degree_in_sign": 10, "lon": 130}}
|
|
return {}
|
|
|
|
monkeypatch.setattr(scanner, "_engine_json", fake_engine)
|
|
birth = {"year": 2000, "month": 1, "day": 1, "hour": 12, "minute": 1, "lat": 1, "lon": 1, "tz": 0}
|
|
report = scanner.scan_candidate_times({**birth, "ayanamsa": "Lahiri", "nodeMode": "TRUE"}, uncertainty_minutes=1)
|
|
assert set(seen) == {("lahiri", "true")}
|
|
assert report["input_contract"]["settings"] == {"ayanamsa": "lahiri", "node_mode": "true"}
|
|
from scripts.rectification_input_contract import candidate_input_fingerprint
|
|
assert report["input_contract"]["center_input_fingerprint"] == candidate_input_fingerprint(
|
|
{**birth, "ayanamsa": "lahiri", "node_mode": "true"})
|