Files
Jyotisha/tests/test_rectification_kp_cusp_observation.py
T
ClaudeandClaude Opus 5.5 c1a69445b5 refactor: retire event-scored rectification backend (BUG-1644)
Remove the V5 scoring pipeline, dynamic rectification, minute-rectification
evaluations and the research scripts built on them, plus their API routes.
Keep the upstream skill layer (gate, questionnaire, active events), the
varga-segments scan and the consult range reading (moved to
scripts/birth_window_range_reading.py).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXozbkyFNqbu8pVEtZ7W
2026-11-06 02:40:28 +08:00

137 lines
4.8 KiB
Python

from __future__ import annotations
from tests.conftest import FIXTURE_BIRTH_DATE, FIXTURE_BIRTH_LAT, FIXTURE_BIRTH_LON
from datetime import datetime
from kp_system import KP_LORDS
from scripts.active_rectification_event_engine import (
build_candidate_static_context,
compute_event_candidate_rows,
)
from scripts.rectification.kp_cusp_observation import observe_kp_cusps
from scripts.rectification.refinement_packet import window_scan
def _request() -> dict:
return {
"birth_date": FIXTURE_BIRTH_DATE,
"start_time": "14:29",
"end_time": "14:30",
"lat": FIXTURE_BIRTH_LAT,
"lon": FIXTURE_BIRTH_LON,
"tz": 8.0,
"events": [{
"id": "5cb071d6-6d99-46be-85dc-a9bf59ef6ac5",
"domain": "career",
"date": "2019-07-01",
"precision": "day",
}],
}
def _score_request() -> dict:
return {
"events": [
{
"id": "00000000-0000-4000-8000-000000000001",
"domain": "career",
"summary": "入职",
"event_kind": "career_entry",
"precision": "day",
"date_start": "2016-09-15",
"date_end": "2016-09-15",
},
{
"id": "00000000-0000-4000-8000-000000000002",
"domain": "relationship",
"summary": "开始一段关系",
"event_kind": "relationship_start",
"precision": "day",
"date_start": "2018-03-01",
"date_end": "2018-03-01",
},
{
"id": "00000000-0000-4000-8000-000000000003",
"domain": "education",
"summary": "毕业",
"event_kind": "education_completion",
"precision": "day",
"date_start": "2015-06-01",
"date_end": "2015-06-01",
},
{
"id": "00000000-0000-4000-8000-000000000004",
"domain": "family",
"summary": "家人变化",
"event_kind": "family_event",
"precision": "day",
"date_start": "2020-01-01",
"date_end": "2020-01-01",
},
]
}
def _diagnostics() -> dict:
return {
"leave_one_event_out_retention_rate": 1,
"leave_one_domain_out_retention_rate": 1,
"date_sensitivity_retention_rate": 1,
"primary_secondary_margin_percent": 50,
}
def test_observe_kp_cusps_uses_placidus_not_equal_houses() -> None:
context = build_candidate_static_context(_request(), datetime(1993, 4, 17, 14, 29))
feature = context["feature"]
snapshot = feature["kp_cusps"]
natal_houses = context["chart"]["houses"]
assert snapshot["status"] == "executed"
assert snapshot["house_system"] == "placidus"
assert snapshot["ayanamsa"] == "krishnamurti"
assert len(snapshot["houses"]) == 12
tenth = snapshot["houses"]["10"]
equal_tenth = float(natal_houses["house_10"]["cusp_degree"])
assert abs(float(tenth["cusp_degree"]) - equal_tenth) > 0.05
assert tenth["sub_lord"] in KP_LORDS
assert isinstance(feature["kp1_sub_index"], int)
assert 0 <= feature["kp1_sub_index"] <= 8
assert "KP_cusps" not in feature["blocked_layers"]
assert "KP_cusps" in feature["available_layers"]
def test_kp_observation_is_absent_from_scoring_missing_layers() -> None:
request = _request()
context = build_candidate_static_context(request, datetime(1993, 4, 17, 14, 29))
rows = compute_event_candidate_rows(request, static_contexts=[context])
assert rows
assert "KP_cusps" not in rows[0]["missing_layers"]
assert context["feature"]["kp_cusps"]["status"] == "executed"
def test_window_scan_emits_kp_sub_lord_changes_without_confirmation() -> None:
scan = window_scan({
"static_contexts": [
{"feature": {"time": "05:13", "kp1_sub_index": 1, "kp4_sub_index": 2, "kp7_sub_index": 3, "kp10_sub_index": 4}},
{"feature": {"time": "05:14", "kp1_sub_index": 2, "kp4_sub_index": 2, "kp7_sub_index": 3, "kp10_sub_index": 4}},
]
})
meanings = [item["user_meaning"] for item in scan["transitions"]]
assert "KP 1宫子主 在 05:14 发生变化" in meanings
assert "KP 4宫子主 在 05:14 发生变化" not in meanings
encoded = str(scan)
assert "白羊" not in encoded
assert "Aries" not in encoded
assert scan["confirmation_allowed"] is False
assert scan["unique_minute_claim"] is False
def test_observe_kp_cusps_blocks_without_inventing_whole_sign_proxy() -> None:
snapshot = observe_kp_cusps(None, 36.6, 114.3)
assert snapshot["status"] == "blocked"
assert snapshot["houses"] == {}
polar = observe_kp_cusps(2451545.0, 80.0, 0.0)
assert polar["status"] == "blocked"
assert polar["houses"] == {}