From 5e48f18da0965c3ce10f852e52d62d55aa1170f6 Mon Sep 17 00:00:00 2001 From: 732642856 <732642856@qq.com> Date: Thu, 25 Jun 2026 23:38:16 +0800 Subject: [PATCH] fix: route synastry api through full ashtakoot engine --- scripts/jyotish_api_server.py | 16 ++++++++++++++-- tests/test_api_server_security.py | 17 ++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/scripts/jyotish_api_server.py b/scripts/jyotish_api_server.py index 42d10be5..c96ac870 100644 --- a/scripts/jyotish_api_server.py +++ b/scripts/jyotish_api_server.py @@ -1999,11 +1999,23 @@ class JyotishAPIHandler(BaseHTTPRequestHandler): } def _compute_synastry(self, body): - from synastry import calc_ashtakoot - return calc_ashtakoot( + from ashtakoot import calculate_ashtakoot + + result = calculate_ashtakoot( self._normalize_degree(body, 'male_moon', 0), self._normalize_degree(body, 'female_moon', 0), ) + # Backward-compatible aliases for older frontend/report consumers. + result['is_approved'] = result.get('is_match_approved', False) + result['assessment'] = ( + '优秀' if result.get('total_score', 0) >= 28 else + '良好' if result.get('total_score', 0) >= 21 else + '一般' if result.get('total_score', 0) >= 18 else + '不推荐' + ) + result['male'] = result.get('male_details', {}) + result['female'] = result.get('female_details', {}) + return result def _compute_dasha_system(self, body): dasha_key = body.get('dasha', body.get('name', 'vimshottari')) diff --git a/tests/test_api_server_security.py b/tests/test_api_server_security.py index b18196b4..964b4def 100644 --- a/tests/test_api_server_security.py +++ b/tests/test_api_server_security.py @@ -70,10 +70,25 @@ def test_synastry_rejects_non_numeric_moon_degree() -> None: def test_synastry_normalizes_360_degree_boundary() -> None: handler = _handler() result = handler._compute_synastry({'male_moon': 360, 'female_moon': 0}) - assert result['male']['nakshatra'] == result['female']['nakshatra'] + assert result['male_details']['nakshatra'] == result['female_details']['nakshatra'] assert result['max_score'] == 36.0 +def test_synastry_api_uses_full_ashtakoot_engine() -> None: + from ashtakoot import calculate_ashtakoot + + handler = _handler() + api_result = handler._compute_synastry({'male_moon': 0, 'female_moon': 60}) + engine_result = calculate_ashtakoot(0, 60) + + assert api_result['method'] == engine_result['method'] + assert api_result['scores'] == engine_result['scores'] + assert api_result['total_score'] == engine_result['total_score'] + assert api_result['is_match_approved'] == engine_result['is_match_approved'] + assert api_result['scores']['Vashya'] == 0.5 + assert 'BadConstellations' in api_result['additional_kutas'] + + def test_prashna_rejects_non_string_question() -> None: handler = _handler() with pytest.raises(BadRequest, match='question must be a string'):