Files
Jyotisha/tests/test_upstream_sync_ea2a9d65.py
T
ClaudeandClaude Opus 5.5 80bcfe1ed4 sync(upstream): method layer and calculation fixes from yinduzhanxing ea2a9d65
Product 2026-11-07: stay in sync with the astrologer's latest (5fb8379c..ea2a9d65).

- Method layer: mirror SKILL.md re-imported with import_yinduzhanxing.py from a
  clean ea2a9d65 clone (import record, manifest, import plan); root SKILL.md
  body equals the mirror again (nine-lord editorial reference line). Router and
  sub-skills unchanged upstream except her rectification skill, which is the
  protected commercial skill here.
- 7b43eaf2: rectification question templates say they are templates (basis,
  timing status, answer impact), no regression_hint +5 bias, low confidence
  cap, blocked/external execution status in the audit table, invalid answers
  ignored by the selector, calculation_profile echoed; API rejects a partial
  lat/lon/tz and event rectification without a place.
- a4b4b267: BPHS 27.19 Drik weighting readings as diagnostic variants in
  scripts/shadbala_reference/drik_profiles.py (shadbala.py is frozen, ERR-110;
  default quarter and BPHS piecewise geometry unchanged, BUG-1586 / BUG-1623);
  oracle audit compares rupa with rupa; VP Jain benchmark prints by default.
- bb26dc2d: /api/jaimini special mode carries the Goel fields, no invented
  Aries ascendant.
- d66d13ce: annual report exposes tajika_named_yoga_structures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
2026-11-07 18:12:32 +08:00

190 lines
8.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""产品 2026-11-07 同步占星师上游 ea2a9d65(yinduzhanxing 5fb8379c..ea2a9d65)。
Her tests for the ported calculation code, adapted where this repository keeps
a variant in a sidecar because the module is in the rectification frozen
identity (ERR-110): ``shadbala_reference.drik_profiles`` (her
``shadbala.drik_aspect_contribution`` / ``compare_drik_profiles``, a4b4b267).
Defaults the astrologer's rulings fixed are asserted unchanged.
"""
from __future__ import annotations
import pytest
from scripts import functional_benefics, jaimini, shadbala
from scripts.shadbala_reference import drik_profiles as drik
from scripts.active_rectification_questions import build_questionnaire, score_answers
from scripts.active_rectification_selector import select_next_questions
from scripts.jyotish_api_server import BadRequest, JyotishComputeService
SYNTHETIC = dict(Sun=29., Moon=58., Mars=87., Mercury=116.,
Jupiter=145., Venus=174., Saturn=203., Rahu=245., Ketu=65.)
def _handler() -> JyotishComputeService:
return JyotishComputeService()
def positions():
return dict(Saturn=85., Rahu=151., Sun=1., Moon=2., Mars=3.,
Mercury=4., Jupiter=5., Venus=6., Ketu=7.)
# --- 7b43eaf2: Arudha lord profile ---
# Already present here as the BUG-1626 reference module (astrologer #166 Q28:
# opt-in, not the default): scripts/arudha_reference/pvr_dual_lord.py, covered
# by tests/test_arudha_lord_selection_pvr.py. Her sample chart gives the same pick.
def test_her_pvr_sample_matches_existing_reference_module():
from scripts.arudha_reference import pvr_dual_lord
pick = pvr_dual_lord.select_pvr_arudha_lord(10, positions())
assert pick['winner'] == 'Rahu' and pick['deciding_level'] == 6 # degree rule, as hers
# --- 7b43eaf2: rectification input guards (her test_active_rectification_*) ---
@pytest.mark.parametrize('location', [{'lat': 0}, {'lat': 0, 'lon': 0}, {'lat': 0, 'lon': 0, 'tz': None}])
def test_question_api_rejects_incomplete_location(location) -> None:
with pytest.raises(BadRequest, match='supplied together'):
_handler()._compute_active_rectification_questions({
'birth_time': '2000-01-01 12:00', 'ayanamsa': 'lahiri', 'node_mode': 'mean', **location,
})
def test_question_api_preserves_explicit_node_profile() -> None:
result = _handler()._compute_active_rectification_questions({
'birth_time': '2000-01-01 12:00', 'ayanamsa': 'lahiri', 'node_mode': 'true',
})
assert result['calculation_profile'] == {'ayanamsa': 'lahiri', 'node_mode': 'true'}
def test_event_api_does_not_default_missing_location_to_zero() -> None:
with pytest.raises(BadRequest, match='required for event'):
_handler()._compute_active_rectification_events({
'birth_date': '2000-01-01', 'start_time': '12:00', 'end_time': '12:01',
'ayanamsa': 'lahiri', 'node_mode': 'mean', 'events': [],
})
def test_target_hint_cannot_bias_minute_priorities_or_claim_dasha_execution() -> None:
questionnaire = {
"question_bank": [],
"candidate_scan": {"minute_scan": {"rows": [
{"time": "2000-01-01 12:00", "sensitivity_count": 1},
{"time": "2000-01-01 12:01", "sensitivity_count": 2},
]}},
}
baseline = score_answers(questionnaire, {})
questionnaire["candidate_scan"]["regression_hint"] = {"target_minute": "12:00"}
hinted = score_answers(questionnaire, {})
assert hinted["minute_rankings"] == baseline["minute_rankings"]
assert hinted["minute_rankings"][0]["time"].endswith("12:01")
assert hinted["can_narrow_from_template_scores"] is False
vimshottari = next(row for row in hinted["technique_audit_table"] if row["technique"] == "Vimshottari Rectification")
assert vimshottari["status"] == "blocked"
def test_selected_template_retains_nonpersonal_timing_label() -> None:
report = build_questionnaire("2000-01-01 12:00", uncertainty_minutes=30)
assert report["questions"][0]["question_basis"] == "generic_interview_template"
assert report["questions"][0]["timing_claim_status"] == "not_individually_calculated"
assert "不提高、排除或确认" in report["questions"][0]["why_asked"][1]
assert "暂不缩小" in report["questions"][0]["answer_impact"]["A"]
def test_missing_cross_calculations_do_not_imply_executed_or_medium_confidence() -> None:
report = build_questionnaire("2000-01-01 12:00", uncertainty_minutes=30)
scored = score_answers(report, {report["questions"][0]["id"]: "A"})
assert all(row["confidence_cap"] == "low" for row in scored["candidate_cluster_rankings"])
assert all(row.get("execution_status", row["status"]) == "blocked" for row in scored["technique_audit_table"])
def test_invalid_answer_does_not_skip_a_question_or_penalize_its_domain() -> None:
questionnaire = build_questionnaire("2000-01-01 12:00", uncertainty_minutes=30)
first = questionnaire["questions"][0]["id"]
baseline = select_next_questions(questionnaire, {})
for invalid in ("", "E", "not an answer", None):
assert select_next_questions(questionnaire, {first: invalid}) == baseline
# --- 7b43eaf2 item 3: functional roles (her functional_benefics.py:34) ---
@pytest.mark.parametrize('lagna', ['Aries', 'Scorpio'])
def test_venus_is_a_functional_malefic_for_aries_and_scorpio(lagna):
assert 'Venus' in functional_benefics.derive_functional_benefic_malefic(lagna)['functional_malefics']
@pytest.mark.parametrize('lagna', ['Gemini', 'Virgo'])
def test_saturn_mixed_ruling_kept_over_upstream_table(lagna):
# Her table still makes Saturn a pure benefic here; the astrologer's #166 Q4
# ruling (BUG-1590) keeps it mixed in this product. Not regressed by the sync.
roles = functional_benefics.derive_functional_benefic_malefic(lagna)
assert 'Saturn' in roles['functional_neutrals']
assert 'Saturn' not in roles['functional_benefics']
# --- a4b4b267: Drik weighting readings (her test_shadbala_bphs_aspect_profiles.py) ---
@pytest.mark.parametrize('profile,want', [
('quarter_v1', 10), ('mercury_jupiter_full_replacement_v1', 40),
('santhanam27_literal_addition_v1', 50),
])
def test_weighting_40_virupas_is_applied_once(profile, want):
assert drik.drik_aspect_contribution(40, 'Jupiter', True, weighting_profile=profile) == want
def test_malefic_mercury_literal_addition_is_not_signed_125_percent():
assert drik.drik_aspect_contribution(40, 'Mercury', False,
weighting_profile='santhanam27_literal_addition_v1') == 30
assert drik.drik_aspect_contribution(40, 'Mercury', False,
weighting_profile='mercury_jupiter_full_replacement_v1') == -40
def test_directed_aspect_and_weighting_reach_drik_total():
# Her test names the geometry ``bphs26_piecewise_v1``; here it is the default
# ``bphs`` (BUG-1586). Jupiter 140 deg -> 60 - 20 = 40; literal addition = 50.
planets = {'Jupiter': {'degree': 0, 'sign': 'Aries'},
'Venus': {'degree': 140, 'sign': 'Leo'}}
assert drik.calc_drik_bala_profiled('Venus', planets,
weighting_profile='santhanam27_literal_addition_v1') == 50
assert drik.calc_drik_bala_profiled('Venus', planets) == shadbala.calc_drik_bala_precise('Venus', planets) == 10
def test_comparison_keeps_default_and_candidate_separate():
planets = {'Jupiter': {'degree': 0, 'sign': 'Aries'},
'Venus': {'degree': 140, 'sign': 'Leo'}}
report = drik.compare_drik_profiles(planets)
assert report['admission_state'] == 'diagnostic_only'
assert report['default'] == {'aspect_profile': 'bphs', 'weighting_profile': 'quarter_v1'}
assert len(report['variants']) == 6
baseline = shadbala.calc_drik_bala_precise('Venus', planets)
for variant in report['variants']:
assert variant['delta_from_default']['Venus'] == pytest.approx(
variant['virupas']['Venus'] - baseline)
assert report['variants'][2]['virupas']['Venus'] == 50
def test_unknown_weighting_profile_is_rejected():
with pytest.raises(ValueError, match='weighting'):
drik.calc_drik_bala_profiled('Venus', {'Venus': {'degree': 1, 'sign': 'Aries'}}, weighting_profile='guess')
# --- bb26dc2d: Goel evidence on the Jaimini special endpoint ---
def test_api_special_matches_native_entry():
from scripts.jyotish_engine import _goel_jaimini_evidence
result = _handler()._compute_jaimini({
'mode': 'special', 'ascendant': {'lon': 0.},
'planets': {p: {'lon': v} for p, v in SYNTHETIC.items()},
})['result']
native = _goel_jaimini_evidence(SYNTHETIC, 0.)
for field in native:
assert result[field] == native[field]
def test_api_does_not_invent_aries_ascendant_for_goel():
result = _handler()._compute_jaimini({
'mode': 'special', 'planets': {p: {'lon': v} for p, v in SYNTHETIC.items()},
})['result']
assert result['goel_full_strength']['status'] == 'blocked'
assert 'ascendant' in result['goel_full_strength']['reason']