"""占星师 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`); in this product that JSON rule is reference_only and the one Neecha Bhanga verdict comes from the main detector `yogas_doshas.calc_nicha_bhanga_raj_yoga` (BUG-1205), whose rows the rule engine appends as `main_detector:neecha_bhanga`. Same inputs, same assertions, on the detector the product runs. 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 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') == 'main_detector:neecha_bhanga' and r['formation_evidence']['planet'] == 'Jupiter') # BUG-2027(占星师 2026-11-19 对第 17 问的答复)改了下面五条的期望: # 原值:只命中「月亮在月亮起第 1 宫」时,落陷取消仍算成立(self_reference_only 为真、强度 moderate), # 有一条主检测器行。 # 新值:这种情况默认标签是落陷,没有行,也不作 Raja Yoga 候选的依据;字面命中和见证字段留在后台 # (calc 结果的 literal_only / neecha_bhanga_literal_only_notes)。另有有效条件时照旧成立, # 恒真条件照列但不计入条数和强度。 # 原因:她确认上游 `bool(reasons)` 让恒真条件单独进入取消和王者格候选判断,「仅记录标志不充分」; # 排除恒真分支是产品解释政策 neecha_bhanga_policy_v1,不是《Light on Life》原文的要求。 def literal_note(planets, planet='Jupiter'): from scripts.main_yoga_detectors import neecha_bhanga_literal_only_notes return next(note for note in neecha_bhanga_literal_only_notes(planets) if note['planet'] == planet) def has_row(planets, planet='Jupiter'): rows = YogaEngine(str(ROOT / 'references/yoga_rules.json')).detect(planets, 'Leo') return any(r.get('rule_id') == 'main_detector:neecha_bhanga' and r['formation_evidence']['planet'] == planet for r in rows) @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. planets = {'Jupiter': {'sign': 'Capricorn', 'house': 6}, 'Moon': {'sign': moon_sign, 'house': (SIGNS.index(moon_sign) - 4) % 12 + 1}} if has_row(planets): # The Moon is also in a kendra from the Lagna here: a real position condition. result = evidence(planets) witnesses = result['cancellation_reasons'] assert any(r['condition'] == 'exaltation_sign_lord_kendra_from_lagna' for r in witnesses) assert result['independent_condition_count'] == 1 and result['self_reference_only'] is False else: note = literal_note(planets) witnesses = note['literal_conditions'] assert note['tautology_only'] is True and note['default_rule_met'] is False witness = next(r for r in witnesses 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(): planets = {'Jupiter': {'sign': 'Capricorn', 'house': 6}, 'Moon': {'sign': 'Aries', 'house': 9}} assert not has_row(planets) note = literal_note(planets) # Not hidden: the literal hit, its source and the flag stay in the backstage record. assert note['raw_rule_met'] is True and note['tautology_only'] is True assert note['default_profile'] == 'light_on_life_p295' and note['policy'] == 'neecha_bhanga_policy_v1' # Not promoted: no formed row, and never the basis of a Raja Yoga candidate. assert note['default_rule_met'] is False and note['royal_yoga_candidate_allowed'] is False 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)]