"""Source-bounded regression tests for Dwisaptatisama MD.""" from __future__ import annotations import json from datetime import datetime from pathlib import Path from scripts.dwisaptatisama_dasha import ( calculate_dwisaptatisama_dasha, dwisaptatisama_applicability, ) ROOT = Path(__file__).resolve().parents[1] def test_dwisaptatisama_accepts_lagna_lord_in_lagna_or_seventh() -> None: first = dwisaptatisama_applicability(ascendant_longitude=0.0, lagna_lord_sign_index=0) seventh = dwisaptatisama_applicability(ascendant_longitude=0.0, lagna_lord_sign_index=6) assert first["applicable"] is True assert first["lagna_lord_house"] == 1 assert seventh["applicable"] is True assert seventh["lagna_lord_house"] == 7 def test_dwisaptatisama_rejects_other_lagna_lord_houses() -> None: result = dwisaptatisama_applicability(ascendant_longitude=0.0, lagna_lord_sign_index=1) assert result["applicable"] is False assert result["lagna_lord_house"] == 2 def test_dwisaptatisama_blocks_without_explicit_lagna_lord_position() -> None: result = calculate_dwisaptatisama_dasha({ "birth_datetime": "2000-01-01T00:00:00", "ascendant_longitude": 0.0, "moon_longitude": 250.0, }) assert result["execution_status"] == "blocked" assert "lagna_lord_sign_index" in result["reason"] def test_dwisaptatisama_emits_only_source_bounded_md() -> None: result = calculate_dwisaptatisama_dasha({ "birth_datetime": datetime(2000, 1, 1, 12, 0), "ascendant_longitude": 0.0, "lagna_lord_sign_index": 0, "moon_longitude": 250.0, }) assert result["execution_status"] == "executed" assert result["confidence_status"] == "parameter_sensitive" assert result["total_cycle"] == 72 assert result["starting_lord"] == "Sun" # Mula is the seed. assert result["major"][0]["start_date"] == "2000-01-01T12:00:00" assert result["major"][0]["years"] < 9.0 assert result["period_depth_status"] == "mahadasha_executed_ad_pd_blocked_pending_row_level_replay" assert "antardasha" not in result["major"][0] def test_dwisaptatisama_standard_table_profile_preserves_unmet_gate_but_emits_rows() -> None: result = calculate_dwisaptatisama_dasha({ "birth_datetime": "2000-01-01T12:00:00", "ascendant_longitude": 0.0, "lagna_lord_sign_index": 1, "moon_longitude": 250.0, "standard_table_profile": "pl9_reports_all_dasha_tables_v1", }) assert result["execution_status"] == "executed" assert result["classical_applicable"] is False assert result["standard_table_profile"] == "pl9_reports_all_dasha_tables_v1" assert len(result["major"]) == 8