fix: source visible chart values from domain service

This commit is contained in:
732642856
2026-07-16 14:38:19 +08:00
parent 3f0d5791dc
commit 73e0ff724d
2 changed files with 46 additions and 0 deletions
+25
View File
@@ -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': {
@@ -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
)