Astrologer 2026-11-19, answer to question 17. Two flags per condition: witness_is_reference (the Moon in the 1st from the Moon, true for every chart) and witness_is_debilitated_planet (Mercury as its own witness, a real position condition that still counts). A planet that hits only the always-true branch keeps the label 落陷, gets no row or cancel relation and is never the basis of a Raja Yoga candidate; the literal hit stays in backstage evidence (literal_only). This is the product policy neecha_bhanga_policy_v1; the raw rule version stays light_on_life_p295. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
243 lines
13 KiB
Python
243 lines
13 KiB
Python
"""占星师 2026-11-08 验收清单 §7 的七个反例:引擎侧端到端断言(BUG-1812)。
|
||
|
||
每个反例一条测试,调用真实的引擎函数(不是包装脚本),断言状态、日期与「不计分 / 不增票」。
|
||
配套的数据卡断言在 `frontend/tests/consult-counterexamples-card-20261109.test.ts`,读同一份
|
||
fixture。fixture 由 `scripts/research/capture_counterexample_fixtures_20261109.py` 生成,
|
||
最后一条测试断言「引擎现在的输出 == fixture」,fixture 过期即失败。
|
||
|
||
只用公开名人盘(Barack Obama)或合成输入。
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import json
|
||
import sys
|
||
from datetime import datetime
|
||
from pathlib import Path
|
||
|
||
import pytest
|
||
|
||
ROOT = Path(__file__).resolve().parents[1]
|
||
for entry in (str(ROOT), str(ROOT / "scripts"), str(ROOT / "scripts" / "research")):
|
||
if entry not in sys.path:
|
||
sys.path.insert(0, entry)
|
||
|
||
from capture_counterexample_fixtures_20261109 import ( # noqa: E402
|
||
CASES,
|
||
OUT,
|
||
REFERENCE_DATE,
|
||
SECOND_CYCLE_AGE,
|
||
build_cases,
|
||
normalise,
|
||
)
|
||
|
||
FIXTURES = {name: json.loads((OUT / f"{name}.json").read_text(encoding="utf-8")) for name in CASES}
|
||
|
||
|
||
def engine(case: str) -> dict:
|
||
return FIXTURES[case]["engine"]
|
||
|
||
|
||
def _moon(layer: dict) -> dict:
|
||
return layer["movable_lagna_moon"]
|
||
|
||
|
||
def _rounded(value):
|
||
"""浮点按 9 位小数比较:Windows 与 Linux 的星历在第 13 位起会差(约 1e-12 度),不是引擎变化。"""
|
||
if isinstance(value, float):
|
||
return round(value, 9)
|
||
if isinstance(value, dict):
|
||
return {key: _rounded(item) for key, item in value.items()}
|
||
if isinstance(value, list):
|
||
return [_rounded(item) for item in value]
|
||
return value
|
||
|
||
|
||
def test_fixture_is_fresh_for_every_counterexample() -> None:
|
||
"""一条覆盖七张 fixture:引擎输出必须与仓内文件逐字段相同(浮点到 9 位小数)。"""
|
||
# 原值:fresh[name] == FIXTURES[name] 逐位相等
|
||
# 新值:两边浮点都取 9 位小数后相等
|
||
# 原因:验收在 Linux 上跑,Moon 经度 41.48538690748626 对 41.485386907488675(Windows 抓取),只差末位;
|
||
# 9 位小数(约 1e-9 度)仍能拦住任何真实的引擎变化。
|
||
fresh = normalise(build_cases())
|
||
for name in CASES:
|
||
assert _rounded(fresh[name]) == _rounded(FIXTURES[name]), (
|
||
f"{name}.json 与引擎当前输出不一致;重跑 "
|
||
"scripts/research/capture_counterexample_fixtures_20261109.py")
|
||
|
||
|
||
def test_a_missing_moon_paksha_blocks_only_the_moon_and_both_layers_agree() -> None:
|
||
"""(a) 缺月相:只有月亮 blocked,原因点名;基础层与事业层同源。"""
|
||
data = engine("a_missing_moon_paksha")
|
||
base, career = data["blocked"]["base"], data["blocked"]["career"]
|
||
for layer in (base, career):
|
||
moon = _moon(layer)
|
||
assert (moon["status"], moon["role"], moon["reason"]) == ("blocked", None, "moon_paksha_missing")
|
||
assert layer["status"] == "used"
|
||
# 只阻塞月亮:其他行星照常分类,月亮不进任何一档。
|
||
assert base["blocked_planets"] == ["Moon"]
|
||
classified = set(base["functional_benefics"]) | set(base["functional_malefics"]) | set(base["functional_neutrals"])
|
||
assert "Moon" not in classified
|
||
# 表 30 只列七颗星(Rahu / Ketu 不在功能吉凶表里),月亮之外六颗照常分类。
|
||
assert len(classified) == 6, sorted(classified)
|
||
# 盈亏已知时两层一致(修复前事业层是 blocked / moon_paksha_missing)。
|
||
known = data["paksha_known"]
|
||
assert _moon(known["base"])["status"] == _moon(known["career"])["status"] == "derived_from_table_30_note"
|
||
assert _moon(known["base"])["role"] == _moon(known["career"])["role"] == "neutral"
|
||
assert _moon(known["base"])["moon_paksha"] == _moon(known["career"])["moon_paksha"] == "waning"
|
||
|
||
|
||
def test_b_low_grade_comparison_undecided_names_the_step_and_scores_nothing() -> None:
|
||
"""(b) 低档强弱未决:Narayana 点名未定步骤、不计分;Shadbala 保留 parameter_sensitive。"""
|
||
data = engine("b_low_grade_undecided")
|
||
comparison = data["narayana"]["comparison"]
|
||
assert (comparison["status"], comparison["comparison_status"]) == ("undecided", "unresolved")
|
||
assert comparison["blocked_level"] == 3
|
||
assert comparison["reason"] == "rule3_highest_tier_below_own_sign_tied"
|
||
calc = data["narayana"]["calc"]
|
||
assert (calc["status"], calc["blocked_step"]) == ("blocked", "seed")
|
||
product = data["narayana"]["product"]
|
||
assert product["status"] == "blocked"
|
||
assert product["used_for_scoring"] is False
|
||
assert "current_dasha" not in product # 不用旧算法补出一个「已确认」的当前大运
|
||
method = product["method_status"]
|
||
assert (method["status"], method["chat_use"]) == ("blocked", "no_judgment")
|
||
assert method["unresolved_steps"] == ["seed"]
|
||
assert method["steps"]["seed"]["status"] == "blocked"
|
||
# Shadbala:翻盘的行星只能是 parameter_sensitive,不写成达标 / 不达标。
|
||
shadbala = data["shadbala"]
|
||
assert shadbala["Jupiter"]["minimum_check"] == "parameter_sensitive"
|
||
assert shadbala["Jupiter"]["minimum_open_questions"]
|
||
others = [name for name, row in shadbala.items() if name != "Jupiter"]
|
||
assert others and not any(row["minimum_check"] == "parameter_sensitive" for row in (shadbala[n] for n in others))
|
||
|
||
|
||
def test_c_ad_undecided_keeps_the_md_and_names_the_reason() -> None:
|
||
"""(c) 小运未决但大运已定:大运星座与日期保留,子运未决且原因被点名,不补旧 AD。"""
|
||
data = engine("c_ad_blocked_md_known")
|
||
md, ad = data["md"], data["antardasha"]
|
||
assert md["sign"] == "Taurus" and md["cycle_index"] == 2
|
||
assert (ad["status"], ad["reason"]) == ("blocked", "saturn_ketu_priority_unresolved")
|
||
assert ad["rows"] == []
|
||
product = data["narayana"]
|
||
current = product["current_dasha"]
|
||
assert current["md"]["sign"] == md["sign"]
|
||
assert current["md"]["cycle_index"] == md["cycle_index"] == 2
|
||
# 大运日期原样来自引擎行(未取整的 age 换成日期后与引擎一致)。
|
||
assert current["md"]["start_date"] and current["md"]["end_date"]
|
||
assert "ad" not in current # 没有由旧算法补出的小运
|
||
assert current["ad_status"] == "blocked"
|
||
assert current["ad_reason"] == ad["reason"]
|
||
# 未决层不计分:Narayana 整体仍是单体系候选,used_for_scoring 为 False。
|
||
assert product["used_for_scoring"] is False
|
||
assert product["method_status"]["chat_use"] == "single_system_candidate"
|
||
# 卡上的 dasha_systems 层同样只带未决的原因,不带一个补出来的小运。
|
||
row = data["dasha_systems_narayana"]
|
||
assert (row["md"]["sign"], row["md"]["cycle_index"]) == (md["sign"], md["cycle_index"])
|
||
assert (row["ad_status"], row["ad_reason"]) == ("blocked", ad["reason"])
|
||
assert "ad" not in row
|
||
|
||
|
||
def test_d_moon_self_reference_is_never_independent_confirmation() -> None:
|
||
"""(d) 月亮自参照:只标自参照,独立确认为 0,不当作独立一票。
|
||
|
||
原值:引擎给一条 Neecha Bhanga 成立行,formation_evidence.self_reference_only 为真。
|
||
新值:没有行;后台只留一条「仅命中字面自我参照条件」的记录。旧行逐字留在 legacy_row,
|
||
代表已保存的卡和报告。
|
||
原因:BUG-2027,占星师 2026-11-19 第 17 问:只因「月亮在月亮起第 1 宫」命中时,默认标签是落陷,
|
||
取消未确认,也不升级为 Raja Yoga 候选。
|
||
"""
|
||
data = engine("d_moon_self_reference")
|
||
assert data["rows"] == []
|
||
note = data["literal_only"][0]
|
||
assert (note["planet"], note["default_rule_met"], note["raw_rule_met"], note["tautology_only"]) == (
|
||
"Jupiter", False, True, True)
|
||
assert note["royal_yoga_candidate_allowed"] is False
|
||
assert note["policy"] == "neecha_bhanga_policy_v1" and note["default_profile"] == "light_on_life_p295"
|
||
moon = note["literal_conditions"][0]
|
||
assert (moon["reference"], moon["relative_house"], moon["self_reference"]) == ("Moon", 1, True)
|
||
assert moon["independent_confirmation_allowed"] is False
|
||
legacy = data["legacy_row"]
|
||
assert legacy["name"] == "Neecha Bhanga" and legacy["formation_evidence"]["self_reference_only"] is True
|
||
assert legacy["formation_evidence"]["independent_condition_count"] == 0
|
||
|
||
|
||
def test_e_birth_balance_keeps_the_full_parent_start_beside_the_visible_one() -> None:
|
||
"""(e) 出生余额:子运边界不因裁剪而改变,父段起点与可见起点都留、且不同。"""
|
||
data = engine("e_birth_balance")
|
||
balance = data["balance"]
|
||
assert balance["remaining_years"] > 9, balance
|
||
sub = data["sub_periods"]
|
||
assert sub["status"] == "ready"
|
||
md = sub["current"]["mahadasha"]
|
||
assert md["lord"] == balance["lord"]
|
||
# 余额大运在出生前开始:卡上看到的是被出生裁出来的那一段。
|
||
assert md["start"] < data["birth"]["date"] < md["end"]
|
||
# 出生那一刻的小运被裁:父段起点(出生前)与可见起点(出生当天)同时留下、且不同。
|
||
clipped = next(row for row in sub["boundaries"] if row.get("parent_period_start"))
|
||
assert clipped["parent_period_start"] < clipped["visible_period_start"] == data["birth"]["date"]
|
||
# 同一条小运的完整父段边界与未裁剪版本逐日相同(边界不移动)。
|
||
from chart_dasha import birth_moment
|
||
|
||
full = {row["lord"]: row for row in birth_moment.antardashas({
|
||
"lord": md["lord"], "start": datetime.fromisoformat(md["start"]), "end": datetime.fromisoformat(md["end"])})}
|
||
assert full[clipped["lord"]]["start"].strftime("%Y-%m-%d") == clipped["parent_period_start"]
|
||
for row in sub["boundaries"]:
|
||
assert full[row["lord"]]["end"].strftime("%Y-%m-%d") == row["end"], row["lord"]
|
||
# 参考日所在的小运仍是引擎值,不是按出生比例重算的。
|
||
assert sub["current"]["antardasha"]["lord"] == next(
|
||
row["lord"] for row in full.values() if row["start"] <= datetime(2026, 11, 9) < row["end"])
|
||
|
||
|
||
def test_f_second_cycle_is_named_and_the_running_row_is_unique() -> None:
|
||
"""(f) 第二轮大运:当前段带 cycle_index 2、年数等于引擎值;Vimshottari 跨 120 年后同样进第二轮。"""
|
||
data = engine("f_second_cycle")
|
||
md = data["narayana"]["current_dasha"]["md"]
|
||
running = data["running_md"]
|
||
assert md["sign"] == running["sign"] == "Aquarius"
|
||
assert md["cycle_index"] == running["cycle_index"] == 2
|
||
assert md["years"] == running["years"] == 11
|
||
# 24 行里只有一行覆盖参考年龄;没有把第二轮当成「还没算」。
|
||
rows = data["narayana"]["mahadasha"]
|
||
live = [row for row in rows if row["start_age"] <= SECOND_CYCLE_AGE < row["end_age"]]
|
||
assert len(live) == 1 and live[0]["sign"] == md["sign"] and live[0]["cycle_index"] == 2
|
||
vim = data["vimshottari"]
|
||
assert vim["first_cycle_years"] == 120
|
||
assert vim["current"]["cycle"] == 2 and vim["current"]["lord"] == "Moon"
|
||
assert vim["current"]["years"] == 10
|
||
|
||
|
||
def test_g_zero_year_period_is_kept_in_the_data_and_never_current() -> None:
|
||
"""(g) 0 年大运:段本身留在数据里并带 zero_duration,当前大运绝不是 0 年段。"""
|
||
data = engine("g_zero_duration")
|
||
zero = data["zero_row"]
|
||
assert (zero["sign"], zero["years"], zero["cycle_index"]) == ("Sagittarius", 0, 1)
|
||
assert zero["zero_duration"] is True and zero["start_age"] == zero["end_age"]
|
||
# 半开区间 [start, end):0 年段占不到任何年龄,参考日落在它的起点也不是它。
|
||
product = data["narayana"]
|
||
assert product["current_dasha"]["md"]["sign"] == "Aquarius"
|
||
assert product["current_dasha"]["md"]["years"] == 11
|
||
assert product["current_dasha"]["md"]["start_age"] == data["age"]
|
||
signs = [row["sign"] for row in product["mahadasha"] if row["sign"] == "Sagittarius"]
|
||
assert signs, "0 年段必须留在 mahadasha 数据里"
|
||
kept = next(row for row in product["mahadasha"] if row["sign"] == "Sagittarius")
|
||
assert kept["years"] == 0 and kept["zero_duration"] is True
|
||
|
||
|
||
def test_fixtures_cover_all_seven_counterexamples() -> None:
|
||
assert sorted(CASES) == [
|
||
"a_missing_moon_paksha", "b_low_grade_undecided", "c_ad_blocked_md_known",
|
||
"d_moon_self_reference", "e_birth_balance", "f_second_cycle", "g_zero_duration",
|
||
]
|
||
for name in CASES:
|
||
payload = FIXTURES[name]
|
||
assert payload["reference_date"] == REFERENCE_DATE
|
||
assert payload["engine"]
|
||
|
||
|
||
@pytest.mark.parametrize("case", sorted(CASES))
|
||
def test_no_real_person_data_in_fixtures(case: str) -> None:
|
||
"""公开名人盘只以公开的出生日期出现;不得有姓名、邮箱、会话或用户标识。"""
|
||
text = (OUT / f"{case}.json").read_text(encoding="utf-8")
|
||
for marker in ("@", "password", "jwt", "cookie", "case_id"):
|
||
assert marker not in text.lower(), (case, marker)
|