diff --git a/docs/BUG_HISTORY.md b/docs/BUG_HISTORY.md index 3c54c8f67..0c1a679f3 100644 --- a/docs/BUG_HISTORY.md +++ b/docs/BUG_HISTORY.md @@ -32866,3 +32866,16 @@ - **修复版本**:1.5(staging)。 - **BUG-2411 跟进(2026-11-26)**:staging 门禁 8774 挂 `personal-report-view` 的「每个阶段恰好一个外壳」:合盘生成中改用 ReportRunCard 后多了一个 `personal-report-state` 阶段,顶栏写法 ` /[一-鿿]/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. diff --git a/frontend/tests/chart-yoga-unlisted-2413.test.ts b/frontend/tests/chart-yoga-unlisted-2413.test.ts new file mode 100644 index 000000000..fc059470d --- /dev/null +++ b/frontend/tests/chart-yoga-unlisted-2413.test.ts @@ -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, "权力地位、影响力"); + } +}); diff --git a/references/yoga_rules.json b/references/yoga_rules.json index b159ada25..4ea0b6ce4 100644 --- a/references/yoga_rules.json +++ b/references/yoga_rules.json @@ -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" } ] }, diff --git a/tests/test_raja_mutual_aspect_text_2413.py b/tests/test_raja_mutual_aspect_text_2413.py new file mode 100644 index 000000000..146f2372a --- /dev/null +++ b/tests/test_raja_mutual_aspect_text_2413.py @@ -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