Files
Jyotisha/tests/test_synastry_full_reader_gate.py
T
ClaudeandClaude Opus 5.5 0f8c0508bc feat(annual,synastry): run the astrologer's tajika-annual and full-synastry skills in full
Annual (产品 2026-11-07 占星师方案 item 9):
- package: optional current-city return location (default birth place, disclosed);
  annual Shadbala; Varsha Narayana (PVR ch.30.4 port of the upstream entry on the
  product's Rath Narayana); transit_context with Sade Sati phase, natal
  Ashtakavarga of each slow ingress and slow-body Vedha; not_included updated
- report_facts: year overview carries Sahams by domain, Panchavargiya/Harsha,
  annual Shadbala, Tajika aspects, Varsha Narayana; phases carry Varsha MD/AD and
  Sade Sati; ingress events carry BAV/SAV; audit rows split (Transits, Sade Sati,
  Transit AV, Vedha, Sahams, Annual Shadbala, Varsha Narayana) and consistent
- writer: full layer (both natal tracks per domain, Mudda/Patyayini four layers,
  year chart) instead of the plain layer; professional rules: evidence first,
  terms explained, dual-track timing, A/B/C confidence capped by the program,
  parameter_sensitive/blocked kept; Tajika yogas stay non-factors (3509ccd7)
- page: current-city picker, evidence/timing/confidence lines

Synastry:
- writer gets relationship_promise and pair_promise_links; four event classes
  with both-person activation (Vimshottari, Narayana, transits); calendar
  overlap is not resonance; English timeline carries parallel timing and the
  resonance gate; profile_gate/delivery_readiness enforced; same ayanamsa for
  both; sections follow customer-report-shape.md; source_modules not truncated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
2026-11-07 14:42:26 +08:00

233 lines
11 KiB
Python

"""Relationship-language gate. The guide's example, padded to the length floor, passes."""
from __future__ import annotations
import copy
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SCRIPTS = ROOT / "scripts"
if str(SCRIPTS) not in sys.path:
sys.path.insert(0, str(SCRIPTS))
from marriage_match_service.synastry_full_reader_gate import validate_synastry_reader
GUIDE = (
"你们这段关系的底色是有吸引,但节奏不同。刚靠近时,彼此容易觉得对方身上有自己缺的东西,所以会有自然的牵引。"
"真正进入日常后,差异会浮出来:一个更习惯用行动表达关心,一个更需要语言和情绪回应;压力大的时候,一个想立刻解决,一个想先躲开。"
"这不是谁对谁错,而是你们的安全感开关不在同一个位置。你们的优势在于,只要愿意把话说明白,理解力是在的;"
"难点在于,情绪上来时容易把我需要空间听成你不在乎我。长期看,这段关系不是靠感觉自动顺滑的类型,"
"而是靠两个人把日常回应、冲突修复和现实安排一点点对齐。如果愿意练,它会长出很稳的默契;如果回避差异,摩擦会反复出现在同一个地方。"
)
FILLER = "你们可以慢慢把彼此的节奏说清楚,把靠近、停顿和修复都留在两个人都能接受的距离里。"
def _prose(seed: str) -> str:
text = seed
while len(text.replace(" ", "")) < 280:
text += FILLER
return text
def _reason(plain: str, basis: str, evidence: str) -> dict:
return {
"plain": plain,
"basis": basis,
"evidence": evidence,
"label": "single_system_inference",
}
def _passing(language: str = "zh") -> tuple[dict, dict]:
evidence = "金星落在第七宫,同时木星大运覆盖接下来这一段"
inputs = {
section: {"quote": evidence, "note": "双方都需要把靠近说出来"}
for section in (
"climate", "emotion", "communication", "safety", "conflict", "daily", "direction", "practices",
)
}
inputs["timeline"] = {"quote": "程序分好的三段"}
reasons = [
_reason("所以你们靠近时会先感到彼此补上了一块缺口。", evidence, evidence),
_reason("所以压力一大,一个想说开,一个想先留出空间。", evidence, evidence),
]
# 原值:关系基调 … 长期方向(体验式九节);新值:占星师 skill 的报告顺序与标题
# 原因:产品 2026-11-07 占星师方案:年报/合盘完整运行 skill
titles = ("结论总纲", "各自带着什么进入关系", "命局承诺", "配偶与婚姻承载", "两盘交感", "能否久处", "辅助证据与边界")
sections = []
for index, section_id in enumerate(("climate", "emotion", "communication", "safety", "conflict", "daily", "direction")):
text = _prose(GUIDE if index == 0 else f"你们在{titles[index]}上需要彼此对齐。{GUIDE}")
if language == "en":
text = " ".join(["You two meet a different pace and can still name what each person needs."] * 90)
sections.append({
"id": section_id,
"title": titles[index],
"text": text,
"reasons": reasons if language == "zh" else [
_reason("So closeness asks both of you to say what care looks like.", "Venus in the 7th house during Jupiter dasha", evidence),
_reason("So pressure sends one person toward talk and the other toward room.", "Venus in the 7th house during Jupiter dasha", evidence),
],
})
if language == "en":
evidence = "Venus in the 7th house during Jupiter dasha"
for section_id, payload in inputs.items():
if section_id == "timeline":
continue
payload["quote"] = evidence
for section in sections:
if section["id"] == "timeline":
continue
for reason in section["reasons"]:
reason["evidence"] = evidence
reason["basis"] = evidence
timeline_index = len(sections) - 1 # timeline sits before direction now
sections.insert(timeline_index, {
"id": "timeline",
"segments": [
{"id": "s1", "phase": "靠近", "text": _prose("这段时间你们适合慢慢认识,把节奏说清楚。") if language == "zh" else "This stretch is for learning each other's pace. " * 20, "basis": evidence},
{"id": "s2", "phase": "对齐", "text": _prose("这段时间适合把日常安排摊开谈。") if language == "zh" else "This stretch is for naming daily arrangements. " * 20, "basis": evidence},
{"id": "s3", "phase": "稳住", "text": _prose("这段时间关系看你们是否把差异留在桌上。") if language == "zh" else "This stretch shows whether differences stay discussable. " * 20, "basis": evidence},
],
})
practice = "挑一件日常回应,这周各自说一次自己需要的靠近方式。" if language == "zh" else "Pick one daily response and each say what closeness you need."
sections.append({
"id": "practices",
"items": [{"text": practice, "evidence": evidence if language == "en" else "金星落在第七宫,同时木星大运覆盖接下来这一段"}],
})
return {"sections": sections}, inputs
def test_guide_example_passes_when_length_and_reasons_are_filled():
delivery, inputs = _passing("zh")
result = validate_synastry_reader(delivery, inputs, "zh")
assert result["ok"], result["failures"]
def test_english_guide_shape_passes():
delivery, inputs = _passing("en")
result = validate_synastry_reader(delivery, inputs, "en")
assert result["ok"], result["failures"]
def _one(delivery: dict, inputs: dict, language: str = "zh") -> set[str]:
result = validate_synastry_reader(delivery, inputs, language)
assert result["ok"] is False
return {row["code"] for row in result["failures"]}
def test_basis_house_that_is_not_in_the_evidence_fails():
delivery, inputs = _passing("zh")
delivery["sections"][0]["reasons"][0]["basis"] = "金星落在第七宫,改成第八宫"
assert "basis_mismatch" in _one(delivery, inputs)
def _section(delivery: dict, section_id: str) -> dict:
return next(row for row in delivery["sections"] if row["id"] == section_id)
def test_each_banned_insertion_fails_once():
# 原值:「金星」「七宫」都是 banned_term;新值:术语可用,缩写第一次出现不解释才失败
# 原因:产品 2026-11-07 占星师方案:年报/合盘完整运行 skill
samples = {
"UL 在这里": "unexplained_term",
"22 分": "score",
"注定": "banned_judgement",
"2027 年结婚": "dated_event",
"宿曜": "supplementary_method",
"execution_receipt": "private_term",
}
for snippet, code in samples.items():
delivery, inputs = _passing("zh")
delivery["sections"][1]["text"] += snippet
assert code in _one(delivery, inputs), snippet
def test_analytic_opening_missing_section_and_missing_claim_fail():
delivery, inputs = _passing("zh")
delivery["sections"][0]["text"] = "这段关系的核心不是顺滑。" + delivery["sections"][0]["text"]
assert "analytic_opening" in _one(delivery, inputs)
delivery, inputs = _passing("zh")
delivery["sections"] = [row for row in delivery["sections"] if row["id"] != "safety"]
assert "section_order" in _one(delivery, inputs)
delivery, inputs = _passing("zh")
delivery["sections"][2]["reasons"] = delivery["sections"][2]["reasons"][:1]
assert "reason_count" in _one(delivery, inputs)
def test_evidence_must_be_a_complete_field():
delivery, inputs = _passing("zh")
delivery["sections"][0]["reasons"][0]["evidence"] = "金"
assert "evidence_missing" in _one(delivery, inputs)
def test_status_only_field_is_not_evidence():
delivery, inputs = _passing("zh")
inputs["climate"]["status"] = "executed"
delivery["sections"][0]["reasons"][0]["evidence"] = "executed"
assert "evidence_missing" in _one(delivery, inputs)
def test_d_chart_must_be_explained_the_first_time():
# 原值:「看D9」是 banned_term;新值:D9 可用,但第一次出现要括号解释
# 原因:产品 2026-11-07 占星师方案:年报/合盘完整运行 skill
delivery, inputs = _passing("zh")
delivery["sections"][1]["text"] += "看D9"
assert "unexplained_term" in _one(delivery, inputs)
delivery, inputs = _passing("zh")
delivery["sections"][1]["text"] += "金星落在第七宫,D9(九分盘,看承诺能否落到长期)也确认,UL(上升婚姻点)同样支持,之后再说 D9 就不必重复。"
result = validate_synastry_reader(delivery, inputs, "zh")
assert result["ok"], result["failures"]
def test_timeline_phase_is_scanned():
# 原值:phase 写「大运」失败(banned_term);新值:术语可用,判语「注定」仍失败
# 原因:产品 2026-11-07 占星师方案:年报/合盘完整运行 skill
delivery, inputs = _passing("zh")
_section(delivery, "timeline")["segments"][0]["phase"] = "注定"
assert "banned_judgement" in _one(delivery, inputs)
def test_english_terms_are_allowed_when_explained():
# 原值:英文出现 kuja / Venus 即 banned_term;新值:术语可用;原因同上
delivery, inputs = _passing("en")
delivery["sections"][1]["text"] += " Venus and kuja "
result = validate_synastry_reader(delivery, inputs, "en")
assert result["ok"], result["failures"]
def test_limited_scope_rejects_consensus_labels_and_blocked_scope_rejects_the_report():
"""delivery_readiness not ready: no full conclusion; profile gate not passed: no report (builder:1154)."""
delivery, inputs = _passing("zh")
for payload in inputs.values():
payload["reading_scope"] = {"status": "limited", "reason": "primary lanes"}
result = validate_synastry_reader(delivery, inputs, "zh")
assert result["ok"], result["failures"]
delivery["sections"][0]["reasons"][0]["label"] = "multi_system_consensus"
assert "scope_limited_consensus" in _one(delivery, inputs)
delivery, inputs = _passing("zh")
inputs["climate"]["reading_scope"] = {"status": "blocked", "reason": "calculation_profile_mismatch"}
assert "scope_blocked" in _one(delivery, inputs)
def test_a_body_that_opens_with_the_section_title_fails():
delivery, inputs = _passing("zh")
delivery["sections"][2]["text"] = "命局承诺 命局承诺 " + delivery["sections"][2]["text"]
assert "repeated_heading" in _one(delivery, inputs)
delivery, inputs = _passing("en")
delivery["sections"][2]["title"] = "Each Chart's Relationship Promise"
delivery["sections"][2]["text"] = "Each Chart's Relationship Promise " + delivery["sections"][2]["text"]
assert "repeated_heading" in _one(delivery, inputs, "en")
def test_english_banned_word_fails():
# 原值:" Venus " → banned_term;新值:判语 soulmate → banned_judgement;原因:产品 2026-11-07 占星师方案(术语可用)
delivery, inputs = _passing("en")
delivery["sections"][1]["text"] += " soulmate "
assert "banned_judgement" in _one(delivery, inputs, "en")
delivery, inputs = _passing("en")
delivery["sections"][0]["text"] = "The core of this relationship is not ease. " + delivery["sections"][0]["text"]
assert "analytic_opening" in _one(delivery, inputs, "en")