fix(yoga): Rohini gana is Manushya; the engine keeps distinct instances and records executed conditions; 19 rules name their participants (BUG-2075)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq
This commit is contained in:
2026-11-20 15:45:51 +08:00
co-authored by Claude Fable 5.2
parent ddc8c3fc17
commit 2245b163f4
9 changed files with 337 additions and 20 deletions
+14
View File
@@ -28038,3 +28038,17 @@
- 验证与防复发:`frontend/tests/report-questions-2081.test.tsx`(10 条):待问对象的三种状态和关闭按钮;整份报告的开场句;复测里那段回答变成固定一句且只调一次模型,答了一部分的不受影响;追问指令里的三处确实是主问答原文的子串;术语清单、用户点名的例外、三句真实的推责句被去掉、有术语时只重写一次;计数;外壳刷新;「现实建议」的入口、绑定、材料和可圈选文字;选区条的五种位置;三处中性底色。按原值 / 新值 / 原因更新:`report-questions-2073`、`synastry-report-chat`、`synastry-followup-2026`、`synastry-full-report`、`reports-redesign-1631`。
- 关联记录:BUG-2073、BUG-2080、BUG-2026、BUG-2023、BUG-2029、BUG-2001、BUG-2059(选中用中性底色)。
- 修复版本:`claude/report-questions-2081`。
## BUG-2075 | Rohini 的 Gana 记成了天神;格局引擎按「名字加说明」去重会吞掉不同的规则和不同行星的实例;不少格局列不出参与行星
- 状态:fixed-pending-verify(待测试环境重新生成报告确认)。
- 首次发现 / 最近更新:2026-11-20 / 2026-11-20。
- 触发与现象:(1) 报告的星宿参考表里,行星落在 Rohini 时 Gana 写「天神」。(2) 引擎层按「去重键或名字 + 组合说明」合并结果:两条不同的规则只要说明文字相同就只剩一条(例如太阳入 7 宫同时满足的两条规则),同一规则对两组行星成立时也只剩一条。(3) 报告的「瑜伽参与行星」表里 Kahala、Mridanga、Pushya、相互照射的 Raja Yoga 等写「规则未单列」,也就无法和当前大运主星比对。占星师 2026-11-20 在自己的仓里修了同样的问题(提交 19cfd9c0、0d6626f2),并在十四问答复的第 6、10 问和 A6、B9 里给了口径。
- 触发条件:任何盘;第 (1) 条需有行星落在 Rohini。
- 根因:(1) `nakshatra_advanced.NAK_GANA` 第 3 项写成 Dev;出处(B. V. Raman《Muhurtha》Gana Kuta 一节)把 Rohini 列在 Manusha 组。合婚用的 `ashtakoot.GANA` 本来就是对的。(2) 名字和说明文字不是身份:不同的定义、不同的见证行星可以共用它们。(3) 上游规则文件有 35 条带 `participants_expr`,我们只同步过 15 条。
- 修复:(1) Rohini 改为 Manushya,移植她的 27 宿分组回归测试,并用同一分组钉住合婚的 Gana 表。(2) 冻结文件 `scripts/yoga_engine.py`(产品负责人 2026-11-20 同意改这一个文件)只动两个函数,照上游 19cfd9c0:`detect` 在每条规则前清空执行记录、把 `execution_trace` 和 `trace_scope` 放进 `condition_evidence`、去重改为整行内容完全相同才合并;`_eval_condition` 变成记录每个被求值节点的包装,原函数体改名 `_dispatch_condition` 不变。执行记录只是数据,行的顶层键没有增减,不进入任何读者文字。(3) 报告层:`yoga_status_words` 的实例键现在同时认列表形和映射形的行星(真实数据是映射形,BUG-2065 的键在真实数据上等于只按名字);候选表另加一个键「同一规则组 + 同行星 + 同组合句只留第一条」,所以两张公开盘的 30 行候选表前后名字和顺序都一样。(4) 上游与我们条件定义相同的 19 条规则补上 `participants_expr`(15 → 34 条);`bvr_matrunasa_precise` 两边条件不同,没有同步。`references/yoga_rule_topics.v1.json` 重新生成,只变了来源哈希。
- 影响面(证据包窗口在改动前后两个版本上核对过,结论在 `/workspace/eval-read-1116/yoga-2075-downstream-review.md`):引擎行两张公开盘 51→51、53→54,400 张合成盘 20,491→20,611,没有丢行,没有两行同名同组合同行星;证据编号只多一条,没有撞号和重复计数;执行记录在问答返回体、格局卡、领域卡片事实和两版报告正文里都不出现;事实核对按名字查状态,不受影响;落陷取消的命名规则路径没有动。`/api/yogas` 的返回体大约大 40%。
- 尚未处理:格局解释页仍然一个名字一页(改成按实例会多出「组合:未判定」的空页,需要占星师的口径);报告候选表把「同行星同组合句的两条不同名规则」只留一条,算不算应当分开要她定;自定义表达式内部的逐项追踪、缺值记为未知(她第 10 问的完整要求)没有做,上游也注明未做;年运的本命格局直接调检测、不带参与行星,两组行星战争会出现两行相同文字(证据包窗口跟进)。
- 验证与防复发:`tests/test_yoga_instances_gana_2075.py`(6 条,不依赖引擎改动:27 宿分组、合婚表同组、Rohini 的打分和报告文字、补上的参与星);`tests/test_yoga_engine_instances_2075.py`(6 条,移植自上游:同名同说明的不同规则都保留、同一规则每组行星各一行、完全相同的仍合并、OR 分支记录区分匹配与未匹配、没跑到的分支不留记录、执行记录不进两版报告)。
- 关联记录:BUG-2065(报告层的同名合并)、BUG-1597 / BUG-1657(参与星)、BUG-2012(落陷取消同一规则)、BUG-1967(30 行候选表)。
- 修复版本:`claude/yoga-instances-2075`。
+1 -1
View File
@@ -2,7 +2,7 @@
"schema": "yoga-rule-topics-v1",
"status": "pending_astrologer_review",
"built_from": "references/yoga_rules.json",
"built_from_sha256": "1d6ae014d74a",
"built_from_sha256": "467311236758",
"builder": "scripts/research/build_yoga_rule_topics.py",
"rule": "A topic is assigned only when the rule's own effect text names the domain with a listed keyword; condition text is not read. unmapped = the text names no domain (待映射, never dropped). longevity, fame_authority and spirituality are recorded for review; no chat domain selects by them.",
"rules": {
+28 -9
View File
@@ -1703,6 +1703,7 @@
"logic": {
"type": "custom",
"expr": "\n# PyJHora/BVR-15: L4 and L9 in mutual kendras, and L1 is in a kendra/trine from Lagna.\nl1 = lord(1)\nl4 = lord(4)\nl9 = lord(9)\nif l1 not in ctx.planets or l4 not in ctx.planets or l9 not in ctx.planets:\n False\nelse:\n l1_strong = house_of(l1) in [1, 4, 5, 7, 9, 10]\n mutual_kendra = offset(house_of(l4), house_of(l9)) in [0, 3, 6, 9]\n l1_strong and mutual_kendra\n",
"participants_expr": "[l1,l4,l9]",
"combo_template": "上升主有力,4宫主与9宫主互为Kendra",
"combo_template_en": "Lagna lord strong; 4th and 9th lords in mutual Kendras"
},
@@ -1791,6 +1792,7 @@
"logic": {
"type": "custom",
"expr": "\n# PyJHora/BVR-46: planets with strength > FRIEND in both quadrants and trines,\n# and Lagna lord strength > FRIEND. Strength > FRIEND means own/exalted only.\nl1 = lord(1)\nif l1 not in ctx.planets:\n False\nelse:\n strong_kendra = any(p in ctx.planets and house_of(p) in [1, 4, 7, 10] and house_strength(p) is not None and house_strength(p) > 3 for p in PLANET_INDEX)\n strong_trine = any(p in ctx.planets and house_of(p) in [1, 5, 9] and house_strength(p) is not None and house_strength(p) > 3 for p in PLANET_INDEX)\n strong_kendra and strong_trine and house_strength(l1) is not None and house_strength(l1) > 3\n",
"participants_expr": "[l1]+[p for p in PLANET_INDEX if p in ctx.planets and house_of(p) in [1,4,5,7,9,10] and house_strength(p) is not None and house_strength(p)>3]",
"combo_template": "上升主星有力+其他行星有力",
"combo_template_en": "Strong Lagna lord plus other strong planets"
},
@@ -2472,6 +2474,7 @@
"logic": {
"type": "custom",
"expr": "\nlord_11 = lord(11)\nlord_11 in ctx.planets and house_of(lord_11) in [6, 8, 12]\n",
"participants_expr": "[lord_11]",
"combo_template": "11宫主落入凶宫",
"combo_template_en": "11th lord in a Dusthana"
},
@@ -2499,6 +2502,7 @@
"logic": {
"type": "custom",
"expr": "\nlord_2 = lord(2)\nlord_2 in ctx.planets and debil(lord_2) and dusthana(house_of(lord_2))\n",
"participants_expr": "[lord_2]",
"combo_template": "2宫主落陷在凶宫",
"combo_template_en": "2nd lord debilitated in a Dusthana"
},
@@ -3011,6 +3015,7 @@
"logic": {
"type": "custom",
"expr": "\nben_in_8912 = [p for p in BENEFICS if p in ctx.planets and house_of(p) in [8, 9, 12]]\nlen(ben_in_8912) >= 2\n",
"participants_expr": "ben_in_8912",
"combo_template": "吉星在8/9/12宫",
"combo_template_en": "Benefics in the 8th/9th/12th houses"
},
@@ -3190,7 +3195,8 @@
"conditions": [
{
"type": "custom",
"expr": "bool([(k,t) for k in kendra_lords_list() for t in trikona_lords_list() if k!=t and k in planets and t in planets and aspect(k,t) and aspect(t,k)])"
"expr": "bool([(k,t) for k in kendra_lords_list() for t in trikona_lords_list() if k!=t and k in planets and t in planets and aspect(k,t) and aspect(t,k)])",
"participants_expr": "[(k,t) for k in kendra_lords_list() for t in trikona_lords_list() if k!=t and k in planets and t in planets and aspect(k,t) and aspect(t,k)]"
}
]
},
@@ -3904,7 +3910,8 @@
"conditions": [
{
"type": "custom",
"expr": "lords_of(2) in planets and is_debilitated(lords_of(2)) and is_dusthana(house_of(lords_of(2)))"
"expr": "lords_of(2) in planets and is_debilitated(lords_of(2)) and is_dusthana(house_of(lords_of(2)))",
"participants_expr": "[lord(2)]"
}
]
},
@@ -3931,7 +3938,8 @@
"conditions": [
{
"type": "custom",
"expr": "'Jupiter' in planets and 'Moon' in planets and (house_of('Jupiter') - house_of('Moon')) % 12 + 1 in [3,6,10,11]"
"expr": "'Jupiter' in planets and 'Moon' in planets and (house_of('Jupiter') - house_of('Moon')) % 12 + 1 in [3,6,10,11]",
"participants_expr": "['Jupiter','Moon']"
}
]
},
@@ -4018,7 +4026,8 @@
"conditions": [
{
"type": "custom",
"expr": "lords_of(2) in planets and lords_of(11) in planets and house_of(lords_of(2)) in [6,8,12] and house_of(lords_of(11)) in [6,8,12]"
"expr": "lords_of(2) in planets and lords_of(11) in planets and house_of(lords_of(2)) in [6,8,12] and house_of(lords_of(11)) in [6,8,12]",
"participants_expr": "[lord(2),lord(11)]"
}
]
},
@@ -4398,7 +4407,8 @@
"conditions": [
{
"type": "custom",
"expr": "lords_of(7) in planets and (is_exalted(lords_of(7)) or is_own_sign(lords_of(7)) or is_kendra(house_of(lords_of(7))))"
"expr": "lords_of(7) in planets and (is_exalted(lords_of(7)) or is_own_sign(lords_of(7)) or is_kendra(house_of(lords_of(7))))",
"participants_expr": "[lord(7)]"
}
]
},
@@ -4461,7 +4471,8 @@
"conditions": [
{
"type": "custom",
"expr": "'Venus' in planets and (is_exalted('Venus') or is_own_sign('Venus') or house_of('Venus') in [1,4,5,7,9,10])"
"expr": "'Venus' in planets and (is_exalted('Venus') or is_own_sign('Venus') or house_of('Venus') in [1,4,5,7,9,10])",
"participants_expr": "['Venus']"
}
]
},
@@ -4522,7 +4533,8 @@
"conditions": [
{
"type": "custom",
"expr": "'Mars' in planets and house_of('Mars') in [1,4,7,8,12]"
"expr": "'Mars' in planets and house_of('Mars') in [1,4,7,8,12]",
"participants_expr": "['Mars']"
}
]
},
@@ -4810,7 +4822,8 @@
"conditions": [
{
"type": "custom",
"expr": "'Moon' in planets and house_of('Moon') is not None and any(house_of(p)==((house_of('Moon')-2)%12)+1 for p in BENEFICS if p!='Moon' and p in planets) and any(house_of(p)==(house_of('Moon')%12)+1 for p in BENEFICS if p!='Moon' and p in planets)"
"expr": "'Moon' in planets and house_of('Moon') is not None and any(house_of(p)==((house_of('Moon')-2)%12)+1 for p in BENEFICS if p!='Moon' and p in planets) and any(house_of(p)==(house_of('Moon')%12)+1 for p in BENEFICS if p!='Moon' and p in planets)",
"participants_expr": "['Moon']+[p for p in BENEFICS if p!='Moon' and p in planets and house_of(p) in [((house_of('Moon')-2)%12)+1,(house_of('Moon')%12)+1]]"
}
]
},
@@ -5074,7 +5087,8 @@
"conditions": [
{
"type": "custom",
"expr": "lords_of(1) in planets and (is_exalted(lords_of(1)) or is_own_sign(lords_of(1))) and sum(1 for p in planets if p in planets_list() and (is_exalted(p) or is_own_sign(p))) >= 3"
"expr": "lords_of(1) in planets and (is_exalted(lords_of(1)) or is_own_sign(lords_of(1))) and sum(1 for p in planets if p in planets_list() and (is_exalted(p) or is_own_sign(p))) >= 3",
"participants_expr": "[lord(1)]+[p for p in planets if is_exalted(p) or is_own_sign(p)]"
}
]
},
@@ -11621,6 +11635,7 @@
"logic": {
"type": "custom",
"expr": "# BVR-66-74 Satkalatra Yoga: 7th lord or Venus joined or aspected by Jupiter or Mercury\n# Fix: use any() pattern instead of for-loop + trailing False (which overwrites True)\nlord_7 = lord(7)\ncandidates = []\nif lord_7 in planets:\n candidates.append(lord_7)\nif 'Venus' in planets:\n candidates.append('Venus')\nany(\n c != benefic and benefic in planets and (same_house(c, benefic) or aspect(benefic, c))\n for c in candidates\n for benefic in ['Jupiter', 'Mercury']\n)",
"participants_expr": "[(c,b) for c in candidates for b in ['Jupiter','Mercury'] if c!=b and b in planets and (same_house(c,b) or aspect(b,c))]",
"combo_template": "7宫主或金星与木星/水星合相或互照",
"combo_template_en": "7th lord or Venus conjoined with or mutually aspecting Jupiter/Mercury"
},
@@ -11680,6 +11695,7 @@
"logic": {
"type": "custom",
"expr": "\n# PyJHora/BVR-144..152 D1-safe Dharidhra variants (v6.0.47).\nl1, l2, l5, l6, l7, l8, l11, l12 = [lord(h) for h in [1, 2, 5, 6, 7, 8, 11, 12]]\ndusthana = [6, 8, 12]\ndusthana_lords = [l6, l8, l12]\nmarakas = [l2, l7]\n\ndef in_chart(p):\n return p in ctx.planets\n\ndef maraka_links_to(p):\n return in_chart(p) and any(in_chart(m) and (same_house(p, m) or aspect(m, p)) for m in marakas)\n\n# v6.1.3: Restored method1 (L2/L11 in dusthana with unfriendly navamsa).\n# PyJHora checks: L2 or L11 in 6/8/12 AND their navamsa is unfriendly.\nmethod1 = False\nif ctx.d9.get('ascendant'):\n for p in [l2, l11]:\n if in_chart(p) and house_of(p) in dusthana and is_unfriendly_navamsa(p) and any(aspect(m, p) for m in MALEFICS if m in ctx.planets and m != p):\n method1 = True\n break\n\n# v144: L1<->L12 exchange, L7 conjoined/aspects L1 or L12\nv144_exchange = in_chart(l1) and in_chart(l12) and house_of(l1) == 12 and house_of(l12) == 1\nv144_on_l1 = in_chart(l7) and (same_house(l1, l7) or aspect(l7, l1))\nv144_on_l12 = in_chart(l7) and (same_house(l12, l7) or aspect(l7, l12))\nv144 = v144_exchange and (v144_on_l1 or v144_on_l12)\n\n# v147: L1 in 8th, conjoined/aspected by maraka (one-way)\nv147 = in_chart(l1) and house_of(l1) == 8 and maraka_links_to(l1)\n\n# v148: L1 in dusthana with malefic, conjoined/aspected by maraka\nv148_malefic = any(m in ctx.planets and m != l1 and same_house(l1, m) for m in MALEFICS)\nv148 = in_chart(l1) and house_of(l1) in dusthana and v148_malefic and maraka_links_to(l1)\n\n# v149: L1 associated with trik lord (trik lord aspects L1), L1 aspected by malefic\nv149_assoc = any(in_chart(tl) and (same_house(l1, tl) or aspect(tl, l1)) for tl in dusthana_lords)\nv149_malefic = any(m in ctx.planets and m != l1 and aspect(m, l1) for m in MALEFICS)\nv149 = v149_assoc and v149_malefic\n\n# v150: L5 joins trik lord, no benefic influence\nv150_join = any(in_chart(tl) and same_house(l5, tl) for tl in dusthana_lords)\nv150_no_benefic = not any(b in ctx.planets and (same_house(l5, b) or aspect(b, l5)) for b in BENEFICS)\nv150 = in_chart(l5) and v150_join and v150_no_benefic\n\n# v151: L5 in 6th or 10th, aspected by lords of 2/6/7/8/12\nv151_pos = in_chart(l5) and house_of(l5) in [6, 10]\nv151_aspected = any(in_chart(tl) and (aspect(tl, l5)) for tl in [l2, l6, l7, l8, l12])\nv151 = v151_pos and v151_aspected\n\n# v152: natural malefic (not L9/L10) in Lagna, conjoined/aspected by maraka\nl9 = lord(9)\nl10 = lord(10)\nv152 = any(in_chart(m) and house_of(m) == 1 and m not in [l9, l10] and maraka_links_to(m) for m in MALEFICS)\n\nmethod1 or v144 or v147 or v148 or v149 or v150 or v151 or v152\n",
"participants_expr": "([(p,m) for p in [l2,l11] for m in MALEFICS if in_chart(p) and house_of(p) in dusthana and is_unfriendly_navamsa(p) and in_chart(m) and m!=p and aspect(m,p)] if method1 else [])+([l1,l12,l7] if v144 else [])+([l1]+[m for m in marakas if in_chart(m) and (same_house(l1,m) or aspect(m,l1))] if v147 or v148 else [])+([m for m in MALEFICS if in_chart(m) and m!=l1 and same_house(l1,m)] if v148 else [])+([l1]+[t for t in dusthana_lords if in_chart(t) and (same_house(l1,t) or aspect(t,l1))]+[m for m in MALEFICS if in_chart(m) and m!=l1 and aspect(m,l1)] if v149 else [])+([l5]+[t for t in dusthana_lords if in_chart(t) and same_house(l5,t)] if v150 else [])+([l5]+[t for t in [l2,l6,l7,l8,l12] if in_chart(t) and aspect(t,l5)] if v151 else [])+([(m,k) for m in MALEFICS for k in marakas if in_chart(m) and house_of(m)==1 and m not in [l9,l10] and in_chart(k) and (same_house(m,k) or aspect(k,m))] if v152 else [])",
"combo_template": "Dharidhra:财帛/收益主落凶宫或Lagna/Maraka/Dusthana组合",
"combo_template_en": "Daridra: 2nd/11th lord in a Dusthana, or a Lagna/Maraka/Dusthana combination"
},
@@ -11708,6 +11724,7 @@
"logic": {
"type": "custom",
"expr": "\n# PyJHora/BVR-117 Sada Sanchara: Lagna lord OR the dispositor of Lagna lord is in a movable sign.\nl1 = lord(1)\nif l1 not in ctx.planets:\n False\nelse:\n l1_h = house_of(l1)\n l1_dispositor = lord(l1_h) if l1_h else None\n sign_of(l1) in MOVABLE_SIGNS or (l1_dispositor in ctx.planets and sign_of(l1_dispositor) in MOVABLE_SIGNS)\n",
"participants_expr": "([l1] if sign_of(l1) in MOVABLE_SIGNS else [])+([l1,l1_dispositor] if l1_dispositor in ctx.planets and sign_of(l1_dispositor) in MOVABLE_SIGNS else [])",
"combo_template": "上升主或月亮在变动星座",
"combo_template_en": "Lagna lord or Moon in a movable sign"
},
@@ -11766,6 +11783,7 @@
"logic": {
"type": "custom",
"expr": "\n# PyJHora/BVR-132 D1/D9-safe portions: 2nd lord in Kendra/Trine from Lagna lord;\n# or 2nd lord as benefic in exaltation / joined with an exalted planet;\n# or Navamsa-dispositor chain strength >= friend and related to 2nd lord.\nasc_lord = lord(1)\nlord_2 = lord(2)\nif asc_lord not in ctx.planets or lord_2 not in ctx.planets:\n False\nelse:\n l1h = house_of(asc_lord)\n l2h = house_of(lord_2)\n rel_good = offset(l1h, l2h) in [0, 3, 4, 6, 8, 9]\n lord2_benefic = lord_2 in BENEFICS\n with_exalted = any(p != lord_2 and same_house(p, lord_2) and exalted(p) for p in ctx.planets)\n nav_lord = navamsa_dispositor(asc_lord)\n final_disp = SIGN_LORDS.get(sign_of(nav_lord)) if nav_lord in ctx.planets else None\n chain_good = bool(final_disp in ctx.planets and house_strength(final_disp) is not None and house_strength(final_disp) >= 3 and (offset(l2h, house_of(final_disp)) in [0, 3, 4, 6, 8, 9] or house_strength(final_disp) >= 4))\n rel_good or (lord2_benefic and (exalted(lord_2) or with_exalted)) or chain_good\n",
"participants_expr": "([asc_lord,lord_2] if rel_good else [])+([lord_2]+[p for p in ctx.planets if p!=lord_2 and same_house(p,lord_2) and exalted(p)] if lord2_benefic and (exalted(lord_2) or with_exalted) else [])+([asc_lord,lord_2,nav_lord,final_disp] if chain_good else [])",
"combo_template": "2宫主与上升主成Kendra/Trine关系或2宫主吉且强",
"combo_template_en": "2nd lord in Kendra/Trine relation to the Lagna lord, or 2nd lord benefic and strong"
},
@@ -11825,6 +11843,7 @@
"logic": {
"type": "custom",
"expr": "\n# PyJHora BVR-195: 4th lord associated with malefics or inimical/debilitated.\n# PyJHora uses house_strength <= _ENEMY (1) for 'inimical', not <= _NEUTRAL (2).\nlord_4 = lord(4)\nif lord_4 not in ctx.planets:\n False\nelse:\n malefic_assoc = any(m in ctx.planets and associated(lord_4, m) for m in MALEFICS if m != lord_4)\n inimical_or_debil = debil(lord_4) or (house_strength(lord_4) is not None and house_strength(lord_4) <= 1) or is_shashtiamsa_evil(lord_4)\n malefic_assoc or inimical_or_debil\n",
"participants_expr": "[lord_4]+[m for m in MALEFICS if m in ctx.planets and m!=lord_4 and associated(lord_4,m)]",
"combo_template": "4宫主受凶星关联或处于弱/不利状态",
"combo_template_en": "4th lord associated with malefics or weak or afflicted"
},
+2 -1
View File
@@ -49,7 +49,8 @@ TARA_CN = {0:'生命Tara',1:'财富Tara',2:'危险Tara',3:'安全Tara',
# Nakshatra元素和属性
NAK_GANA = { # 气质类型
0:'Dev(神圣)',1:'Manushya(人类)',2:'Rakshasa(罗刹)',
3:'Dev',4:'Dev',5:'Manushya',6:'Dev',7:'Dev',8:'Rakshasa',
# BUG-2075 (upstream 0d6626f2). Raman, Muhurtha, Gana Kuta: Rohini belongs to Manusha/Manushya.
3:'Manushya',4:'Dev',5:'Manushya',6:'Dev',7:'Dev',8:'Rakshasa',
9:'Rakshasa',10:'Manushya',11:'Manushya',12:'Dev',13:'Rakshasa',14:'Dev',
15:'Rakshasa',16:'Dev',17:'Rakshasa',18:'Rakshasa',19:'Manushya',20:'Manushya',
21:'Dev',22:'Rakshasa',23:'Rakshasa',24:'Manushya',25:'Manushya',26:'Dev',
+41 -6
View File
@@ -2,7 +2,10 @@
from __future__ import annotations
import json
from datetime import date, time
from functools import lru_cache
from pathlib import Path
from types import SimpleNamespace
from .english_gaps import HAN
@@ -95,6 +98,12 @@ def report_yoga_inputs(packet):
return payload, {"reference_date": day}
def _legacy_yoga_rows(packet):
advanced = _record(_record(packet.get("worksheets")).get("advanced_systems"))
legacy = _record(advanced.get("yoga"))
return legacy.get("detected_yogas") or legacy.get("yogas") or []
def _project_rows(rows, fields):
return [{key: row[key] for key in fields if key in row} for row in rows or [] if isinstance(row, dict)]
@@ -107,12 +116,35 @@ REPORT_YOGA_ROW_CAP = 30
def _yoga_instance_key(row):
# BUG-2065:同名但参与行星不同的行是两条(两颗落陷星各有一条落陷取消),不能并成一条。
# 原值:只认列表形式的参与行星;问答层的行把参与行星写成以行星名为键的映射,键因此退化成只有名字
# 新值:列表和映射都认,行星名排序后入键
# 原因:BUG-2075(占星师 2026-11-20 A6):真实报告里两颗落陷星的同名行仍被并成一条
planets = row.get("planets")
names = tuple(name for name in planets if isinstance(name, str)) if isinstance(planets, (list, tuple)) else ()
names = tuple(sorted(name for name in planets if isinstance(name, str))) if isinstance(planets, (list, tuple, dict)) else ()
return row.get("name"), names
def _report_yoga_rows(rows, cap=REPORT_YOGA_ROW_CAP):
@lru_cache(maxsize=1)
def _rule_dedup_groups():
path = Path(__file__).resolve().parents[2] / "references" / "yoga_rules.json"
rules = json.loads(path.read_text(encoding="utf-8")).get("rules") or []
return {rule["id"]: rule["dedup_key"] for rule in rules if isinstance(rule, dict) and rule.get("id") and rule.get("dedup_key")}
def _engine_variant_keys(engine_rows):
"""BUG-2075:规则引擎不再按规则组加组合文字并行(上游 19cfd9c0),各规则的行都留在引擎输出里。
报告候选表照旧:同一规则组、同样的参与行星、同一句组合文字的几条变体只列第一条。"""
keys = {}
for row in engine_rows or []:
if not isinstance(row, dict):
continue
group = _rule_dedup_groups().get(row.get("rule_id"))
if group and row.get("combination"):
keys.setdefault((row["rule_id"], _yoga_instance_key(row)[1]), (group, _yoga_instance_key(row)[1], str(row["combination"])))
return keys
def _report_yoga_rows(rows, cap=REPORT_YOGA_ROW_CAP, variant_keys=None):
# 改前引擎层按名字去重(同名只留第一条);报告照旧,问答卡上同名不同规则各占一行。
# BUG-2065:去重键加上参与行星,同名同行星的不同规则仍只留第一条。
seen = set()
@@ -120,7 +152,12 @@ def _report_yoga_rows(rows, cap=REPORT_YOGA_ROW_CAP):
for row in rows or []:
if not isinstance(row, dict) or _yoga_instance_key(row) in seen:
continue
variant = (variant_keys or {}).get((row.get("rule_id"), _yoga_instance_key(row)[1]))
if variant in seen:
continue
seen.add(_yoga_instance_key(row))
if variant:
seen.add(variant)
unique.append(row)
rows = unique
if len(rows) <= cap:
@@ -171,7 +208,7 @@ def report_yoga_conditions(packet, *, gender=None):
result = {
"status": layer.get("status") or "blocked",
"reference_date": body["reference_date"],
"rows": _project_rows(_report_yoga_rows(layer.get("rows")), YOGA_FIELDS),
"rows": _project_rows(_report_yoga_rows(layer.get("rows"), variant_keys=_engine_variant_keys(_legacy_yoga_rows(packet))), YOGA_FIELDS),
"not_evaluated": _project_rows(layer.get("not_evaluated"), UNEVALUATED_FIELDS),
}
if result["status"] != "executed":
@@ -182,9 +219,7 @@ def report_yoga_conditions(packet, *, gender=None):
def report_yoga_table(packet):
layer = report_yoga_conditions(packet)
advanced = _record(_record(packet.get("worksheets")).get("advanced_systems"))
legacy = _record(advanced.get("yoga"))
old_rows = legacy.get("detected_yogas") or legacy.get("yogas") or []
old_rows = _legacy_yoga_rows(packet)
by_name = {row["name"]: row for row in old_rows if isinstance(row, dict) and row.get("name")}
# BUG-2065:同名多行(每颗落陷星一条)按名字加参与行星对应,各取各的组合说明。
by_instance = {_yoga_instance_key(row): row for row in old_rows if isinstance(row, dict) and row.get("name")}
+24 -2
View File
@@ -1223,6 +1223,8 @@ class YogaEngine:
# 规则匹配。一条规则求值失败(异常)记为 evaluation_failed 并带错误类,
# 不得静默当成不成立(占星师第三轮审查 2026-11-07)。
for rule in self.rules:
# 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:
@@ -1270,6 +1272,8 @@ class YogaEngine:
'rule_id': rule.get('id'),
'definition': rule.get('logic'),
'source_reference': entry['source_reference'],
'execution_trace': list(ctx.condition_execution_trace),
'trace_scope': 'executed_condition_nodes; custom_expression_internals_not_traced',
'participants': {p: {'sign': ctx.sign_of(p), 'house': ctx.house_of(p)}
for p in entry.get('planets', [])},
}
@@ -1309,8 +1313,10 @@ class YogaEngine:
entry['strength'] = 'conditional'
entry['strength_en'] = 'Conditional'
self._attach_interpretive_evidence(entry, ctx)
dedup_key = rule.get("dedup_key") or rule["name"]
dedup_val = f"{dedup_key}:{m.get('combination', '')}"
# 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.
dedup_val = json.dumps(entry, sort_keys=True, ensure_ascii=False, default=str)
if dedup_val in seen_dedup:
continue
seen_dedup.add(dedup_val)
@@ -1401,6 +1407,22 @@ class YogaEngine:
def _eval_condition(self, cond: Dict, ctx: YogaContext, rule: Dict,
bindings: Dict) -> List[Dict]:
"""Record actual node evaluations, including unsuccessful OR branches.
BUG-2075 (upstream 19cfd9c0). An execution receipt, not independent
source validation: a node that was never reached has no entry, and a
custom expression stays opaque (its internal tests are not traced).
"""
matches = self._dispatch_condition(cond, ctx, rule, bindings)
trace = getattr(ctx, 'condition_execution_trace', None)
if trace is not None:
trace.append({'condition_type': cond.get('type') or cond.get('op'),
'definition': cond, 'input_bindings': dict(bindings),
'matched': bool(matches), 'match_count': len(matches)})
return matches
def _dispatch_condition(self, cond: Dict, ctx: YogaContext, rule: Dict,
bindings: Dict) -> List[Dict]:
"""评估条件节点,返回匹配列表"""
# v6.0.31: 兼容历史规则中的 "op" 字段。
# 早期批量扩展脚本误用 op 而不是 type;如果只读 type,会导致这些规则静默失效。
+5 -1
View File
@@ -23,6 +23,7 @@ from scripts.report_render.yoga_status_words import (
YOGA_GAP_NO_ROW, YOGA_NOTICE_EN, YOGA_NOTICE_ZH, YOGA_STATUS_MAPPING,
is_structural_observation, report_yoga_conditions, report_yoga_inputs,
report_yoga_table, yoga_status, _report_yoga_rows,
_engine_variant_keys, _legacy_yoga_rows,
)
from tests.public_chart_reports import PUBLIC_REPORT_CASES, public_chart_reports
@@ -225,7 +226,10 @@ def test_public_reports_match_native_yoga_status_and_audit_axes(case):
# 原值:报告行等于引擎层全部行(引擎层原来就截在 30 行)
# 新值:报告行等于引擎层按报告原规则取的行(前 30 行 + 带见证或互换的行)
# 原因:BUG-1967 引擎层不再截行,按领域选行只在问答卡做;个人报告保持改前逐行相同
reported = _report_yoga_rows(native["rows"])
# 原值: _report_yoga_rows(native["rows"])
# 新值: 同一调用加上 variant_keys(取自报告自己的规则引擎行)
# 原因: BUG-2075 规则引擎不再按规则组加组合文字并行(上游 19cfd9c0),报告候选表照旧只列同组同星同句的第一条
reported = _report_yoga_rows(native["rows"], variant_keys=_engine_variant_keys(_legacy_yoga_rows(packet)))
assert layer["rows"] == [{key: row[key] for key in YOGA_FIELDS if key in row} for row in reported]
assert layer["not_evaluated"] == [
{key: row[key] for key in UNEVALUATED_FIELDS if key in row} for row in native.get("not_evaluated", [])
+100
View File
@@ -0,0 +1,100 @@
"""BUG-2075 (upstream 19cfd9c0): the rule engine keeps distinct yoga instances and records executed conditions.
Every test here needs the BUG-2075 change in scripts/yoga_engine.py. Adapted from
her tests/test_yoga_instance_preservation.py; her two report-pack tests target
professional_parity_closure, which the product does not run.
"""
from __future__ import annotations
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "scripts"))
from yoga_engine import YogaEngine # noqa: E402
RULES_PATH = str(ROOT / "references" / "yoga_rules.json")
CHART = {"Sun": {"sign": "Aries", "house": 1}, "Moon": {"sign": "Taurus", "house": 2}}
TRACE_SCOPE = "executed_condition_nodes; custom_expression_internals_not_traced"
def _detect(rules, planets=None):
engine = YogaEngine(RULES_PATH)
engine.rules = rules
rows = [row for row in engine.detect(planets or CHART, "Aries") if not str(row.get("rule_id")).startswith("main_detector:")]
assert engine.last_evaluation_failures == []
return rows
def _custom(expr, **extra):
return {"type": "custom", "expr": expr, **extra}
def _rule(rule_id, logic, **extra):
return {"id": rule_id, "name": "Shared name", "name_cn": "同名", "logic": logic, **extra}
def test_same_name_and_prose_do_not_erase_different_rules():
rows = _detect([_rule(key, _custom("True", combo_template="Same wording"), dedup_key="one_group")
for key in ("source_a", "source_b")])
assert [row["rule_id"] for row in rows] == ["source_a", "source_b"]
def test_same_rule_keeps_one_row_per_planet():
logic = {"type": "or", "conditions": [
_custom("True", combo_template="Same wording", participants_expr="['Sun']"),
_custom("True", combo_template="Same wording", participants_expr="['Moon']"),
]}
rows = _detect([_rule("per_planet", logic)])
assert [row["planets"] for row in rows] == [["Sun"], ["Moon"]]
assert len({row["combination"] for row in rows}) == 1
def test_exact_duplicate_is_still_collapsed():
logic = {"type": "or", "conditions": [_custom("True", combo_template="Same wording")] * 2}
rows = _detect([_rule("twice", logic)])
assert len(rows) == 1
def test_or_trace_distinguishes_failed_branch_from_matching_branch():
rows = _detect([_rule("branch_test", {"type": "or", "conditions": [_custom("False"), _custom("True")]})])
evidence = rows[0]["condition_evidence"]
assert evidence["trace_scope"] == TRACE_SCOPE
trace = evidence["execution_trace"]
assert [(node["definition"].get("expr"), node["matched"]) for node in trace
if node["condition_type"] == "custom"] == [("False", False), ("True", True)]
assert trace[-1]["condition_type"] == "or" and trace[-1]["matched"] is True and trace[-1]["match_count"] == 1
def test_and_trace_has_no_entry_for_a_branch_that_never_ran():
never = _custom("'never' == 'ran'")
rows = _detect([
_rule("short_circuit", {"type": "and", "conditions": [_custom("False"), never]}),
_rule("after", _custom("True")),
])
# The first rule did not form; its trace is not carried into the next rule.
assert [row["rule_id"] for row in rows] == ["after"]
assert [node["definition"]["expr"] for node in rows[0]["condition_evidence"]["execution_trace"]] == ["True"]
engine = YogaEngine(RULES_PATH)
from yoga_engine import YogaContext
ctx = YogaContext(CHART, "Aries")
ctx.condition_execution_trace = []
assert engine._eval_condition({"type": "and", "conditions": [_custom("False"), never]}, ctx, _rule("x", {}), {}) == []
assert [(node["condition_type"], node["definition"].get("expr"), node["matched"])
for node in ctx.condition_execution_trace] == [("custom", "False", False), ("and", None, False)]
def test_trace_stays_out_of_both_report_editions():
from tests.public_chart_reports import public_chart_reports
packet, chinese, english = public_chart_reports("steve_jobs_1955_aa")
rows = packet["worksheets"]["advanced_systems"]["yoga"]["detected_yogas"]
traced = [row for row in rows if (row.get("condition_evidence") or {}).get("execution_trace")]
assert traced and all(row["condition_evidence"]["trace_scope"] == TRACE_SCOPE for row in traced)
for text in (chinese, english):
for word in ("execution_trace", "trace_scope", "condition_type", "input_bindings", "match_count",
"executed_condition_nodes"):
assert word not in text, word
+122
View File
@@ -0,0 +1,122 @@
"""BUG-2075: Rohini gana, rule participants and the report's yoga instance keys.
Nothing here depends on the BUG-2075 change inside scripts/yoga_engine.py; the
tests that do are in tests/test_yoga_engine_instances_2075.py.
"""
from __future__ import annotations
import json
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "scripts"))
from scripts.ashtakoot import GANA # noqa: E402
from scripts.nakshatra_advanced import NAK_GANA, find_nakshatra, nakshatra_compatibility # noqa: E402
from scripts.report_render import parity_chapters as pc # noqa: E402
from scripts.report_render.yoga_status_words import ( # noqa: E402
_engine_variant_keys, _report_yoga_rows, _yoga_instance_key,
)
from yoga_engine import YogaEngine # noqa: E402
RULES_PATH = ROOT / "references" / "yoga_rules.json"
# Raman, Muhurtha, Gana Kuta list (her corpus Page 81, lines 3928-3940); zero-based nakshatra indices.
GANA_GROUPS = {
"Dev": {0, 4, 6, 7, 12, 14, 16, 21, 26},
"Manushya": {1, 3, 5, 10, 11, 19, 20, 24, 25},
"Rakshasa": {2, 8, 9, 13, 15, 17, 18, 22, 23},
}
ROHINI = 3
def test_all_27_ganas_match_source_groups_including_rohini():
for gana, indices in GANA_GROUPS.items():
for index in indices:
result = find_nakshatra((index + 0.5) * 360 / 27)
assert result["gana"].startswith(gana), result["nakshatra"]
assert NAK_GANA[ROHINI] == "Manushya"
def test_marriage_match_gana_table_uses_the_same_27_groups():
spelling = {"Dev": "Deva", "Manushya": "Manushya", "Rakshasa": "Rakshasa"}
assert len(GANA) == 27
for gana, indices in GANA_GROUPS.items():
assert {index for index, value in enumerate(GANA) if value == spelling[gana]} == indices
def test_rohini_pair_scores_as_manushya_and_report_prints_it():
bharani = 1
match = nakshatra_compatibility(ROHINI, bharani)["gana_match"]
assert match["g1"] == "Manushya" and match["score"] == 6
packet = {"worksheets": {"advanced_systems": {"nakshatra_adv": {"natal_nakshatras": {
"Moon": {**find_nakshatra((ROHINI + 0.5) * 360 / 27), "nakshatra_lord": "Moon"}}}}}}
assert "| Moon | Rohini | 2 | Moon | Manushya |" in pc._nakshatra_reference(packet, "en")
assert "| 月亮 | Rohini | 2 | 月亮 | 人 |" in pc._nakshatra_reference(packet, "zh")
def _logic_nodes(node):
if isinstance(node, dict):
yield node
for value in node.values():
yield from _logic_nodes(value)
elif isinstance(node, list):
for value in node:
yield from _logic_nodes(value)
def test_synced_rules_carry_participants_expr_and_name_their_planets():
rules = {rule["id"]: rule for rule in json.loads(RULES_PATH.read_text(encoding="utf-8"))["rules"]}
carrying = {rule_id for rule_id, rule in rules.items()
if any("participants_expr" in node for node in _logic_nodes(rule.get("logic")))}
assert {"kahala_yoga", "mridanga_yoga", "mridanga_yoga_variant", "pushya_yoga", "raja_yoga_mutual_aspect"} <= carrying
assert len(carrying) == 34
# Her expression for this rule belongs to a different condition text than ours; not copied.
assert "bvr_matrunasa_precise" not in carrying
# Synthetic chart: Scorpio Lagna; lords 1/4/9 = Mars / Saturn / Moon.
signs = ["Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius",
"Capricorn", "Aquarius", "Pisces"]
places = {"Sun": ("Cancer", 20), "Moon": ("Pisces", 11), "Mars": ("Cancer", 29), "Mercury": ("Cancer", 28),
"Jupiter": ("Taurus", 23), "Venus": ("Gemini", 28), "Saturn": ("Virgo", 8), "Rahu": ("Leo", 14),
"Ketu": ("Aquarius", 14)}
planets = {name: {"sign": sign, "house": (signs.index(sign) - signs.index("Scorpio")) % 12 + 1,
"degree": float(degree), "longitude": signs.index(sign) * 30.0 + degree}
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 == []
assert rows["kahala_yoga"]["planets"] == ["Moon", "Mars", "Saturn"]
assert rows["raja_yoga_mutual_aspect"]["planets"] == ["Moon", "Saturn"]
assert rows["pushya_yoga"]["planets"] == ["Mercury", "Venus"]
def test_report_instance_key_reads_planets_from_layer_rows():
# Consultation-layer rows carry planets as a mapping keyed by planet name.
def row(planet, **extra):
return {"name": "Neecha Bhanga", "planets": {planet: {"owns": [1]}}, "status": "computed", **extra}
assert _yoga_instance_key(row("Mars")) != _yoga_instance_key(row("Venus"))
assert _yoga_instance_key(row("Mars")) == _yoga_instance_key({"name": "Neecha Bhanga", "planets": ["Mars"]})
kept = _report_yoga_rows([row("Mars"), row("Venus"), row("Mars", rule_id="second_rule_same_planet")])
assert [list(item["planets"]) for item in kept] == [["Mars"], ["Venus"]]
def test_report_table_lists_one_row_for_variants_of_one_rule_group():
# The engine now returns both rules for one placement (same rule group, same planet, same wording).
engine_rows = [
{"rule_id": "surya_yoga_kendra", "name": "Surya Yoga (Sun in Kendra)", "planets": ["Sun"], "combination": "太阳在第7宫"},
{"rule_id": "surya_yoga_7", "name": "Surya Yoga (Sun in 7th House)", "planets": ["Sun"], "combination": "太阳在第7宫"},
{"rule_id": "chandra_yoga_1", "name": "Chandra Yoga (Moon in 1st House)", "planets": ["Moon"], "combination": "月亮在第1宫"},
]
layer_rows = [{"rule_id": item["rule_id"], "name": item["name"], "planets": {item["planets"][0]: {}}}
for item in engine_rows]
kept = _report_yoga_rows(layer_rows, variant_keys=_engine_variant_keys(engine_rows))
assert [item["rule_id"] for item in kept] == ["surya_yoga_kendra", "chandra_yoga_1"]
# Without the engine rows nothing is known about the wording: every rule keeps its row.
assert len(_report_yoga_rows(layer_rows)) == 3
# A different wording inside the same rule group is a different row.
engine_rows[1]["combination"] = "另一句组合"
assert len(_report_yoga_rows(layer_rows, variant_keys=_engine_variant_keys(engine_rows))) == 3