fix(yoga): 王者格局(互视) names the pair that matched; no card says 「条件未能逐项列出」 (BUG-2413)

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-26 11:01:44 +08:00
co-authored by Claude Opus 5.5
parent 377d186eb1
commit c2ac5150f3
5 changed files with 115 additions and 10 deletions
+13
View File
@@ -32866,3 +32866,16 @@
- **修复版本**:1.5(staging)。
- **BUG-2411 跟进(2026-11-26)**:staging 门禁 8774 挂 `personal-report-view` 的「每个阶段恰好一个外壳」:合盘生成中改用 ReportRunCard 后多了一个 `personal-report-state` 阶段,顶栏写法 `<SecondaryHeader title="婚恋合盘" back=…` 没被计入。测试按原值/新值/原因补认这一写法;断言主语不变。
## BUG-2413 | 星盘页「王者格局(互视)」成立卡写着「条件未能逐项列出」
- **状态**:resolved(staging 待负责人验收,1.5)
- **现象**:负责人 2026-11-26 在星盘页「全局 Yoga」看到成立的「王者格局(互视)」卡,说明只有「条件未能逐项列出」,属于负责人禁止的两可说法。
- **触发条件**:任一角宫主和三方宫主互相相照的盘(例:巨蟹上升,土星在双鱼、月亮在处女)。
- **根因**:`raja_yoga_mutual_aspect` 是自定义表达式规则,命中后只返回默认的「自定义条件满足」,没有写是哪两颗星;读者句子 `reader_yoga_condition_zh` 删掉这类占位后只剩「条件未能逐项列出」,星盘页照样显示。150 张合成盘扫描:能成立的规则里只有这一条落到这句(其余落到这句的都是候选行,不出卡)。
- **修复**:`references/yoga_rules.json` 里这条规则改成多语句表达式,判定条件不变,命中的每一对只写一次,组合句为「角宫主与三方宫主互相相照:土星(第 7、8 宫主)和月亮(第 1 宫主)」(英文同步);星盘页 `chart-yoga-groups.ts` 不再显示「条件未能逐项列出」或「按规则判定」,真没有条件句时只写这条格局的白话作用。没有改 yoga_engine.py。
- **验证**:`tests/test_raja_mutual_aspect_text_2413.py`(成立、句子、成对只写一次)、`frontend/tests/chart-yoga-unlisted-2413.test.ts`;星盘与格局相关前端测试 412 条通过;tsc 无错。
- **防复发**:前端测试钉住卡片不出现「条件未能逐项列出 / 按规则判定」。
- **关联记录**:BUG-2392(王者格局结构满足即成立)、BUG-2412(成立的规则格局进星盘页)、BUG-2226(读者条件句)。
- **未处理**:报告附录的格局表仍用 `CUSTOM_CONDITION_UNLISTED_ZH`(报告窗口负责),这条规则现在有句子,不会再落到那里。
- **修复版本**:1.5。
+14 -8
View File
@@ -171,15 +171,21 @@ function conditionText(row: Row): string {
// BUG-2226: the engine's reader sentence (report_render.appendix_language.reader_yoga_condition_zh).
const raw = text(row.reader_condition_zh);
const reader = raw ? tidyYogaCondition(raw) || null : null;
if (reader && !/^按(?:来源)?规则判定$/u.test(reader)) return reader;
if (reader) return "条件未能逐项列出";
const combination = text(row.combination_zh) ?? text(row.combination);
if (combination && /[一-鿿]/u.test(combination) && !placeholder(combination)) return combination;
const conditions = strings(row.conditions).filter((line) => /[一-鿿]/u.test(line));
if (conditions.length) return conditions.join(";");
return "条件未能逐项列出";
if (reader && !UNLISTED.test(reader)) return reader;
if (!reader) {
const combination = text(row.combination_zh) ?? text(row.combination);
if (combination && /[一-鿿]/u.test(combination) && !placeholder(combination)) return combination;
const conditions = strings(row.conditions).filter((line) => /[一-鿿]/u.test(line));
if (conditions.length) return conditions.join(";");
}
// BUG-2413 原值「条件未能逐项列出」/ 新值:只写这条格局的白话作用(没有就留空)/ 原因:负责人不要两可的话,
// 卡片上不说「列不出」。
return strings(row.effects).filter((line) => /[一-鿿]/u.test(line)).join("、");
}
// The server's 「列不出条件」 placeholders (appendix_language.CUSTOM_CONDITION_UNLISTED_ZH and the rule-judged label).
const UNLISTED = /^(?:按(?:来源)?规则判定|条件未能逐项列出)$/u;
function rowPlanets(row: Row): string[] {
return strings(row.planets).filter((planet) => (VISIBLE as readonly string[]).includes(planet) || planet === "Rahu" || planet === "Ketu");
}
@@ -442,7 +448,7 @@ export function buildYogaGroups(input: Readonly<{
const tags = strings(row.reductions).map((line) => line);
const sentence = conditionText(row);
// The same fact under another rule (two 太阳瑜伽 rows, three rules on one exalted Saturn) is one card.
const twin = formed.find((card) => (card.text === sentence && sentence !== "条件未能逐项列出")
const twin = formed.find((card) => (card.text === sentence && sentence !== "")
|| (planets.length > 0 && card.planets.length === planets.length && card.planets.every((planet) => planets.includes(planet))
&& (String(row.category ?? "") === categories.get(card.id)
// BUG-2412: the same sign exchange named twice (王者互换 and 大互换) is one fact, whatever the category.
@@ -0,0 +1,38 @@
import assert from "node:assert/strict";
import test from "node:test";
import { buildYogaGroups } from "../src/lib/chart-yoga-groups.ts";
/**
* BUG-2413 (owner 2026-11-26): the formed 王者格局(互视) card read 「条件未能逐项列出」. The engine now names
* the matched pair; and when a row truly carries no condition words, the card shows the yoga's plain effect
* instead of any 「列不出」 placeholder. Synthetic chart, no birth data.
*/
const planets = [
{ name: "Sun", sign: "Cancer", house: 1 },
{ name: "Moon", sign: "Virgo", house: 3 },
{ name: "Mars", sign: "Libra", house: 4 },
{ name: "Mercury", sign: "Leo", house: 2 },
{ name: "Jupiter", sign: "Capricorn", house: 7 },
{ name: "Venus", sign: "Gemini", house: 12 },
{ name: "Saturn", sign: "Pisces", house: 9 },
];
const live = { evidence_status: "local_rule_match", display_status: "candidate_review",
assertion_label: "single_system_inference", card_eligible: false, card_status: "reference_only",
formation_status: "conditions_met", formation_assessment: { status: "formed_under_source" } };
const aspect = { ...live, rule_id: "raja_yoga_mutual_aspect", name: "Raja Yoga (Mutual Aspect)", name_cn: "王者格局(互视)",
category: "raja", planets: ["Moon", "Saturn"], effects: ["权力地位", "影响力"] };
test("the mutual-aspect card shows the engine's named pair", () => {
const row = { ...aspect, reader_condition_zh: "角宫主与三方宫主互相相照:土星(第 7、8 宫主)和月亮(第 1 宫主)" };
const card = buildYogaGroups({ rows: [row], planets, ascendant: "Cancer" })!.formed[0]!;
assert.match(card.text, /^角宫主与三方宫主互相相照:土星(第 7、8 宫主)和月亮(第 1 宫主)/u);
});
test("an old placeholder sentence never reaches a card; the plain effect stands in", () => {
for (const reader of ["条件未能逐项列出", "按规则判定", "按来源规则判定"]) {
const card = buildYogaGroups({ rows: [{ ...aspect, reader_condition_zh: reader }], planets, ascendant: "Cancer" })!.formed[0]!;
assert.doesNotMatch(card.text, /条件未能逐项列出|按(?:来源)?规则判定/u);
assert.equal(card.text, "权力地位、影响力");
}
});
+4 -2
View File
@@ -3190,8 +3190,10 @@
"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)])",
"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)]"
"expr": "\n# BUG-2413: same test as before; the matched pairs are named in plain words so the card never reads\n# 「条件未能逐项列出」. Each unordered pair once; a lord's houses are all the houses it rules.\npairs = []\nfor k in kendra_lords_list():\n for t in trikona_lords_list():\n if k != t and k in planets and t in planets and aspect(k,t) and aspect(t,k) and {k, t} not in [set(x) for x in pairs]:\n pairs.append((k, t))\ndef _ruled(p):\n return [h for h in range(1, 13) if lord(h) == p]\ndef _zh(p):\n return PLANET_ZH.get(p, p) + '(第 ' + '、'.join(f'{h}' for h in _ruled(p)) + ' 宫主)'\ndef _en(p):\n return p + ' (lord of ' + ', '.join(f'{h}' for h in _ruled(p)) + ')'\ntriggers = [(_zh(k) + '和' + _zh(t), _en(k) + ' and ' + _en(t)) for k, t in pairs]\n__result__ = bool(pairs)\n",
"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)]",
"combo_template": "角宫主与三方宫主互相相照",
"combo_template_en": "A kendra lord and a trikona lord aspect each other"
}
]
},
@@ -0,0 +1,46 @@
"""BUG-2413: the formed 王者格局(互视) names the pair that matched, so no card reads 「条件未能逐项列出」 (synthetic chart)."""
from pathlib import Path
import pytest
from scripts.report_render.appendix_language import CUSTOM_CONDITION_UNLISTED_ZH, reader_yoga_condition_zh
from scripts.yoga_engine import SIGNS, YogaEngine
RULES = Path(__file__).resolve().parents[1] / "references" / "yoga_rules.json"
CANCER = {"Jupiter": "Capricorn", "Saturn": "Pisces", "Sun": "Cancer", "Moon": "Virgo",
"Mars": "Libra", "Mercury": "Leo", "Venus": "Gemini"}
@pytest.fixture(scope="module")
def engine():
return YogaEngine(str(RULES))
def _row(engine, ascendant, signs, rule_id):
asc = SIGNS.index(ascendant)
chart = {p: {"sign": s, "house": (SIGNS.index(s) - asc) % 12 + 1} for p, s in signs.items()}
rows = [r for r in engine.detect(chart, ascendant, context={"chart_type": "D1"}) if r["rule_id"] == rule_id]
return rows[0] if rows else None
def test_mutual_aspect_names_the_pair_and_their_houses(engine):
row = _row(engine, "Cancer", CANCER, "raja_yoga_mutual_aspect")
assert row is not None
assert row["formation_assessment"]["status"] == "formed_under_source"
text = reader_yoga_condition_zh(row)
assert text != CUSTOM_CONDITION_UNLISTED_ZH
assert text == "角宫主与三方宫主互相相照:土星(第 7、8 宫主)和月亮(第 1 宫主)"
assert row["combination_en"].endswith("Saturn (lord of 7, 8) and Moon (lord of 1)")
assert sorted(row["planets"]) == ["Moon", "Saturn"]
def test_each_pair_is_named_once(engine):
# Aries: Mars (L1/L8) in Libra and Venus (L2/L7) in Aries face each other; Sun (L5) in Aquarius and
# Moon (L4) in Leo face each other. Lagna lord is both kendra and trikona lord, so (Mars, Venus) could
# appear as (k, t) and (t, k); it must be named once.
row = _row(engine, "Aries", {"Mars": "Libra", "Venus": "Aries", "Sun": "Aquarius", "Moon": "Leo",
"Mercury": "Gemini", "Jupiter": "Sagittarius", "Saturn": "Taurus"},
"raja_yoga_mutual_aspect")
assert row is not None
text = reader_yoga_condition_zh(row)
assert text.count("火星") == 1, text