fix(report): reading facts keep each rule's Chinese name, the Neecha Bhanga witness roles, and Narayana's second reading when stored (BUG-2106)
Independent Staging Quality Gate / validate-frontend (push) Successful in 6m7s
Independent Staging Quality Gate / validate-python (push) Successful in 7m42s
Independent Staging Quality Gate / publish (push) Successful in 3m33s

Rules sharing an English name printed each other's Chinese name in the reading
facts; each row now takes its engine row's name_cn by rule id. Neecha Bhanga rows
carry the fallen planet and the cancellation witnesses as two roles in the data
chapters' words. Narayana's direction readings are read from the report packet
when BUG-2105 stores them, and skipped otherwise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
This commit is contained in:
2026-11-20 23:28:28 +08:00
co-authored by Claude Opus 5.5
parent 2b580562e9
commit eebd60e0f5
5 changed files with 290 additions and 3 deletions
+20
View File
@@ -28389,3 +28389,23 @@
- 验证与防复发:`frontend/tests/question-material-2103.test.ts`(8 条,合成报告文本);`frontend/tests/report-questions-personal-2093.test.tsx` 中处理函数读取规则的断言按原值 / 新值 / 原因更新。
- 关联记录:BUG-2100(章节归并)、BUG-2093(个人报告内提问)、BUG-2061(目录分组)。
- 修复版本:`claude/question-material-2103`。
## BUG-2106 | 个人报告写解读用的事实里,同英文名的三对规则中文名串了;落陷取消没有见证星;Narayana 第二种方向读法没有进来
- 状态:fixed-pending-verify(中文名与见证星已在两张公开盘上复核;Narayana 第二种读法要等 BUG-2105 把它存进报告数据包后才生效)。
- 首次发现 / 最近更新:2026-11-20 / 2026-11-20。
- 触发与现象:问答可读性窗口给占星师做回包时发现,写个人报告解读的事实(也存为报告内提问用的 `longform-reading-facts-v1`)里:`ev:yoga:amala_yoga` 印成「纯净瑜伽」(`bvr_amala_precise` 的名字),`ev:yoga:kalatra_dosha_mars_7` 印成「火星婚姻煞(火星入1/4/7/8/12宫)」;落陷取消的行只有落陷星,没有化解条件的见证星;Narayana 只有当前读法。
- 触发条件:两条规则英文名相同、rule_id 不同(amala_yoga / bvr_amala_precise、kalatra_dosha_mars_7 / kalatra_dosha_mars_1_4_7_8_12、bvr_durumukha_precise / bvr_durmukha_yoga);任何有落陷取消的盘。
- 根因:
- 中文名:共用的报告格局表 `scripts/report_render/yoga_status_words.py` `report_yoga_table`(第 241、243、254、257 行)按英文名(加参与行星)去对引擎行,后一条覆盖前一条,引擎行自己的 `name_cn` 被别的规则的名字盖掉。该文件归问答可读性窗口,本条没有改它,只在事实这一侧按 rule_id 取。问答卡 `merge_detected_yogas` 按 rule_id 保留不同规则,也不按英文名查中文名,不受影响。
- 见证星:事实在报告解读步骤(`pl9_interpretation_packs` → `attach_neecha_witness_roles`)写 `cancellation_witnesses` 之前就生成,读到的引擎行上还没有这两个键。
- Narayana:第二种方向读法只在渲染时由 `narayana_report_extras` 现算,没有存进数据包。
- 修复(`scripts/report_render/reading_facts.py`):
- 每一行按 rule_id(同一规则多行时再按参与行星)找引擎自己的行,用它的 `name_cn`。
- 落陷取消的行用数据章节同一个函数(`neecha_witness.participant_cells`)按引擎执行过的条件算两种角色,加 `fallen_planets`、`cancellation_witnesses`、`self_reference_witnesses`、`witnesses_returned`、`witness_text_zh`(「化解条件的见证星:土星;月亮(自我参照,不作独立印证)」),当前周期主星是见证星时加 `current_lord_witness_text_zh`(「当前周期关联到该化解条件的见证星:土星」),不写已激活 / 已兑现。证据编号不变。
- 报告数据包里有 `worksheets.timing_and_predictive_systems.narayana_dasha_report_extras` 时,Narayana 事实加 `direction_readings`(两种读法各自的大运、小运和日期),标 `use_in: 依据与边界`;没有就不加。
- `frontend/src/lib/personal-question-material.ts`:报告内提问的格局行带上「落陷星:…;化解条件的见证星:…」。
- 大小:两张公开盘的事实 95,581 → 95,574 字节(乔布斯)、96,309 → 96,649 字节(奥巴马)。
- 验证与防复发:`tests/test_reading_facts_2106.py`(5 条:两张公开盘的中文名和见证星,按 rule_id 和参与行星对行,见证星角色和未返回的情况,Narayana 两种读法有就读、没有就跳过);`frontend/tests/reading-facts-material-2106.test.ts`(1 条)。
- 关联记录:BUG-2089(见证星进报告)、BUG-2105(Narayana 读法存进数据包)、BUG-2088、BUG-2093、BUG-2098、BUG-1988 / BUG-2012(落陷取消逐星一行、编号不变)。
- 修复版本:`claude/reading-facts-2106`。
@@ -197,7 +197,12 @@ function yogaLines(facts: Row, limit: number): string[] {
const name = text(row.name_cn) || text(row.name);
const state = text(row.state_text);
const conditions = text(row.conditions);
return [name, state, conditions].filter(Boolean).join(":");
// BUG-2106: a Neecha Bhanga row names the fallen planet and its cancellation witnesses as two roles,
// in the data chapters' words (占星师 2026-11-20 Q4).
const fallen = list(row.fallen_planets).map((name) => planet(name)).filter(Boolean).join("、");
const roles = [fallen ? `落陷星:${fallen}` : "", text(row.witness_text_zh), text(row.current_lord_witness_text_zh)]
.filter(Boolean).join(";");
return [name, state, conditions, roles].filter(Boolean).join(":");
}).filter(Boolean);
}
@@ -0,0 +1,30 @@
/**
* BUG-2106: the question material shows a Neecha Bhanga row's two roles (fallen planet, cancellation
* witnesses) in the data chapters' words. Synthetic facts only.
*/
import assert from "node:assert/strict";
import test from "node:test";
import { personalSectionMaterial } from "../src/lib/personal-question-material.ts";
const facts = {
yogas: [{
name: "Neecha Bhanga", name_cn: "落陷取消", state_text: "条件满足",
fallen_planets: ["Jupiter"], cancellation_witnesses: ["Saturn", "Moon"], self_reference_witnesses: ["Moon"],
witness_text_zh: "化解条件的见证星:土星;月亮(自我参照,不作独立印证)",
current_lord_witness_text_zh: "当前周期关联到该化解条件的见证星:土星",
}, { name: "Amala Yoga", name_cn: "无瑕格局", state_text: "成立" }],
};
const reading = {
version: 1,
sections: [{ id: "character", title: "性格", status: "ok", paragraphs: [{ text: "你做事稳。" }] }],
};
test("a Neecha Bhanga row in the material names the fallen planet and the witnesses", () => {
const material = personalSectionMaterial({ reading: reading as never, markdown: "", factTables: [], facts }, "character");
const body = JSON.stringify(material);
assert.match(body, /落陷取消:条件满足:落陷星:木星;化解条件的见证星:土星;月亮(自我参照,不作独立印证);当前周期关联到该化解条件的见证星:土星/);
assert.match(body, /无瑕格局:成立/);
assert.doesNotMatch(body, /激活|兑现/);
});
+127 -2
View File
@@ -297,9 +297,52 @@ def _narayana(packet: dict) -> dict[str, Any]:
out["branch_summary"] = _pick(node.get("branch_summary"), ("candidates_exhausted",))
if node.get("years_unresolved"):
out["years_unresolved"] = copy.deepcopy(node["years_unresolved"])
if readings := _narayana_direction_readings(packet):
out["direction_readings"] = readings
return out
NARAYANA_REPORT_EXTRAS = f"{TIMING}.narayana_dasha_report_extras"
def _narayana_reading_period(value: Any) -> dict[str, Any] | None:
if not isinstance(value, dict) or not isinstance(value.get("sign"), str):
return None
out = _pick(value, ("sign", "lord", "start_age", "end_age"))
if dates := narayana_report_date_pair(value.get("start_date"), value.get("end_date")):
out["start"], out["end"] = dates
return out
def _narayana_direction_readings(packet: dict) -> dict[str, Any] | None:
"""Both direction readings of the running Narayana sub-periods, when the report stored them (BUG-2106).
The report computes them with narayana_report_extras (BUG-2088) and stores the result at
NARAYANA_REPORT_EXTRAS (BUG-2105); absent → nothing. Narayana is conditional (占星师 2026-11-07 Q1,
2026-11-08 profiles) and the reading names techniques only in 「依据与边界」 (BUG-2098), so the block is
marked for that section.
"""
extras = dig(packet, NARAYANA_REPORT_EXTRAS)
rows = extras.get("ad_direction_readings") if isinstance(extras, dict) else None
if not isinstance(rows, list):
return None
readings = []
for row in rows:
if not isinstance(row, dict) or not isinstance(row.get("profile"), str):
continue
item = {**_pick(row, ("profile", "status", "reason", "start_sign", "direction", "rule_text")),
"default": row.get("default") is True}
if isinstance(row.get("exception_applied"), bool):
item["exception_applied"] = row["exception_applied"]
for level in ("md", "ad"):
if period := _narayana_reading_period(row.get(level)):
item[level] = period
readings.append(item)
if not readings:
return None
return {"use_in": "依据与边界", "readings": readings}
def _current_row(rows: Any, today: str) -> tuple[int, dict] | None:
if not isinstance(rows, list):
return None
@@ -668,16 +711,92 @@ def _jaimini(packet: dict) -> dict[str, Any]:
return out
def _engine_yoga_rows(packet: dict) -> list[dict[str, Any]]:
advanced = dig(packet, "worksheets.advanced_systems.yoga")
if not isinstance(advanced, dict):
return []
rows = advanced.get("detected_yogas") or advanced.get("yogas") or []
return [row for row in rows if isinstance(row, dict)]
def _planet_names(value: Any) -> tuple[str, ...]:
if isinstance(value, (list, tuple, dict)):
return tuple(sorted(name for name in value if isinstance(name, str)))
return ()
def _engine_row_for(evidence: Any, engine_rows: list[dict[str, Any]]) -> dict[str, Any] | None:
"""The engine's own row for one table row, matched by rule id (and participants when a rule has several rows).
BUG-2106: the shared report table matches engine rows by English name, so two rules that share an English
name (amala_yoga / bvr_amala_precise, kalatra_dosha_mars_7 / kalatra_dosha_mars_1_4_7_8_12,
bvr_durumukha_precise / bvr_durmukha_yoga) printed each other's Chinese name in the model input.
"""
if not isinstance(evidence, dict) or not isinstance(evidence.get("rule_id"), str):
return None
same_rule = [row for row in engine_rows if row.get("rule_id") == evidence["rule_id"]]
if len(same_rule) > 1:
wanted = _planet_names(evidence.get("planets"))
for row in same_rule:
if _planet_names(row.get("planets")) == wanted:
return row
return same_rule[0] if same_rule else None
def _neecha_roles_fields(engine_row: dict[str, Any] | None, packet: dict, active: list[str]) -> dict[str, Any]:
"""The fallen planet and the cancellation witnesses as two roles, in the data chapters' own words (BUG-2106).
The facts are built before the report's interpretation step writes ``cancellation_witnesses`` on the
engine rows (pl9_interpretation_packs → attach_neecha_witness_roles), so the roles are read here the same
way, from the detector's executed conditions (占星师 2026-11-20 Q4: separate roles; a self-reference witness
is recorded, not independent support; one witness is one planet).
"""
from .neecha_witness import participant_cells
if engine_row is None:
return {}
cells = participant_cells(engine_row, active, "zh", dig(packet, "worksheets.advanced_systems.yogas_doshas"))
if cells is None:
return {}
roles = cells["roles"]
out: dict[str, Any] = {
"fallen_planets": list(roles["fallen"]),
"witnesses_returned": roles["witnesses_returned"],
}
if roles["witnesses_returned"]:
out["cancellation_witnesses"] = list(roles["witnesses"])
out["self_reference_witnesses"] = list(roles["self_reference_witnesses"])
out["witness_text_zh"] = f"化解条件的见证星:{cells['witness_cell']}"
if cells["witness_status"]:
out["current_lord_witness_text_zh"] = cells["witness_status"]
return out
def _active_lords(packet: dict) -> list[str]:
current = dig(packet, DASHA)
if not isinstance(current, dict):
return []
lords = [current.get("lord")]
for key in ("antardasha_timeline", "pratyantardasha_timeline"):
rows = current.get(key) if isinstance(current.get(key), list) else []
lords += [row.get("lord") for row in rows if isinstance(row, dict) and row.get("is_current") is True]
return [name for name in dict.fromkeys(lords) if isinstance(name, str)]
def _yogas(packet: dict) -> list[dict[str, Any]]:
from .neecha_witness import is_neecha_bhanga_row
from .yoga_status_words import report_yoga_table, yoga_status
layer, rows, _observations = report_yoga_table(packet)
if layer["status"] != "executed":
return []
engine_rows = _engine_yoga_rows(packet)
active = _active_lords(packet)
out = []
for evidence, row in rows:
state, state_text = yoga_status(evidence)
out.append({
engine_row = _engine_row_for(evidence, engine_rows)
entry = {
**({"evidence_id": yoga_id(evidence["rule_id"], obj=evidence.get("instance_object")
if isinstance(evidence.get("instance_object"), str) else None)}
if isinstance(evidence, dict) and isinstance(evidence.get("rule_id"), str) else {}),
@@ -686,7 +805,13 @@ def _yogas(packet: dict) -> list[dict[str, Any]]:
**({"detector_strength": row["strength"]} if row.get("strength") else {}),
"state": state,
"state_text": state_text,
})
}
# BUG-2106: each rule's own Chinese name, by rule id.
if engine_row is not None and isinstance(engine_row.get("name_cn"), str) and engine_row["name_cn"].strip():
entry["name_cn"] = engine_row["name_cn"]
if is_neecha_bhanga_row(evidence if isinstance(evidence, dict) else row):
entry.update(_neecha_roles_fields(engine_row, packet, active))
out.append(entry)
return out
+107
View File
@@ -0,0 +1,107 @@
"""BUG-2106: reading facts carry each rule's own Chinese name, the Neecha Bhanga roles, and
Narayana's direction readings when the report stored them.
Public AA fixtures (Steve Jobs, Barack Obama) and synthetic dicts only.
"""
from __future__ import annotations
from functools import lru_cache
from scripts.jyotish_engine import build_professional_report_reference_packet, cmd_full_reading
from scripts.professional_report_reference import _export_args
from scripts.report_render import reading_facts as rf
from scripts.report_render.reading_facts import build_report_reading_facts
from tests.test_consult_card_full_source import _public_body
@lru_cache(maxsize=2)
def _facts(case: str) -> dict:
args = _export_args({**_public_body(case), "today": "2026-11-11", "target_year": 2026})
reading = cmd_full_reading(args)
packet = dict(build_professional_report_reference_packet(reading, args, []))
packet["report_version"] = "pl9_personal_long_report.v3"
return build_report_reading_facts(packet, reading, minute_confirmed=True, today="2026-11-11")
def _yoga(facts: dict, evidence_id: str) -> dict:
return next(row for row in facts["yogas"] if row.get("evidence_id") == evidence_id)
def test_rules_sharing_an_english_name_keep_their_own_chinese_name() -> None:
# 原值:ev:yoga:amala_yoga 印「纯净瑜伽」(bvr_amala_precise 的名字),kalatra_dosha_mars_7 印
# 「火星婚姻煞(火星入1/4/7/8/12宫)」;新值:各按 rule_id 取引擎行自己的 name_cn;原因:BUG-2106。
facts = _facts("steve_jobs_1955_aa")
assert _yoga(facts, "ev:yoga:amala_yoga@D1")["name_cn"] == "无瑕格局"
assert _yoga(facts, "ev:yoga:kalatra_dosha_mars_7@D1")["name_cn"] == "火星障碍(火星在关键宫)"
def test_neecha_bhanga_row_names_the_fallen_planet_and_the_witnesses_as_two_roles() -> None:
facts = _facts("barack_obama_1961_aa")
row = _yoga(facts, "ev:yoga:main_detector:neecha_bhanga@D1")
assert row["fallen_planets"] == ["Jupiter"]
assert row["witnesses_returned"] is True
assert row["cancellation_witnesses"] == ["Saturn", "Moon"]
assert row["self_reference_witnesses"] == ["Moon"]
assert row["witness_text_zh"] == "化解条件的见证星:土星;月亮(自我参照,不作独立印证)"
# A witness that is a current lord is a link to the condition, never 已激活 / 已兑现.
text = row.get("current_lord_witness_text_zh", "")
assert "激活" not in text and "兑现" not in text
# The evidence id stays the one the chat card uses (BUG-1988 / 2012).
assert row["evidence_id"] == "ev:yoga:main_detector:neecha_bhanga@D1"
def test_engine_row_is_matched_by_rule_id_and_participants() -> None:
rows = [
{"rule_id": "amala_yoga", "name": "Amala Yoga", "name_cn": "无瑕格局", "planets": ["Jupiter"]},
{"rule_id": "bvr_amala_precise", "name": "Amala Yoga", "name_cn": "纯净瑜伽", "planets": ["Jupiter"]},
{"rule_id": "main_detector:neecha_bhanga", "name": "Neecha Bhanga", "planets": ["Mars"], "name_cn": "落陷取消"},
{"rule_id": "main_detector:neecha_bhanga", "name": "Neecha Bhanga", "planets": ["Mercury"], "name_cn": "落陷取消"},
]
assert rf._engine_row_for({"rule_id": "amala_yoga"}, rows)["name_cn"] == "无瑕格局"
assert rf._engine_row_for({"rule_id": "bvr_amala_precise"}, rows)["name_cn"] == "纯净瑜伽"
mercury = rf._engine_row_for({"rule_id": "main_detector:neecha_bhanga", "planets": {"Mercury": {}}}, rows)
assert mercury["planets"] == ["Mercury"]
assert rf._engine_row_for({"rule_id": "missing"}, rows) is None
def test_witness_roles_follow_the_detector_conditions() -> None:
row = {"name": "Neecha Bhanga", "rule_id": "main_detector:neecha_bhanga", "planets": ["Mars"],
"cancellation_conditions": [
{"condition": "dispositor_kendra_from_lagna", "planet": "Moon", "relative_house": 4},
{"condition": "dispositor_aspect", "planet": "Moon"},
{"condition": "exaltation_sign_lord_kendra_from_moon", "planet": "Mars", "relative_house": 1},
]}
out = rf._neecha_roles_fields(row, {}, ["Moon"])
assert out["fallen_planets"] == ["Mars"]
# One witness tied to several conditions is one planet.
assert out["cancellation_witnesses"] == ["Moon", "Mars"]
assert out["self_reference_witnesses"] == ["Mars"]
assert out["witness_text_zh"] == "化解条件的见证星:月亮;火星(自我参照,不作独立印证)"
assert out["current_lord_witness_text_zh"] == "当前周期关联到该化解条件的见证星:月亮"
unknown = rf._neecha_roles_fields({"name": "Neecha Bhanga", "planets": ["Mars"]}, {}, [])
assert unknown["witnesses_returned"] is False and "cancellation_witnesses" not in unknown
assert unknown["witness_text_zh"] == "化解条件的见证星:本次未返回"
def test_narayana_direction_readings_are_read_when_stored_and_skipped_when_absent() -> None:
assert rf._narayana_direction_readings({}) is None
extras = {"ad_direction_readings": [
{"profile": "rath_parity", "default": True, "status": "selected", "start_sign": "Leo", "direction": "forward",
"exception_applied": False, "rule_text": "顺行",
"md": {"sign": "Leo", "lord": "Sun", "start_age": 66.0, "end_age": 75.0,
"start_date": "2021-02-24", "end_date": "2030-02-24"},
"ad": {"sign": "Virgo", "lord": "Mercury", "start_age": 70.0, "end_age": 70.75,
"start_date": "2025-02-24", "end_date": "2025-11-24"}},
{"profile": "classical_odd_even", "default": False, "status": "blocked", "reason": "antardasha_not_selected",
"md": {"sign": "Leo", "lord": "Sun", "start_age": 66.0, "end_age": 75.0}},
]}
packet = {"worksheets": {"timing_and_predictive_systems": {"narayana_dasha_report_extras": extras}}}
out = rf._narayana_direction_readings(packet)
assert out["use_in"] == "依据与边界"
first, second = out["readings"]
assert first["default"] is True and first["exception_applied"] is False
assert first["ad"] == {"sign": "Virgo", "lord": "Mercury", "start_age": 70.0, "end_age": 70.75,
"start": "2025-02-24", "end": "2025-11-24"}
assert second == {"profile": "classical_odd_even", "status": "blocked", "reason": "antardasha_not_selected",
"default": False, "md": {"sign": "Leo", "lord": "Sun", "start_age": 66.0, "end_age": 75.0}}