From 9f5158c15deb0bca187aa0a8cc53fda331bbcdba Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 09:29:39 +0800 Subject: [PATCH] =?UTF-8?q?fix(yoga):=20her=20detect=20status=20layer=20?= =?UTF-8?q?=E2=80=94=20effect=5Fassessment=20and=20method=5Freview=20gates?= =?UTF-8?q?,=20row=20status=20fields,=20shared-lordship=20dependencies,=20?= =?UTF-8?q?blocked=20rows=20kept=20apart=20from=20yogas=20(BUG-2299)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DbBXp2U3BH1SxwAGyhhbe1 --- docs/BUG_HISTORY.md | 13 ++ references/yoga_rules.json | 86 +++++++-- scripts/yoga_engine.py | 185 +++++++++++++++++++- tests/test_upstream_r40_sync.py | 22 ++- tests/test_yoga_custom_branch_trace_2124.py | 5 +- tests/test_yoga_instances_gana_2075.py | 5 +- 6 files changed, 292 insertions(+), 24 deletions(-) diff --git a/docs/BUG_HISTORY.md b/docs/BUG_HISTORY.md index 57fedb605..e3455f4b5 100644 --- a/docs/BUG_HISTORY.md +++ b/docs/BUG_HISTORY.md @@ -31078,3 +31078,16 @@ - 影响(公开盘 Jobs / Obama):成立的格局不变;`bvr_bandhubhisthyaktha_precise`(Obama)从「不成立」变为条件资料不全(缺来源认可的 Shashtiamsa 性质)。 - 验证:新增她的 `test_yoga_output_guardrails`、`test_yoga_english_delivery_contract`、`test_yoga_degree_transport`(4 条走她改过的 `cmd_yoga` 的测试跳过并写明原因:jyotish_engine.py 封存);`test_handoff_2e5485f5_sync`、`test_yoga_evaluation_status_r3` 按原值 / 新值 / 原因更新。 - 修复版本:`claude/density-b3`。 + +## BUG-2299 | 格局引擎没有占星师的状态层:作用闸门(effect_assessment)、取法待核闸门(method_review)和逐条状态字段 + +- 状态:fixed-pending-verify。 +- 现象:信息密度第 3 批对照上游 58f37ee5b:本站 `YogaEngine.detect` 不处理她评估器返回的 `effect_assessment`(医疗、操守、伤害的历史参考,缓解条件已满足,条件不全),也不处理规则的 `method_review: pending`,匹配到的规则总是带着传统作用;没有 `formation_status` / `evidence_status` / `display_status` / `assertion_label` / `claim_boundary`、`evidence_dependencies`(同一颗星的多个宫主角色不算独立证据)和 `shared_fact_keys` / `overlapping_rule_ids`;求值失败的规则不在 `detect` 的结果里留行;本站规则表把她的 12 条 `method_review: pending` 全部丢了。 +- 修复(负责人批准改 yoga_engine.py): + - `detect` 照她的写法:每条规则先补她的英文登记(`english_delivery_fields`,规则自己的字段优先);匹配行按她的作用闸门处理:5 种状态下组合文字后接限定句,传统作用(中英两份)移到 `traditional_effects` / `traditional_effects_en`,`effects` 清空,强度改为 conditional;`method_review.pending` 同样处理并标 `method_requires_review`;Budha-Aditya 燃烧时英文作用也移走;随后写她的状态字段、`evidence_dependencies`、`shared_fact_keys` 和 `overlapping_rule_ids`。 + - 求值失败的规则照她的写法在 `detect` 结果里留一行 blocked 行(保留定义、出处和传统作用,不推断成立);产品入口 `detect_yogas` / `detect_yogas_with_status` 把 blocked 行拿出去,失败的规则照旧在 `evaluation_failures` / `unimplemented_rules`,`/api/yogas` 结构不变。 + - 规则表恢复她的 `method_review: pending`:kahala_yoga、mridanga_yoga、mridanga_yoga_variant、pushya_yoga、daridra_2、daridra_yoga_6、daridra_yoga_combined、daridra_yoga_2_lord_6_8_12、daridra_yoga_11_lord_6_8_12、bvr_bhratruvriddhi_precise、bvr_matrunasa_precise。另两处是公告的产品层:她给 `gajakesari` 的待核说明针对宽口径定义,本站 `gajakesari` 是 PVR 严格定义(BUG-1596/BUG-1624),宽口径是单独的 `gajakesari_strong_jupiter_variant`,待核放在后者;她的 matrunasa 待核覆盖 Raman 198 和 199,本站 199 是单列的 `bvr_matrunasa_199`(BUG-1616/BUG-1625),两条都带待核。两处都写了 `product_note`,需占星师确认。 + - 公告的产品层:她的每条匹配行都带 `card_eligible: false`;本站星盘页把 `card_eligible: false` 读作「暂无法判断」(BUG-2173),所以只在闸门生效或条件未全部满足的行上写 `card_eligible` / `card_status`,其余行不写。是否所有本地匹配都应「暂无法判断」,待占星师定。 +- 影响(公开盘):Jobs 的 bvr_matrunasa_precise、bvr_bhratruvriddhi_precise 由带作用变为取法待核、无作用;成立的格局不变。 +- 验证:`test_upstream_r40_sync::test_diagnostic_rows_never_enter_detected_yogas`(改为行为断言)、`test_yoga_instances_gana_2075`、`test_yoga_custom_branch_trace_2124`(求值抛条件不全时记录的结果为 None)按原值 / 新值 / 原因更新;2124/2170/1657/2075、Budha-Aditya、规则批次、P0、婚姻规则各测试通过。 +- 修复版本:`claude/density-b3`。 diff --git a/references/yoga_rules.json b/references/yoga_rules.json index 7ae717eac..ea51b8d0a 100644 --- a/references/yoga_rules.json +++ b/references/yoga_rules.json @@ -970,7 +970,14 @@ "strength_en": "weak", "enabled": true, "source_reference": "#166 Q5: a strong Jupiter (exalted / own / moolatrikona) substitutes for the benefic association; not the strict yoga. #166 2026-11-05 (BUG-1624): shown only when the strict definition (with the malefic-Mercury rule) does not hold.", - "bvr_chapter": "Chapter 1" + "bvr_chapter": "Chapter 1", + "method_review": { + "status": "pending", + "profile": "legacy_benefic_support_or_strong_jupiter", + "boundary": "Broad alternate definition, not the strict PVR definition. Combustion, enemy dignity and conditional Mercury support require adjudication.", + "source_locator": "PVR Integrated Approach, section 11.6, PDF pages 136-137; corpus lines 2766-2772", + "product_note": "BUG-2299: her pending review of the broad alternate Gajakesari definition (upstream 58f37ee5b rule gajakesari). Here that definition is this variant rule; the rule id gajakesari is the strict PVR definition (BUG-1596/BUG-1624) and carries no pending review." + } }, { "id": "moon_jupiter_kendra_relation", @@ -1681,7 +1688,12 @@ "strength_en": "moderate", "enabled": true, "source_reference": "BVR-15: L4 and L9 in mutual Kendras", - "bvr_chapter": "Chapter 2" + "bvr_chapter": "Chapter 2", + "method_review": { + "status": "pending", + "profile": "legacy_l4_l9_angular_l1_house_proxy", + "reason": "The implemented L4/L9 version is retained separately from the L4/Jupiter version. Angular/trinal placement is only a proxy for Lagna-lord strength; shared L4/L9 identity is not independent corroboration. Do not claim universal BPHS equivalence." + } }, { "id": "sankha_yoga", @@ -1770,7 +1782,12 @@ "strength_en": "strong", "enabled": true, "source_reference": "BVR-10: Planets in exaltation/own in Kendras", - "bvr_chapter": "Chapter 2" + "bvr_chapter": "Chapter 2", + "method_review": { + "status": "pending", + "profile": "legacy_kendra_trine_dignity", + "reason": "This predicate does not evaluate the exalted planet -> Navamsa sign lord chain described in Raman, Hindu Predictive Astrology, printed p.109, corpus lines 4588-4593. Preserve the matched structure, but do not present it as equivalent to that definition." + } }, { "id": "sreenatha_yoga", @@ -2473,7 +2490,11 @@ "strength": "弱", "strength_en": "weak", "enabled": true, - "dedup_key": "Daridra Yoga" + "dedup_key": "Daridra Yoga", + "method_review": { + "status": "pending", + "reason": "Exact source definition not located; preserve geometry, not a named poverty verdict." + } }, { "id": "gola_yoga", @@ -2985,7 +3006,12 @@ ], "strength": "强", "strength_en": "strong", - "enabled": true + "enabled": true, + "method_review": { + "status": "pending", + "profile": "legacy_benefics_8_9_12", + "reason": "This search did not establish a precise natal source for the two-benefics-in-8/9/12 predicate. Pushya nakshatra and electional references do not validate this named natal yoga. Retain the positions and conditional traditional interpretation." + } }, { "id": "raja_yoga_2_10", @@ -3967,7 +3993,11 @@ ], "strength": "弱", "strength_en": "weak", - "enabled": true + "enabled": true, + "method_review": { + "status": "pending", + "reason": "Exact source definition not located; preserve geometry, not a named poverty verdict." + } }, { "id": "daridra_yoga_combined", @@ -3996,7 +4026,11 @@ ], "strength": "弱", "strength_en": "weak", - "enabled": true + "enabled": true, + "method_review": { + "status": "pending", + "reason": "Exact source definition not located; preserve geometry, not a named poverty verdict." + } }, { "id": "surya_guru_yoga", @@ -5057,7 +5091,12 @@ "strength_en": "strong", "enabled": true, "source_reference": "BVR-10: Planets in exaltation/own in Kendras", - "bvr_chapter": "Chapter 2" + "bvr_chapter": "Chapter 2", + "method_review": { + "status": "pending", + "profile": "legacy_three_dignified_planets", + "reason": "Three dignified planets and a dignified Lagna lord do not establish the Navamsa-dispositor chain. Full was an unsupported superiority label; this variant is retained without outcome authority." + } }, { "id": "pancha_maha_yoga", @@ -7211,6 +7250,10 @@ 8, 12 ] + }, + "method_review": { + "status": "pending", + "reason": "Exact source definition not located; preserve geometry, not a named poverty verdict." } }, { @@ -7239,6 +7282,10 @@ 8, 12 ] + }, + "method_review": { + "status": "pending", + "reason": "Exact source definition not located; preserve geometry, not a named poverty verdict." } }, { @@ -11776,7 +11823,11 @@ "strength": "中", "strength_en": "moderate", "enabled": true, - "accuracy_note": "v6.0.42 source-parity: uses PyJHora natural benefics and preserves house.aspected_planets_of_the_planet() direction semantics." + "accuracy_note": "v6.0.42 source-parity: uses PyJHora natural benefics and preserves house.aspected_planets_of_the_planet() direction semantics.", + "method_review": { + "status": "pending", + "reason": "Received-aspect geometry repaired; separate planetary/house strength and whole-chart qualifications remain unresolved." + } }, { "id": "bvr_bandhubhisthyaktha_precise", @@ -11830,7 +11881,13 @@ "strength_en": "weak", "enabled": true, "accuracy_note": "定义来自 B.V. Raman 第 198 条(三种情况任一即成立);成立面很宽,区分度低,只作参考(#166 第 6 条)。凶星集合:太阳、火星、土星、罗睺、计都(夹制、同宫);相照只取太阳、火星、土星的具名行星相照。交点不给相照是保守的工程口径,待核;Raman 书的版本与页码待核(此前记录的第 188–190 页只是定位线索)。命中只是结构特征,不作母亲健康或寿命判断。", - "accuracy_note_en": "Definition from B.V. Raman no. 198 (any one of the three conditions); it holds widely and discriminates little; reference only (#166 Q6). Malefics: Sun, Mars, Saturn, Rahu, Ketu for hemming and conjunction; aspects only from Sun, Mars, Saturn (named graha aspects). Nodes casting no aspect is a conservative engineering choice, pending review; Raman edition and page pending (pp. 188-190 in earlier notes is a locator only). A hit is a structural feature, not a statement about the mother's health or life." + "accuracy_note_en": "Definition from B.V. Raman no. 198 (any one of the three conditions); it holds widely and discriminates little; reference only (#166 Q6). Malefics: Sun, Mars, Saturn, Rahu, Ketu for hemming and conjunction; aspects only from Sun, Mars, Saturn (named graha aspects). Nodes casting no aspect is a conservative engineering choice, pending review; Raman edition and page pending (pp. 188-190 in earlier notes is a locator only). A hit is a structural feature, not a statement about the mother's health or life.", + "method_review": { + "status": "pending", + "profile": "legacy_pyjhora_198_199_rasi_aspect_union", + "boundary": "Rules 198 and 199 are combined. Rasi versus graha aspects and node involvement remain unadjudicated; a structural match does not establish a maternal event.", + "source_locator": "Raman 198-199 transcription; original printed edition not verified" + } }, { "id": "bvr_matrunasa_199", @@ -11856,7 +11913,14 @@ "enabled": true, "accuracy_note": "定义来自 B.V. Raman 第 199 条;只作参考(#166 第 6 条)。Raman 书的版本与页码待核。命中只是结构特征,不作母亲健康或寿命判断。", "accuracy_note_en": "Definition from B.V. Raman no. 199; reference only (#166 Q6). Raman edition and page pending. A hit is a structural feature, not a statement about the mother's health or life.", - "canonical_mapping": "bvr_matrunasa_precise" + "canonical_mapping": "bvr_matrunasa_precise", + "method_review": { + "status": "pending", + "profile": "legacy_pyjhora_198_199_rasi_aspect_union", + "boundary": "Rules 198 and 199 are combined. Rasi versus graha aspects and node involvement remain unadjudicated; a structural match does not establish a maternal event.", + "source_locator": "Raman 198-199 transcription; original printed edition not verified", + "product_note": "BUG-2299: her pending review covers Raman 198 and 199 together (upstream rule bvr_matrunasa_precise); here 199 is its own rule (BUG-1616/BUG-1625), so it carries the same pending review." + } }, { "id": "bvr_nishkapata_precise", diff --git a/scripts/yoga_engine.py b/scripts/yoga_engine.py index 9637266b8..4fb67ad65 100644 --- a/scripts/yoga_engine.py +++ b/scripts/yoga_engine.py @@ -279,12 +279,14 @@ try: # scripts/ on sys.path _formation_logic as _upstream_formation_logic, assess_yoga_formation as _upstream_assess_yoga_formation, ) + from report_render.yoga_english_delivery import english_delivery_fields except ImportError: # package import (scripts.yoga_engine) from scripts.report_render.yoga_output_guardrails import ( # noqa: F401 - re-exported yoga_formation_contract, _formation_logic as _upstream_formation_logic, assess_yoga_formation as _upstream_assess_yoga_formation, ) + from scripts.report_render.yoga_english_delivery import english_delivery_fields def _formation_logic(value: Any) -> Any: @@ -941,6 +943,127 @@ class MissingYogaInput(YogaRuleEvaluationError): super().__init__("MissingYogaInput", field) +# BUG-2299 (upstream 58f37ee5b `detect`): the five effect statuses her source evaluators +# return; each keeps the structure and source but no traditional verdict as a personal result. +EFFECT_QUALIFICATIONS = { + 'source_neutralized': ('木星照射的缓解条件已满足;不据月土同宫判定言语性格。', + 'The source-neutralizing Jupiter aspect is present; do not infer a speech trait from the conjunction.'), + 'incomplete': ('影响表现的条件资料不全;结构记录不等于个人结论。', + 'Expression qualifiers have missing inputs; the structural match is not a personal conclusion.'), + 'historical_medical_reference': ('仅保留传统结构,不据此判断疾病、伤残或治疗结果。', + 'Historical structure only; no diagnosis, disability or treatment outcome is inferred.'), + 'historical_injury_reference': ('仅保留传统结构,不据此判断战争、伤害或死亡事件。', + 'Historical structure only; no war, injury or death event is established.'), + 'historical_conduct_reference': ('仅保留传统结构,不能据此认定本人或伴侣不忠。', + 'Historical structure only; no infidelity or personal conduct is established.'), +} +GATED_EFFECT_STATUSES = frozenset(EFFECT_QUALIFICATIONS) + + +def _withhold_effects(entry: Dict) -> None: + """Move the traditional effects (both languages) aside; the row states no verdict.""" + entry.setdefault('traditional_effects', entry.get('effects') or []) + entry['effects'] = [] + if entry.get('effects_en'): + entry.setdefault('traditional_effects_en', entry['effects_en']) + entry['effects_en'] = [] + entry['strength'] = 'conditional' + entry['strength_en'] = 'Conditional' + + +def _apply_effect_and_method_gates(entry: Dict, rule: Dict, match: Dict) -> None: + """Her `effect_assessment` and `method_review` gates, then her row status fields. + + BUG-2299 (upstream 58f37ee5b `detect`). Was: neither gate existed here; a matched + rule always carried its traditional effects. + """ + gated = False + assessment = match.get('effect_assessment') + if isinstance(assessment, dict) and assessment: + entry['effect_assessment'] = dict(assessment) + status = assessment.get('status') + if status in EFFECT_QUALIFICATIONS: + zh, en = EFFECT_QUALIFICATIONS[status] + zh = assessment.get('summary_zh', zh) + en = assessment.get('summary_en', en) + entry['effect_assessment'].update({'summary_zh': zh, 'summary_en': en}) + entry['combination'] = str(entry.get('combination') or '') + ';' + zh + if entry.get('combination_en'): + entry['combination_en'] = str(entry['combination_en']) + ' ' + en + _withhold_effects(entry) + gated = True + if rule.get('method_review'): + entry['method_review'] = dict(rule['method_review']) + if entry['method_review'].get('status') == 'pending': + # Preserve the matched structure and traditional claims without treating + # an unresolved method as adjudicated. + _withhold_effects(entry) + entry.setdefault('condition_status', 'method_requires_review') + gated = True + entry['formation_status'] = entry.get('condition_status', 'conditions_met') + entry['evidence_status'] = 'local_rule_match' + entry['display_status'] = 'candidate_review' + entry['assertion_label'] = 'single_system_inference' + entry['claim_boundary'] = ('Named rule conditions only; external validation and real-life ' + 'results are not established by detection.') + # Her rows all carry card_eligible=False. Product layer (announced, BUG-2299): the chart + # page reads card_eligible=False as 「暂无法判断」 (BUG-2173), so here it is set only on rows + # a gate restricted; whether every local match should read so is an open question for her. + if gated or entry['formation_status'] != 'conditions_met': + entry['card_eligible'] = False + entry['card_status'] = 'reference_only' + entry['card_block_reason'] = ( + 'Traditional yoga is detected by the local rule library; independent source/case ' + 'verification is still required before it can appear as a conclusion card.') + + +def _blocked_rule_row(rule: Dict, exc: BaseException, ctx: "YogaContext") -> Dict: + """Her failure row (upstream 58f37ee5b `detect`): neither formed nor ruled out.""" + failure_status = ('incomplete_conditions' if isinstance(exc, MissingYogaInput) + else 'not_implemented' if isinstance(exc, UnsupportedYogaCondition) + else 'evaluation_error') + return { + 'rule_id': rule.get('id', ''), 'name': rule.get('name', ''), + 'name_cn': rule.get('name_cn', ''), 'source': rule.get('source', ''), + 'category': rule.get('category') or 'unclassified_rule', + 'formation_status': failure_status, + 'condition_status': failure_status, + 'evidence_status': failure_status, + 'unsupported_conditions': getattr(exc, 'conditions', []), + 'missing_inputs': getattr(exc, 'fields', []), + 'display_status': 'blocked', 'assertion_label': 'blocked', + 'card_eligible': False, 'card_status': 'blocked', + 'effects': [], 'effects_en': [], 'planets': [], + 'strength': 'not_assessed', 'combination': '', + 'error_type': type(exc).__name__, + 'claim_boundary': 'Rule evaluation failed; no formation or outcome is inferred.', + # An unavailable predicate must not erase its reviewed definition/source or turn + # a source gap into absence. + 'source_reference': rule.get('source_reference', rule.get('source', '')), + 'combination_en': rule.get('combination_en', ''), + 'english_source_reference': rule.get('english_source_reference', ''), + 'traditional_effects': list(rule.get('effects') or []), + 'traditional_effects_en': list(rule.get('effects_en') or []), + 'source_method_notes': list(rule.get('source_method_notes') or []), + 'condition_evidence': { + 'rule_id': rule.get('id'), 'definition': rule.get('logic'), + 'source_reference': rule.get('source_reference', rule.get('source', '')), + 'execution_trace': list(getattr(ctx, 'condition_execution_trace', []) or []), + 'trace_scope': 'executed_condition_nodes_before_failure; not a successful evaluation', + 'participants': {}, + }, + } + + +BLOCKED_ROW_STATUSES = frozenset({'incomplete_conditions', 'not_implemented', 'evaluation_error'}) + + +def is_blocked_rule_row(row: Any) -> bool: + """True for a `detect` row that records a rule evaluation failure (BUG-2299).""" + return (isinstance(row, dict) and row.get('display_status') == 'blocked' + and row.get('formation_status') in BLOCKED_ROW_STATUSES) + + def evaluation_failure_row(rule: Dict, exc: BaseException) -> Dict: """The record of one rule that could not be evaluated on this chart.""" error_class = getattr(exc, "error_class", None) or type(exc).__name__ @@ -1606,6 +1729,21 @@ class YogaEngine: entry['formation_checks'] = checks entry['formation_assessment'] = assess_yoga_formation(entry) + # BUG-2299 (upstream 58f37ee5b): different lordship roles can refer to one + # physical planet. Preserve the literal rule match, but never count roles as + # independent witnesses. + shared = {p: [h for h in range(1, 13) if ctx.lord_of_house(h) == p] + for p in planets_bound} + cancellation = entry.get('formation_evidence') or {} + entry['evidence_dependencies'] = { + 'shared_lordships': {p: houses for p, houses in shared.items() if len(houses) > 1}, + 'participant_positions': {p: {'sign': ctx.sign_of(p), 'house': ctx.house_of(p)} + for p in planets_bound}, + 'self_reference_only': cancellation.get('self_reference_only'), + 'independent_confirmation_count': None, + 'claim_boundary': 'Shared planets, lordship roles and overlapping yoga names are not independent confirmations. Formation, strength, activation and outcome require separate assessment.', + } + supporting, limiting, contextual = [], [], [] unassessed = {'functional_benefic_malefic', 'Shadbala', 'Vimsopaka', 'aspect_strength', 'event_timing', 'composite_yoga_strength'} @@ -1661,15 +1799,22 @@ class YogaEngine: # 规则匹配。一条规则求值失败(异常)记为 evaluation_failed 并带错误类, # 不得静默当成不成立(占星师第三轮审查 2026-11-07)。 for rule in self.rules: + # BUG-2299 (upstream 58f37ee5b): her registry English for rules without their own + # English fields; the rule's own fields always win. + rule = dict(english_delivery_fields(rule), **rule) # BUG-2075 (upstream 19cfd9c0): receipt of the condition nodes this rule actually evaluated. ctx.condition_execution_trace = [] try: matches = self._eval_rule(rule, ctx) - except UnsupportedYogaCondition as exc: - unimplemented.append(_not_implemented_row(rule, exc.conditions)) - continue except Exception as exc: # noqa: BLE001 - recorded per rule, see evaluation_failure_row - failures.append(evaluation_failure_row(rule, exc)) + if isinstance(exc, UnsupportedYogaCondition): + unimplemented.append(_not_implemented_row(rule, exc.conditions)) + else: + failures.append(evaluation_failure_row(rule, exc)) + # BUG-2299 (upstream 58f37ee5b): failure is not evidence of absence or a formed + # yoga. Her blocked row stays in `detect`'s list; the product entry points + # (`detect_yogas`, `detect_yogas_with_status`) list it apart, as before. + results.append(_blocked_rule_row(rule, exc, ctx)) continue for m in matches: combination = m.get("combination", "") @@ -1705,6 +1850,9 @@ class YogaEngine: # BUG-2222 (upstream b6754475): where the traditional meaning comes from. if rule.get('meaning_source_reference'): entry['meaning_source_reference'] = rule['meaning_source_reference'] + # BUG-2299 (upstream 58f37ee5b): the English source line her renderers read. + if rule.get('english_source_reference'): + entry['english_source_reference'] = rule['english_source_reference'] entry['claim_kind'] = rule.get('claim_kind', 'named_yoga_candidate') for key in ('legacy_name', 'traditional_effects', 'traditional_effects_en'): if key in rule: @@ -1745,7 +1893,12 @@ class YogaEngine: entry['condition_status'] = 'combustion_requires_review' entry['traditional_effects'] = entry['effects'] entry['effects'] = [] + # BUG-2299 (upstream 58f37ee5b): the English twin moves too. + if entry.get('effects_en'): + entry['traditional_effects_en'] = entry['effects_en'] + entry['effects_en'] = [] entry['strength'] = 'conditional' + entry['strength_en'] = 'Conditional' entry['combustion_witness'] = { 'planet': 'Mercury', 'combust': True, @@ -1766,7 +1919,15 @@ class YogaEngine: entry['effects_en'] = [] entry['strength'] = 'conditional' entry['strength_en'] = 'Conditional' + _apply_effect_and_method_gates(entry, rule, m) self._attach_interpretive_evidence(entry, ctx) + # BUG-2299 (upstream 58f37ee5b): rules that name the lordships they rely on share + # fact keys, so overlapping rules are listed and never counted as independent votes. + roles = rule.get('evidence_lordship_houses', []) + if roles: + entry['evidence_dependencies']['shared_fact_keys'] = [ + f"D1:lord:{house}:{ctx.lord_of_house(house)}:house:{ctx.house_of(ctx.lord_of_house(house))}" + for house in roles] # BUG-2075 (upstream 19cfd9c0): names and prose are not identities. # Distinct rules or planetary witnesses may share both; collapse # only identical results, and never count variants as votes. @@ -1781,6 +1942,15 @@ class YogaEngine: # e628118d removed it. The precise rules count the same five planets # (BUG-1187 / BUG-1206), so nothing they ruled is lost. # ── 主检测器(同名 JSON 规则为 reference_only) ── + # BUG-2299 (upstream 58f37ee5b): rules sharing a lordship fact name each other. + for entry in results: + dependencies = entry.get('evidence_dependencies', {}) + keys = set(dependencies.get('shared_fact_keys', [])) + if keys: + dependencies['overlapping_rule_ids'] = sorted({ + other['rule_id'] for other in results if other is not entry and + keys.intersection(other.get('evidence_dependencies', {}).get('shared_fact_keys', []))}) + dependencies['independent_confirmation_count'] = None results += main_detector_rows(ctx.planets, ctx.ascendant) return results @@ -3475,7 +3645,8 @@ def detect_yogas(planets: Dict[str, Dict], ascendant: str, skill_dir = os.path.dirname(script_dir) rules_path = os.path.join(skill_dir, "references", "yoga_rules.json") engine = YogaEngine(rules_path) - return engine.detect(planets, ascendant, context=context) + # BUG-2299: her blocked rows are listed apart (`detect_yogas_with_status`), not as yogas. + return [row for row in engine.detect(planets, ascendant, context=context) if not is_blocked_rule_row(row)] def detect_yogas_with_status(planets: Dict[str, Dict], ascendant: str, @@ -3490,7 +3661,9 @@ def detect_yogas_with_status(planets: Dict[str, Dict], ascendant: str, script_dir = os.path.dirname(os.path.abspath(__file__)) rules_path = os.path.join(os.path.dirname(script_dir), "references", "yoga_rules.json") engine = YogaEngine(rules_path) - yogas = engine.detect(planets, ascendant, context=context) + # BUG-2299: her blocked rows (upstream 58f37ee5b) stay out of `yogas`; the same rules are in + # `evaluation_failures` / `unimplemented_rules`, so the /api/yogas shape is unchanged. + yogas = [row for row in engine.detect(planets, ascendant, context=context) if not is_blocked_rule_row(row)] failures = list(engine.last_evaluation_failures) unimplemented = list(engine.unimplemented_rules) + list(engine.last_unimplemented) return { diff --git a/tests/test_upstream_r40_sync.py b/tests/test_upstream_r40_sync.py index 30099817e..577d2f03f 100644 --- a/tests/test_upstream_r40_sync.py +++ b/tests/test_upstream_r40_sync.py @@ -45,11 +45,23 @@ def test_diagnostic_rows_keep_rule_category(): def test_diagnostic_rows_never_enter_detected_yogas(): from yoga_engine import YogaEngine - src = (ROOT / "scripts" / "yoga_engine.py").read_text(encoding="utf-8") - # 诊断行只追加到 unimplemented / failures,然后 continue,不会进入 results - assert "unimplemented.append(_not_implemented_row(rule, exc.conditions))\n continue" in src - assert "failures.append(evaluation_failure_row(rule, exc))\n continue" in src - assert YogaEngine + from yoga_engine import detect_yogas, detect_yogas_with_status, is_blocked_rule_row + + # 原值:读源码,断言诊断行只追加到 unimplemented / failures 后 continue + # 新值:detect 照上游 58f37ee5b 把她的 blocked 行留在自己的列表里;产品入口 detect_yogas / + # detect_yogas_with_status 把它们拿出去,yogas 里没有 blocked 行,失败的规则仍在 evaluation_failures + # 原因:BUG-2299 同步她的 detect 状态层 + planets = {"Moon": {"sign": "Cancer", "house": 4}, "Saturn": {"sign": "Cancer", "house": 4}} + engine = YogaEngine(str(ROOT / "references" / "yoga_rules.json")) + engine.rules = [{"id": "probe_missing_input", "name": "Probe", "name_cn": "探针", "effects": ["x"], + "logic": {"type": "custom", "expr": "vaiseshikamsa_score('Moon') > 5"}}] + rows = [row for row in engine.detect(planets, "Aries") if row.get("rule_id") == "probe_missing_input"] + assert len(rows) == 1 and is_blocked_rule_row(rows[0]) and rows[0]["formation_status"] == "incomplete_conditions" + assert rows[0]["effects"] == [] and rows[0]["traditional_effects"] == ["x"] + status = detect_yogas_with_status(planets, "Aries") + assert not any(is_blocked_rule_row(row) for row in status["yogas"]) + assert not any(is_blocked_rule_row(row) for row in detect_yogas(planets, "Aries")) + assert status["evaluation_failures"] def test_pvr_table30_is_a_separate_named_profile_and_virgo_matches_product(): diff --git a/tests/test_yoga_custom_branch_trace_2124.py b/tests/test_yoga_custom_branch_trace_2124.py index 359a7bdbc..a20f95490 100644 --- a/tests/test_yoga_custom_branch_trace_2124.py +++ b/tests/test_yoga_custom_branch_trace_2124.py @@ -196,7 +196,10 @@ def test_full_library_on_both_fixtures_keeps_every_rule_result(): def recording(expr, exec_globals, result, *args, traced=traced, seen=seen): record = traced(expr, exec_globals, result, *args) - seen.append((record, bool(result))) + # 原值:seen.append((record, bool(result))),假设每次自定义求值都有结果 + # 新值:求值抛出「条件资料不全」时 result 是 None,记录的 result 也必须是 None + # 原因:BUG-2298 照上游,缺来源定义的 Shashtiamsa / Vaiseshikamsa 抛 MissingYogaInput(Obama 的 bvr_nishkapata_precise) + seen.append((record, None if result is None else bool(result))) return record module._custom_branch_trace = recording diff --git a/tests/test_yoga_instances_gana_2075.py b/tests/test_yoga_instances_gana_2075.py index 7b52c6dd6..596aaa101 100644 --- a/tests/test_yoga_instances_gana_2075.py +++ b/tests/test_yoga_instances_gana_2075.py @@ -87,7 +87,10 @@ def test_synced_rules_carry_participants_expr_and_name_their_planets(): for name, (sign, degree) in places.items()} engine = YogaEngine(str(RULES_PATH)) rows = {row["rule_id"]: row for row in engine.detect(planets, "Scorpio")} - assert engine.last_evaluation_failures == [] + # 原值:last_evaluation_failures == [] + # 新值:只允许「条件资料不全」(缺来源认可的 Shashtiamsa 性质 / Vaiseshikamsa 方法) + # 原因:BUG-2298 照上游 58f37ee5b,这两项不再用 D60 星座吉凶或自造分数代替 + assert all(row["condition_status"] == "incomplete_conditions" for row in engine.last_evaluation_failures) assert rows["kahala_yoga"]["planets"] == ["Moon", "Mars", "Saturn"] assert rows["raja_yoga_mutual_aspect"]["planets"] == ["Moon", "Saturn"] assert rows["pushya_yoga"]["planets"] == ["Mercury", "Venus"]