Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp2U3BH1SxwAGyhhbe1
135 lines
8.3 KiB
Python
135 lines
8.3 KiB
Python
"""占星师 2026-11-08 第六轮 R3: Moon self-reference is visible and never independent confirmation.
|
||
|
||
Ported from her `tests/test_round6_self_reference.py` (yinduzhanxing 62791acb, 14 cases).
|
||
Her cases call `YogaEngine._eval_neecha_bhanga` (rule `neechabhanga_basic`); since BUG-2303
|
||
that rule decides Neecha Bhanga here too, so the first three cases are hers again. The last case
|
||
keeps the site's `calc_nicha_bhanga_raj_yoga` record (still used for the witness list).
|
||
Synthetic inputs, not event validation.
|
||
"""
|
||
from pathlib import Path
|
||
import sys
|
||
|
||
import pytest
|
||
|
||
ROOT = Path(__file__).resolve().parents[1]
|
||
for entry in (str(ROOT), str(ROOT / 'scripts')):
|
||
if entry not in sys.path:
|
||
sys.path.insert(0, entry)
|
||
|
||
from scripts.yoga_engine import YogaEngine, SIGNS # noqa: E402
|
||
from scripts.yogas_doshas import calc_nicha_bhanga_raj_yoga # noqa: E402
|
||
|
||
|
||
# BUG-2303 原值:这三条测本站 Neecha 主检测器(main_detector:neecha_bhanga)的行,月亮自参照单独时没有行
|
||
# 新值:照她 58f37ee5b 的原测试,测她的规则 neechabhanga_basic 的行:月亮自参照照列、标 self_reference_only,
|
||
# 不作独立印证、不作王者候选;本站的状态层(neecha_witness)把它读作 self_reference_only,标签仍是落陷
|
||
# 原因:负责人 2026-11-24 同意 Neecha Bhanga 由她的规则判定,本站 Neecha 主检测器退役
|
||
def evidence(planets):
|
||
rows = YogaEngine(str(ROOT / 'references/yoga_rules.json')).detect(planets, 'Leo')
|
||
return next(r['formation_evidence'] for r in rows
|
||
if r.get('rule_id') == 'neechabhanga_basic'
|
||
and r['formation_evidence']['planet'] == 'Jupiter')
|
||
|
||
|
||
@pytest.mark.parametrize('moon_sign', SIGNS)
|
||
def test_jupiter_moon_self_reference_is_visible_for_every_moon_sign(moon_sign):
|
||
# Jupiter's exaltation sign is Cancer, ruled by Moon. Moon from itself
|
||
# is always H1; moving Moon cannot create independent corroboration.
|
||
result = evidence({'Jupiter': {'sign': 'Capricorn', 'house': 6},
|
||
'Moon': {'sign': moon_sign, 'house': (SIGNS.index(moon_sign)-4) % 12+1}})
|
||
witness = next(r for r in result['cancellation_reasons']
|
||
if r['condition'] == 'exaltation_sign_lord_kendra_from_moon')
|
||
assert witness['self_reference'] is True
|
||
assert witness['independent_confirmation_allowed'] is False
|
||
assert witness['reference'] == 'Moon'
|
||
assert witness['relative_house'] == 1
|
||
|
||
|
||
def test_self_reference_only_is_not_hidden_or_promoted_to_nonself_support():
|
||
result = evidence({'Jupiter': {'sign': 'Capricorn', 'house': 6},
|
||
'Moon': {'sign': 'Aries', 'house': 9}})
|
||
assert result['self_reference_only'] is True
|
||
assert result['royal_yoga_candidate'] is False
|
||
assert result['profile'] == 'light_on_life_p295'
|
||
|
||
|
||
def test_distinct_geometric_condition_survives_beside_self_reference():
|
||
result = evidence({'Jupiter': {'sign': 'Capricorn', 'house': 6},
|
||
'Moon': {'sign': 'Aries', 'house': 9},
|
||
'Saturn': {'sign': 'Leo', 'house': 1}})
|
||
assert result['self_reference_only'] is False
|
||
assert any(r['condition'] == 'dispositor_kendra_from_lagna'
|
||
for r in result['cancellation_reasons'])
|
||
assert any(r.get('self_reference') for r in result['cancellation_reasons'])
|
||
|
||
|
||
def test_literal_branch_alone_is_not_formed_and_self_reference_does_not_raise_strength():
|
||
# The literal hit is kept as evidence, but alone it no longer forms the cancellation.
|
||
result = calc_nicha_bhanga_raj_yoga({'Jupiter': {'sign': 'Capricorn', 'house': 6},
|
||
'Moon': {'sign': 'Aries', 'house': 9}}, {})
|
||
assert result['yogas'] == []
|
||
only = result['literal_only'][0]
|
||
assert only['planet'] == 'Jupiter' and only['tautology_only'] is True
|
||
assert only['default_rule_met'] is False and only['raw_rule_met'] is True
|
||
assert [c['condition'] for c in only['literal_conditions']] == ['exaltation_sign_lord_kendra_from_moon']
|
||
# Mars debilitated in Cancer: dispositor Moon from the Moon is the same tautology.
|
||
mars = calc_nicha_bhanga_raj_yoga({'Mars': {'sign': 'Cancer', 'house': 12},
|
||
'Moon': {'sign': 'Taurus', 'house': 10}}, {})['yogas'][0]
|
||
witness = next(c for c in mars['cancellation_conditions'] if c['condition'] == 'dispositor_kendra_from_moon')
|
||
assert witness['self_reference'] is True and witness['independent_confirmation_allowed'] is False
|
||
lagna = next(c for c in mars['cancellation_conditions'] if c['condition'] == 'dispositor_kendra_from_lagna')
|
||
assert lagna['self_reference'] is False and 'independent_confirmation_allowed' not in lagna
|
||
assert mars['independent_cancellation_count'] == mars['cancellation_count'] - 1
|
||
assert mars['self_reference_only'] is False and mars['strength'] == 'moderate'
|
||
|
||
|
||
def test_card_layer_carries_the_witness_fields():
|
||
from scripts.main_yoga_detectors import neecha_bhanga_rows
|
||
|
||
# Tautology only: no row reaches the card layer.
|
||
assert neecha_bhanga_rows({'Jupiter': {'sign': 'Capricorn', 'house': 6},
|
||
'Moon': {'sign': 'Aries', 'house': 9}}) == []
|
||
# Beside a real condition the tautological witness is still carried, flagged.
|
||
row = neecha_bhanga_rows({'Jupiter': {'sign': 'Capricorn', 'house': 6},
|
||
'Moon': {'sign': 'Aries', 'house': 9},
|
||
'Saturn': {'sign': 'Leo', 'house': 1}})[0]
|
||
assert row['formation_evidence']['self_reference_only'] is False
|
||
assert row['formation_evidence']['independent_condition_count'] == 1
|
||
assert len(row['conditions']) == 1 and '月亮在月亮起' not in row['combination']
|
||
reason = next(r for r in row['formation_evidence']['cancellation_reasons'] if r.get('self_reference'))
|
||
assert {k: reason[k] for k in ('reference', 'relative_house', 'self_reference',
|
||
'independent_confirmation_allowed')} == {
|
||
'reference': 'Moon', 'relative_house': 1, 'self_reference': True,
|
||
'independent_confirmation_allowed': False}
|
||
|
||
|
||
def test_witness_fields_survive_the_real_pipeline_compact_and_row_cap():
|
||
"""BUG-1786 补(round-7 integration 2026-11-08):公开盘 Zidane(火星落陷巨蟹,定位星月亮)
|
||
与 Obama(木星落陷,擢升星座主星月亮)的 Neecha Bhanga 行在主检测器里带见证字段,但
|
||
`_compact_yoga_entry` 把 formation_evidence 压掉了,且该行排在第 45 位,被 `rows[:30]` 截掉,
|
||
卡上的 yogas_detail 没有这一行。这里用同样的形状(火星落陷巨蟹、月亮为定位星)走压缩 → 筛 → 卡层。"""
|
||
from scripts.consultation_native_layers import build_yoga_conditions
|
||
from scripts.jyotish_api_server import _compact_yoga_entry
|
||
from scripts.main_yoga_detectors import neecha_bhanga_rows
|
||
|
||
planets = {'Mars': {'sign': 'Cancer', 'house': 12}, 'Moon': {'sign': 'Taurus', 'house': 10}}
|
||
compact = _compact_yoga_entry(neecha_bhanga_rows(planets)[0])
|
||
evidence = compact['formation_evidence']
|
||
moon = next(r for r in evidence['cancellation_reasons'] if r['condition'] == 'dispositor_kendra_from_moon')
|
||
assert moon == {'condition': 'dispositor_kendra_from_moon', 'planet': 'Moon', 'reference': 'Moon',
|
||
'relative_house': 1, 'self_reference': True, 'independent_confirmation_allowed': False}
|
||
assert evidence['independent_condition_count'] == len(evidence['cancellation_reasons']) - 1
|
||
assert evidence['self_reference_only'] is False
|
||
|
||
# 原值:45 条填充行,卡层只留 30 行,主检测器行让出末尾一行后保留
|
||
# 新值:这一层不再截行(BUG-1967),46 行按原顺序全留,主检测器行在最后
|
||
# 原因:占星师 2026-11-17 第二批第三节第 2 条:不能把前 30 行当全量,按领域选行由卡做
|
||
filler = [{'name': f'Filler Yoga {i}', 'planets': ['Sun']} for i in range(45)]
|
||
modules = {'raman_support': {'yogas': {'status': 'executed', 'hits': [], 'ungoverned_detected': filler + [compact]}}}
|
||
rows = build_yoga_conditions({'planets': planets}, modules, {})['rows']
|
||
assert len(rows) == 46
|
||
neecha = next(row for row in rows if row['name'] == 'Neecha Bhanga')
|
||
assert neecha['formation_evidence'] == evidence
|
||
# The ordinary rows keep their order and none gives way.
|
||
assert [row['name'] for row in rows[:-1]] == [f'Filler Yoga {i}' for i in range(45)]
|