"""产品 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']