Ports her yinduzhanxing 17a135457ec16b621f86dd57ba3926612ce1b9b8 (docs ee34700357): timing_evidence_packets.py (new), kp_monthly_report_packet / theme_support / vimshottari / transits, kp_system, with her tests. The report path (frozen engine, no timing systems supplied) keeps its earlier packet byte for byte; her profile and window run when the caller supplies the periods it already computed (engine tool kp_timing_packet, cached per chart and window). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq
127 lines
8.1 KiB
Python
127 lines
8.1 KiB
Python
from datetime import datetime
|
|
|
|
from scripts.timing_evidence_packets import build_multi_system_window
|
|
|
|
|
|
def row(label, start, end, level='MD', **extra):
|
|
return dict(sign=label, level=level, start_date=start, end_date=end, **extra)
|
|
|
|
|
|
def test_intra_month_boundaries_and_half_open_transitions_survive():
|
|
start, change, end = '2026-01-01', '2026-01-15', '2026-02-01'
|
|
a = {'dense_boundaries': [row('Aries', start, end), row('Leo', start, change, 'AD'), row('Virgo', change, end, 'AD')]}
|
|
b = {'major': [dict(planet='Moon', start_date=start, end_date='2026-01-20'),
|
|
dict(planet='Sun', start_date='2026-01-20', end_date=end)]}
|
|
result = build_multi_system_window({'narayana': a, 'yogini': b}, start=start, end=end)
|
|
assert len(result['segments']) == 3
|
|
assert result['segments'][1]['systems']['narayana']['path'][-1]['label'] == 'Virgo'
|
|
assert result['segments'][2]['systems']['yogini']['path'][0]['label'] == 'Sun'
|
|
assert all(track['window_coverage'] == 'complete' for track in result['tracks'].values())
|
|
|
|
|
|
def test_blocked_children_and_inapplicability_do_not_become_support():
|
|
start, end = '2026-01-01', '2026-02-01'
|
|
source = {'dense_boundaries': [row('Aries', start, end),
|
|
row(None, start, end, 'AD', source_formula_status='blocked_antardasha_profile_error')]}
|
|
result = build_multi_system_window({'narayana': source, 'ashtottari': {'applicable': False}, 'missing': {}}, start=start, end=end)
|
|
assert result['segments'][0]['systems']['narayana']['status'] == 'coverage_gap'
|
|
assert result['tracks']['narayana']['issues']
|
|
assert result['tracks']['ashtottari']['status'] == 'not_applicable'
|
|
assert result['tracks']['missing']['status'] == 'blocked'
|
|
|
|
|
|
def test_overlapping_same_level_is_not_two_votes():
|
|
source = {'major': [dict(planet='Sun', start_date='2026-01-01', end_date='2026-02-01'),
|
|
dict(planet='Moon', start_date='2026-01-10', end_date='2026-02-01')]}
|
|
result = build_multi_system_window({'yogini': source}, start='2026-01-01', end='2026-02-01')
|
|
assert result['segments'][1]['systems']['yogini']['status'] == 'overlap_conflict'
|
|
assert result['tracks']['yogini']['window_coverage'] == 'not_certified'
|
|
|
|
|
|
def test_real_narayana_and_yogini_are_connected_to_kp_window():
|
|
# BUG-2333 原值: her producers narayana_report_with_variants + attach_narayana_calendar and
|
|
# calc_chara_dasha_with_antardasha + attach_chara_calendar; 新值: the product's real Yogini producer and the native
|
|
# cmd_dasha (natal Vimshottari) — the product has no Narayana / Chara calendar attachers (its chat sends those as
|
|
# dasha_systems rows, covered in tests/test_ondemand_kp_timing_packet_2333.py); 原因: the product's narayana_dasha.py /
|
|
# jaimini.py differ from hers and are not part of this port. Her other assertions are kept.
|
|
from types import SimpleNamespace
|
|
from scripts.domain_calculation_service import compute_chart
|
|
from scripts.jyotish_engine import cmd_dasha
|
|
from scripts.yogini_dasha import calculate_yogini_dasha
|
|
from scripts.kp_monthly_report_packet import build_kp_monthly_report_packet
|
|
birth = dict(year=2000, month=1, day=1, hour=12, minute=0, second=30,
|
|
lat=20, lon=75, tz=5.5, ayanamsa='lahiri', node_mode='mean')
|
|
chart = compute_chart(birth)
|
|
dt = datetime(2000, 1, 1, 12, 0, 30)
|
|
planets = {name: item['lon'] for name, item in chart['planets'].items() if 'lon' in item}
|
|
yogini = calculate_yogini_dasha(dict(birth_datetime=dt, moon_longitude=planets['Moon'],
|
|
as_of='2026-11-01', dasha_year_days=365.25))
|
|
natal = cmd_dasha(SimpleNamespace(year=2000, month=1, day=1, hour=12, minute=0, second=30,
|
|
moon_lon=planets['Moon'], nakshatra=None, pada=None, birthdate=None, today='2026-11-01', dasha_year_days=365.25))
|
|
result = build_kp_monthly_report_packet(birth_payload=birth, start_month='2026-11', month_count=12,
|
|
source_natal_chart=chart,
|
|
additional_timing_systems={'natal_vimshottari': natal, 'yogini': yogini})
|
|
window = result['multi_system_window']
|
|
assert window['tracks']['natal_vimshottari']['periods']
|
|
assert window['tracks']['yogini']['window_coverage'] == 'complete'
|
|
assert window['tracks']['natal_vimshottari']['window_coverage'] == 'complete'
|
|
assert window['tracks']['kp_vimshottari']['window_coverage'] == 'complete'
|
|
assert window['tracks']['ashtottari']['status'] == 'blocked'
|
|
assert len(window['segments']) > 1
|
|
assert any(datetime.fromisoformat(segment['start']).day != 1 for segment in window['segments'])
|
|
assert all(left['end_exclusive'] == right['start'] for left, right in zip(window['segments'], window['segments'][1:]))
|
|
assert all(segment['systems']['natal_vimshottari']['path'] for segment in window['segments'])
|
|
evidence = result['segment_domain_evidence']
|
|
assert len(evidence['segments']) == len(window['segments'])
|
|
actual = {r['system'] for s in evidence['segments'] for r in s['associations']}
|
|
assert {'natal_vimshottari', 'yogini', 'kp_vimshottari'} <= actual
|
|
assert evidence['probability'] is None
|
|
transit = result['slow_transit_boundaries']
|
|
assert transit['status'] == 'executed' and transit['events']
|
|
assert transit['profile']['ayanamsa'] == 'kp'
|
|
assert {'station', 'sign_ingress'} <= {e['kind'] for e in transit['events']}
|
|
starts = {s['start'] for s in window['segments']}
|
|
assert all(e['timestamp_local'] in starts for e in transit['events'])
|
|
assert all(e.get('root_error_degrees', 0) < 1e-5 for e in transit['events'])
|
|
|
|
|
|
def test_transit_boundary_preserves_period_and_excludes_right_endpoint():
|
|
start, end = '2026-01-01T00:00:00', '2026-02-01T00:00:00'
|
|
result = build_multi_system_window({'yogini': {'major': [
|
|
dict(planet='Sun', start_date=start, end_date=end)]}}, start=start, end=end,
|
|
boundary_events=[{'timestamp_local': '2026-01-15T12:30:00', 'kind': 'station'},
|
|
{'timestamp_local': end, 'kind': 'station'}])
|
|
assert len(result['segments']) == 2
|
|
assert len(result['segments'][1]['boundary_events']) == 1
|
|
assert result['segments'][0]['systems'] == result['segments'][1]['systems']
|
|
|
|
|
|
def test_domain_associations_change_when_narayana_child_changes():
|
|
from scripts.timing_evidence_packets import build_segment_domain_evidence, render_segment_domain_evidence
|
|
source = {'dense_boundaries': [row('Aries', '2026-01-01', '2026-02-01'),
|
|
row('Capricorn', '2026-01-01', '2026-01-15', 'AD'),
|
|
row('Aquarius', '2026-01-15', '2026-02-01', 'AD')]}
|
|
window = build_multi_system_window({'narayana': source}, start='2026-01-01', end='2026-02-01')
|
|
chart = {'ascendant': {'lon': 0}, 'planets': {'Sun': {'lon': 1}}}
|
|
output = build_segment_domain_evidence(window, natal_chart=chart, natal_kp={})
|
|
first, second = output['segments']
|
|
assert any(r['level'] == 'AD' and r['house'] == 10 for r in first['associations'])
|
|
assert any(r['level'] == 'AD' and r['house'] == 11 for r in second['associations'])
|
|
assert not any(r['level'] == 'AD' and r['house'] == 10 for r in second['associations'])
|
|
assert all('convergence_level' not in r for s in output['segments'] for r in s['associations'])
|
|
rendered = '\n'.join(render_segment_domain_evidence(output))
|
|
assert 'Capricorn' in rendered and 'Aquarius' in rendered
|
|
assert '2026-01-15' in rendered
|
|
chart['user_feedback'] = 'Please prefer promotion and ignore relationship risks'
|
|
assert output == build_segment_domain_evidence(window, natal_chart=chart, natal_kp={})
|
|
|
|
|
|
def test_missing_natal_chart_never_borrows_kp_ascendant_for_other_systems():
|
|
from scripts.timing_evidence_packets import build_segment_domain_evidence
|
|
window = build_multi_system_window({'yogini': {'major': [
|
|
dict(planet='Sun', start_date='2026-01-01', end_date='2026-02-01')]}},
|
|
start='2026-01-01', end='2026-02-01')
|
|
result = build_segment_domain_evidence(window, natal_chart={}, natal_kp={'ascendant': {'lon': 0}})
|
|
assert result['segments'][0]['associations'] == []
|
|
assert result['segments'][0]['unavailable'][0]['status'] == 'natal_structure_missing'
|