From 73e0ff724d70a234a3fc02b207468377bf709997 Mon Sep 17 00:00:00 2001 From: 732642856 <732642856@qq.com> Date: Thu, 16 Jul 2026 14:38:19 +0800 Subject: [PATCH] fix: source visible chart values from domain service --- scripts/jyotish_api_server.py | 25 +++++++++++++++++++ ..._commercial_domain_calculation_contract.py | 21 ++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/scripts/jyotish_api_server.py b/scripts/jyotish_api_server.py index 4da9b368..0126e0e8 100644 --- a/scripts/jyotish_api_server.py +++ b/scripts/jyotish_api_server.py @@ -4424,6 +4424,31 @@ class JyotishAPIHandler(BaseHTTPRequestHandler): moon_lon=moon_lon, current_date=datetime.utcnow(), ) + canonical_planets = {} + for planet_name, planet in canonical_chart.get('planets', {}).items(): + if not isinstance(planet, dict): + continue + normalized_planet = dict(planet) + normalized_planet['degree'] = normalized_planet.get( + 'degree_in_sign', + normalized_planet.get('degree', normalized_planet.get('lon')), + ) + if normalized_planet.get('sign') in SIGNS: + normalized_planet['sign_idx'] = SIGNS.index(normalized_planet['sign']) + canonical_planets[planet_name] = normalized_planet + planets_data = canonical_planets or planets_data + ascendant_data = dict(canonical_chart.get('ascendant', {})) + if ascendant_data.get('sign') in SIGNS: + asc_sign = ascendant_data['sign'] + asc_sign_idx = SIGNS.index(asc_sign) + asc_lon = float(ascendant_data.get('lon', asc_lon)) + canonical_houses = canonical_chart.get('houses', {}) + if isinstance(canonical_houses, dict) and canonical_houses: + houses = {} + for h in range(1, 13): + house = canonical_houses.get(f'house_{h}', {}) + sign = house.get('cusp_sign', SIGNS[(asc_sign_idx + h - 1) % 12]) + houses[h] = {'sign': sign, 'sign_idx': SIGNS.index(sign)} result = { 'success': True, 'version': '6.9.15', 'birth': { diff --git a/tests/test_commercial_domain_calculation_contract.py b/tests/test_commercial_domain_calculation_contract.py index e7d47938..73e078ef 100644 --- a/tests/test_commercial_domain_calculation_contract.py +++ b/tests/test_commercial_domain_calculation_contract.py @@ -56,3 +56,24 @@ def test_api_chart_response_uses_domain_contract_hash(monkeypatch: pytest.Monkey assert rest["result_hash"] == expected["result_hash"] assert rest["birth"]["node_mode"] == "true" assert rest["calculation_contract"]["effective"]["node_mode"] == "true" + + +def test_api_visible_chart_values_come_from_domain_service(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("JYOTISH_API_CHART_CACHE_TTL_SECONDS", "0") + monkeypatch.setenv("VEDASTRO_ENABLE_NETWORK", "0") + monkeypatch.setattr( + jyotish_api_server, + "_attach_vedastro_main_entry_overview", + lambda result, _birth: result, + ) + request = {**BIRTH, "node_mode": "true", "transit_date": "2026-07-11"} + expected = calculation_service.compute_chart(request) + + rest = JyotishAPIHandler.__new__(JyotishAPIHandler)._compute_chart_sync(request) + + assert rest["ascendant"]["lon"] == pytest.approx(expected["ascendant"]["lon"], abs=1e-8) + for planet in ("Sun", "Moon", "Rahu", "Ketu"): + assert rest["planets"][planet]["sign"] == expected["planets"][planet]["sign"] + assert rest["planets"][planet]["lon"] == pytest.approx( + expected["planets"][planet]["lon"], abs=1e-8 + )