fix(rectification): scan chart boundaries in the user's ayanamsa (BUG-1307, BUG-1309)

This commit is contained in:
jesse-ux
2026-10-12 14:41:13 +08:00
parent b9a2866a22
commit ce4e98036d
12 changed files with 252 additions and 25 deletions
@@ -183,3 +183,66 @@ def test_api_boundary_is_optional_and_matches_window_scan(tmp_path):
scan_varga_segments({**body, "target_charts": ["D12"]}, cache_dir=tmp_path)
with pytest.raises(ValueError, match="invalid_boundary_charts"):
scan_varga_segments({**body, "boundary_charts": ["D99"], "recorded_time": "19:15"}, cache_dir=tmp_path)
# sha256 of the omitted-ayanamsa public-chart body, captured before this whitelist.
OMITTED_AYANAMSA_WINDOW_KEY = "58c936a2ccdbb5e339c79f9c43b990d556b627230cd5d5d200f3fcaaea85fad4"
def _public_segment_body() -> dict:
start = datetime(1955, 2, 24, 19, 12)
return {
"start_at": start.strftime("%Y-%m-%dT%H:%M"),
"end_at": (start + timedelta(minutes=6)).strftime("%Y-%m-%dT%H:%M"),
"latitude": JOBS["lat"], "longitude": JOBS["lon"], "timezone_offset": JOBS["tz"],
"target_charts": ["D1", "D9", "D10"],
}
def test_omitted_ayanamsa_matches_raman_and_lahiri_moves(tmp_path):
from scripts.rectification_varga_segments_api import VERSION, _segment_ayanamsa
body = _public_segment_body()
omitted = scan_varga_segments(body, cache_dir=tmp_path)
assert omitted["version"] == VERSION == "rectification-varga-segments-v1"
assert omitted["ayanamsa"] == "raman"
assert omitted["node_mode"] == "mean"
assert omitted["window_key"] == OMITTED_AYANAMSA_WINDOW_KEY
assert "nearest_boundary" not in omitted
for same in (
{"ayanamsa": "raman"},
{"ayanamsa": " Raman "},
{"ayanamsa": " "},
{"ayanamsa": None},
{"node_mode": "true"},
):
assert scan_varga_segments({**body, **same}, cache_dir=tmp_path) == omitted
lahiri = scan_varga_segments({**body, "ayanamsa": "Lahiri"}, cache_dir=tmp_path)
assert lahiri["ayanamsa"] == "lahiri"
assert lahiri["node_mode"] == "mean"
assert lahiri["window_key"] != omitted["window_key"]
assert [row["signs"] for row in lahiri["minutes"]] != [row["signs"] for row in omitted["minutes"]]
assert scan_varga_segments({**body, "ayanamsa": "lahiri"}, cache_dir=tmp_path) == lahiri
kp = scan_varga_segments({**body, "ayanamsa": "kp"}, cache_dir=tmp_path)
assert kp["ayanamsa"] == "kp"
assert kp["window_key"] not in {omitted["window_key"], lahiri["window_key"]}
for alias in ("krishnamurti", "krishnamurti_paddhati", "krishnamurti/kp", "Krishnamurti-Paddhati"):
assert scan_varga_segments({**body, "ayanamsa": alias}, cache_dir=tmp_path) == kp
citra = scan_varga_segments({**body, "ayanamsa": "true_chitra"}, cache_dir=tmp_path)
assert citra["ayanamsa"] == "true_citra"
assert scan_varga_segments({**body, "ayanamsa": "true-citra"}, cache_dir=tmp_path) == citra
pushya = scan_varga_segments({**body, "ayanamsa": "true_pushya"}, cache_dir=tmp_path)
assert pushya["ayanamsa"] == "true_pushya"
fagan = scan_varga_segments({**body, "ayanamsa": "fagan-bradley"}, cache_dir=tmp_path)
assert fagan["ayanamsa"] == "fagan_bradley"
assert len({omitted["window_key"], lahiri["window_key"], kp["window_key"], citra["window_key"], pushya["window_key"], fagan["window_key"]}) == 6
cached = {path.name for path in tmp_path.glob("*.json")}
for bad in ("djwhal_khul", "sassanian", "nope", 1, True):
with pytest.raises(ValueError, match="^invalid_ayanamsa$"):
scan_varga_segments({**body, "ayanamsa": bad}, cache_dir=tmp_path)
assert {path.name for path in tmp_path.glob("*.json")} == cached
assert _segment_ayanamsa("true_chitra") == "true_citra"
assert _segment_ayanamsa(None) == "raman"