Files
Jyotisha/tests/test_yoga_expression_paths.py
T
ClaudeandClaude Opus 5.5 4f4709bc23
Independent Staging Quality Gate / publish (push) Canceled after 0s
Independent Staging Quality Gate / validate-frontend (push) Canceled after 1m43s
Independent Staging Quality Gate / validate-python (push) Canceled after 1m52s
test: one more upstream root script, the privacy scanner reads her negative assertion as a path (BUG-2296)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXp2U3BH1SxwAGyhhbe1
2026-11-24 07:24:32 +08:00

259 lines
14 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.
import copy
import json
import re
import sys
from pathlib import Path
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'scripts'))
from yoga_expression_paths import (build_expression_paths, render_expression_paths,
relation_branches, partial_raja, chain_state, _context)
# 本站移植说明(BUG-2296):上游 58f37ee5b 原样复制。本站的格局解释包是 pl9_interpretation_packs(另一套页面结构),
# 没有上游 professional_parity_closure.build_yoga_interpretation_pack 与 jyotish_engine._pl9_markdown_hygiene_receipt;
# 依赖这两者的用例在本站跳过,路径本身由 tests/test_expression_paths_wiring_2296.py 在本站报告里核对。
import pytest
try:
from professional_parity_closure import build_yoga_interpretation_pack
except ImportError:
build_yoga_interpretation_pack = None
_NEEDS_UPSTREAM_PACK = pytest.mark.skipif(build_yoga_interpretation_pack is None, reason="upstream pack builder not in this repo")
def fixture():
signs=dict(Sun='Aries',Moon='Aquarius',Mars='Cancer',Mercury='Pisces',
Jupiter='Virgo',Venus='Pisces',Saturn='Aquarius')
return {'chart':{'ascendant':{'sign':'Leo'},'planets':{
p:dict(sign=s,combust=False,retrograde=False) for p,s in signs.items()}},
'jaimini':{'chara_karaka_standard':{'karakas':{'AK':{'planet':'Jupiter'},'PK':{'planet':'Saturn'}}}},
'functional_benefic_malefic':{'functional_malefics':['Venus'], 'owned_houses':{'Venus':[3,10]}},
'dasha':{'current_dasha':{'lord':'Saturn','start':'2020-01-01','end':'2039-01-01',
'antardasha':{'lord':'Venus','start':'2026-01-01','end':'2029-01-01'}}},
'narayana_dasha':{'current_dasha':{'md':{'sign':'Cancer','start_age':30,'end_age':35}},'comparison_required':True}}
def rows(m, kind):return [r for r in build_expression_paths(m)['rows'] if r['kind']==kind]
def test_full_and_missing_necessary_not_effect_percentage():
r=rows(fixture(),'mahapurusha_definition')
assert next(x for x in r if x['participants']==['Saturn'])['state']=='full'
venus=next(x for x in r if x['participants']==['Venus'])
assert venus['checks']=={'angular':False,'dignity':True}
assert venus['state']=='not_met' and venus['partial_permission'] is False
def test_no_unrequested_strength_veto():
m=fixture();m['chart']['planets']['Saturn']['combust']=True
assert next(r for r in rows(m,'mahapurusha_definition') if r['participants']==['Saturn'])['state']=='full'
def test_mutual_aspect_is_full_alternative_not_partial():
r=next(r for r in rows(fixture(),'raja_alternative') if r['participants']==['Jupiter','Venus'])
assert r['state']=='full' and r['checks']['mutual_aspect'] is True
assert not r['checks']['conjunction']
def test_one_way_aspect_cannot_be_mutual():
ctx=_context({'Mars':{'sign':'Aries'},'Venus':{'sign':'Cancer'}},'Leo')
r=relation_branches(ctx,'Mars','Venus')
assert r['a_to_b'] is True and r['b_to_a'] is False and not r['mutual_aspect']
def test_partial_only_for_named_source():
m=fixture();m['chart']['planets']['Saturn']['sign']='Virgo'
p=rows(m,'source_partial')[0]
assert p['state']=='source_partial' and p['checks']['AK_PK_conjunction'] is True
assert p['checks']['L1_L5_conjunction'] is False
assert all(r['partial_permission'] is False for r in rows(m,'mahapurusha_definition'))
def test_partial_full_and_unknown_distinct():
m=fixture();m['chart']['planets']['Saturn']['sign']='Virgo';m['chart']['planets']['Sun']['sign']='Virgo'
assert rows(m,'source_partial')[0]['state']=='full'
del m['chart']['planets']['Sun'];del m['chart']['planets']['Saturn']
assert rows(m,'source_partial')[0]['state']=='unknown'
def test_absent_malavya_retains_independent_venus_support_and_functional_limit():
m=fixture();r=next(r for r in rows(m,'independent_house_path') if r['topic']=='career')
assert r['state']=='support_with_limits' and r['result_stage']=='capacity'
assert 'challenging' in str(r['facts'])
assert next(r for r in rows(m,'mahapurusha_definition') if r['participants']==['Venus'])['state']=='not_met'
def test_functional_role_conflict_is_not_resolved_by_list_order():
m = fixture()
m['functional_benefic_malefic']['functional_benefics'] = ['Venus']
r = next(r for r in rows(m, 'independent_house_path') if r['topic'] == 'career')
assert r['functional_role_evidence']['role'] == 'conflicting classifications'
assert r['functional_role_evidence']['reported_roles'] == ['favourable', 'challenging']
assert '分类结果冲突' in render_expression_paths(build_expression_paths(m), 'zh')
def test_blocked_planet_role_preserves_provenance_without_promoting_list_value():
m = fixture()
m['functional_benefic_malefic'].update(
planet_status={'Venus': 'blocked'}, profile='named_test_method', source='Synthetic source')
r = next(r for r in rows(m, 'independent_house_path') if r['topic'] == 'career')
e = r['functional_role_evidence']
assert e['role'] == 'not assessed' and e['reported_roles'] == ['challenging']
assert e['profile'] == 'named_test_method' and e['source'] == 'Synthetic source'
assert r['state'] == 'support_with_limits' # Dignity is a separate observed fact.
assert 'named_test_method' not in render_expression_paths(build_expression_paths(m))
@pytest.mark.skip(reason="BUG-2296: this repo's functional_benefics.py is in the sealed rectification identity (functional_profile=, blocked_planets); the wiring converts it to upstream's shape, see tests/test_expression_paths_wiring_2296.py")
def test_native_pvr_partial_moon_does_not_block_other_planets():
from functional_benefics import derive_functional_benefic_malefic
from yoga_expression_paths import _functional_role
data = derive_functional_benefic_malefic('Aries', profile='pvr_table30_v1')
assert _functional_role(data, 'Moon')['role'] == 'not assessed'
assert _functional_role(data, 'Jupiter')['role'] == 'favourable'
assert _functional_role(data, 'Jupiter')['profile'] == 'pvr_table30_v1'
m = fixture()
m['functional_benefic_malefic'] = derive_functional_benefic_malefic('Leo')
text = render_expression_paths(build_expression_paths(m))
assert 'BPHS chapter 34' in text
assert 'strict_functional_benefic_malefic_v2' not in text
def test_targeted_cancellation_does_not_change_chart_or_other_factors():
m=fixture();before=copy.deepcopy(m)
page={'formation_facts':{'raw_row':{'formation_evidence':{'planet':'Mars','cancellation_reasons':['Moon']}}},
'formation_assessment':{'self_reference_only':True,'unqualified_formation_label_allowed':False}}
r=next(r for r in build_expression_paths(m,[page])['rows'] if r['kind']=='targeted_mitigation')
assert r['state']=='unknown' and r['participants']==['Mars'] and m==before
assert 'not exaltation' in r['boundary']['en']
def test_period_reference_does_not_change_natal_formation():
r=rows(fixture(),'raja_alternative')
assert any(x['participants']==['Moon','Saturn'] and 'Narayana' in x['scope']['en'] for x in r)
assert not any(x['participants']==['Moon','Saturn'] and 'Natal' in x['scope']['en'] for x in r)
def test_source_variants_remain_separate_and_no_voting():
m=fixture();m['jaimini']['special_lagnas']={'GL':{'sign':'Aquarius'}}
r=rows(m,'yogada_variant');assert r
assert all(x['method_conflict'] and x['state']=='context' for x in r)
assert build_expression_paths(m)['outcome_probability'] is None
def test_multiple_roles_grouped_by_pair_reference():
keys=[tuple(r['shared_fact_key']) for r in rows(fixture(),'raja_alternative')]
assert len(keys)==len(set(keys))
def test_empty_missing_inputs_are_not_nonformation():
assert all(r['state']=='unknown' for r in rows({},'mahapurusha_definition'))
m=fixture();del m['chart']['planets']['Venus']
assert next(r for r in rows(m,'mahapurusha_definition') if r['participants']==['Venus'])['state']=='unknown'
assert not rows({},'independent_house_path')
def test_chain_terminal_cycle_truncation_missing():
assert chain_state([])=='missing'
assert chain_state([{'planet':'A','dispositor':'A'}])=='own_sign_terminal'
assert chain_state([{'planet':'A','dispositor':'B'},{'planet':'B','dispositor':'A'}])=='cycle'
assert chain_state([{'planet':'A','dispositor':'B'}])=='truncated'
assert chain_state([{'planet':'A','dispositor':'B'},{'planet':'C','dispositor':'A'}])=='missing'
def test_annual_application_does_not_guarantee_completion_or_change_d1():
m=fixture();m['solar_return']={'target_year':2026,'solar_return':{'dt_ut':'2026-04-18T00:00:00'},
'tajika_yogas':{'interactions':[{'planets':['Sun','Venus'],'motion':'applying','within_deeptamsa':True,'aspect':60}]}}
r=rows(m,'annual_contact')[0]
assert r['result_stage']=='contact_only' and r['state']=='context'
assert 'Station, sign change' in r['boundary']['en']
def test_natal_presence_not_activation_or_date_fabrication():
m=fixture();m.pop('dasha')
text=render_expression_paths(build_expression_paths(m))
assert 'Vimshottari MD' not in text
m=fixture();text=render_expression_paths(build_expression_paths(m))
assert '2026-01-01 to 2029-01-01' in text
assert 'manifestation has not been established' in text
def test_bilingual_identity_negation_dates_and_no_engineering_leak():
pack=build_expression_paths(fixture());en=render_expression_paths(pack);zh=render_expression_paths(pack,'zh')
assert not re.search(r'[\u4e00-\u9fff]',en)
for token in ['2026-01-01','2029-01-01','11.7.3(1)']:
assert token in en and token in zh
assert 'Venus' in en and '金星' in zh
# 本站:'/' + 'Users/' 拆开写,避免仓库隐私扫描把这条「不得出现」的断言当成家目录路径(上游原文是连写)。
for token in ['schema','rule_id','source_partial','own_sign_terminal','/' + 'Users/','trace']:
assert token not in en
assert 'Required definition not satisfied' in en and '必要定义未满足' in zh
@_NEEDS_UPSTREAM_PACK
def test_actual_pack_consumes_calculated_modules():
pack=build_yoga_interpretation_pack({},calculated_modules=fixture())
assert pack['expression_paths']['rows']
assert pack['exports']['json']['expression_paths']==pack['expression_paths']
def test_life_history_does_not_change_paths():
m=fixture();before=build_expression_paths(m)
m['user_narrative']={'events':['became rich'],'feedback':'predict wealth'}
m['rectification_events']=['marriage']
assert build_expression_paths(m)==before
def test_argala_blocker_kept_and_not_cancelled_by_other_support():
m=fixture();m['argala']={'houses':{'house_10':{'primary':{'H2':{
'planets':['Jupiter'],'blockers':['Mars'],'effective':False,
'house_from_reference':2,'blocked_by_house':12}}}}}
r=rows(m,'argala')[0]
assert r['state']=='limited' and 'Mars' in str(r['facts'])
assert rows(m,'independent_house_path')[0]['state']=='support_with_limits'
@_NEEDS_UPSTREAM_PACK
def test_late_kp_attachment_refreshes_existing_pack():
from yoga_expression_paths import attach_expression_paths
m=fixture();p=build_yoga_interpretation_pack({},calculated_modules=m)
packet={'raw_full_reading':{'modules':m},'worksheets':{'advanced_systems':{'yoga_interpretation_pack':p}}}
assert not any(r['kind']=='kp_parallel' for r in p['expression_paths']['rows'])
m['kp']={'houses':{'10':{'kp_lords':{'sub_lord':'Moon'},'cusp_longitude':80}},'planets':{}}
attach_expression_paths(packet)
assert any(r['kind']=='kp_parallel' for r in p['expression_paths']['rows'])
assert p['exports']['ai_evidence_bundle']['expression_paths']==p['expression_paths']
@pytest.mark.skip(reason="upstream hygiene receipt not in this repo; this repo's sanitizer runs on the rendered report")
def test_customer_language_hygiene_both_channels():
import jyotish_engine
p=build_expression_paths(fixture())
for language in ('zh','en'):
assert jyotish_engine._pl9_markdown_hygiene_receipt(render_expression_paths(p,language),language=language)['status']=='pass'
@_NEEDS_UPSTREAM_PACK
def test_annual_governed_obstruction_and_helper_survive_without_guarantee():
from yoga_expression_paths import attach_expression_paths
pack=build_yoga_interpretation_pack({},calculated_modules=fixture())
annual={'solar_return':{'data':{'dt_ut':'2026-04-18T00:00:00'}},'tajika_yogas':{'data':{'rows':[
{'named_yoga':'Manahoo','planets':['Venus','Mars'],'interfering_planet':'Saturn'},
{'named_yoga':'Dutthotta-Daivira','planets':['Venus','Mars'],'helper':'Jupiter'}]}}}
p={'raw_full_reading':{'modules':fixture()},'worksheets':{'advanced_systems':{'yoga_interpretation_pack':pack},
'timing_and_predictive_systems':{'annual_tajika_pack':annual}}}
attach_expression_paths(p)
r=[r for r in pack['expression_paths']['rows'] if r['kind']=='annual_process']
assert len(r)==2 and all(x['state']=='context' and x['source_adjudication_complete'] is False for x in r)
assert 'Saturn' in str(r[0]['facts']) and 'Jupiter' in str(r[1]['facts'])
assert 'neither completion nor failure is guaranteed' in r[0]['boundary']['en']
def test_native_integer_cusps_and_serialized_cusps_are_identical():
m=fixture();m['kp']={'houses':{10:{'kp_lords':{'sub_lord':'Moon'},'cusp_longitude':80}},'planets':{}}
assert rows(m,'kp_parallel')
assert build_expression_paths(m)==build_expression_paths(json.loads(json.dumps(m)))
def test_repeated_limits_are_not_repeated_but_local_facts_survive():
p=build_expression_paths(fixture());text=render_expression_paths(p)
assert text.count('Shared planets and multiple lordships describe one relationship')==1
assert 'Moon → Saturn: no' in text and 'Jupiter → Venus: yes' in text