Product order 2026-11-07: birth-time rectification follows the astrologer's skill (yinduzhanxing 5fb8379c) in full. The chart-choice page stays; her method is added as a stage and both results are shown side by side. - scripts/chart_choice/astrologer.py, POST /api/chart_choice/astrologer: minute-by-minute scan of D1/D2/D3/D4/D7/D9/D10/D12/D20/D24/D30/D60 (D60 reference only), ascendant nakshatra/pada, KP sub-lord, A7/UL/A10; her five stages (intake, appearance/birthmark screens, event verification with Vimshottari MD/AD/PD + Narayana MD/AD per event and the >=5-event gate, D9/D10 trait correction, report); her 40/35/15/10 scoring, match-rate tiers (80/60), report confidence (90/70) and engine confidence; family (六亲) event categories; D30 only with health-type events; Gochara blocked; our 77-case backtest caveat on every result. - active_rectification_questions.py synced to upstream (question_bank, bindings, workflow_status), local adaptations marked LOCAL, accepts an in-process minute_scan. - Frontend: /api/chart-choice/astrologer and an AstrologerStage step, reachable from the result, the no-line case and the current record. - Consultation reads the other version for domains kept 「两版都读」 (provenance now records other_saved_at). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
135 lines
6.5 KiB
Python
135 lines
6.5 KiB
Python
from __future__ import annotations
|
||
|
||
from scripts.active_rectification_questions import build_questionnaire, score_answers
|
||
|
||
|
||
def test_active_rectification_questions_generate_choice_based_workflow() -> None:
|
||
report = build_questionnaire("2001-02-03 10:20", uncertainty_minutes=30)
|
||
|
||
assert report["scope"] == "active_birth_time_rectification_questionnaire"
|
||
assert report["candidate_scan"]["start"] == "2001-02-03 09:50"
|
||
assert report["candidate_scan"]["end"] == "2001-02-03 10:50"
|
||
assert report["candidate_scan"]["candidate_count"] == 61
|
||
assert len(report["candidate_scan"]["samples"]) == 61
|
||
assert report["candidate_scan"]["sensitivity_summary"]["method"] == "minute_feature_scan_v2"
|
||
assert "high_information_question_generation" in report["workflow"]
|
||
assert {"D9", "D10", "D24", "D30", "UL", "A10", "KP_cusp"} <= set(report["sensitivity_layers"])
|
||
# 原值:report["questions"] 是全部 8 道题。
|
||
# 新值:上游把全部题放在 question_bank,questions 只放选题器挑出的下一题。
|
||
# 原因:产品 2026-11-07:生时校正按占星师 skill 完整执行(问卷同步上游 5fb8379c)
|
||
assert len(report["question_bank"]) >= 8
|
||
assert len(report["questions"]) == 1
|
||
assert {q["round"] for q in report["question_bank"]} == {1, 2, 3}
|
||
assert all({option["key"] for option in q["options"]} == {"A", "B", "C", "D"} for q in report["question_bank"])
|
||
assert all("scoring_map" in q for q in report["question_bank"])
|
||
assert report["candidate_scan"]["samples"]
|
||
assert report["candidate_scan"]["sensitivity_summary"]
|
||
assert {"D9", "D10", "D24", "D30", "UL", "A10", "KP_cusp"} <= set(
|
||
report["candidate_scan"]["sensitivity_summary"]["high_value_layers"]
|
||
)
|
||
assert report["candidate_scan"]["samples"][0]["cluster"] == "early_candidate_cluster"
|
||
assert report["candidate_scan"]["samples"][-1]["cluster"] == "late_candidate_cluster"
|
||
assert report["selection"]["selected_questions"]
|
||
assert all("factual_reliability" in question for question in report["question_bank"])
|
||
assert all("positive_cluster" in question and "negative_cluster" in question for question in report["question_bank"])
|
||
|
||
|
||
def test_active_rectification_scores_answers_and_selects_next_round() -> None:
|
||
report = build_questionnaire("2001-02-03 10:20", uncertainty_minutes=30)
|
||
scored = score_answers(
|
||
report,
|
||
{
|
||
"education_environment_shift": "A",
|
||
"residence_relocation_shift": "B",
|
||
"relationship_or_partner_entry": "D",
|
||
"career_responsibility_pressure": "A",
|
||
"research_tool_expression_shift": "C",
|
||
},
|
||
)
|
||
|
||
assert scored["scope"] == "active_birth_time_rectification_scoring"
|
||
assert scored["answered_count"] == 5
|
||
assert scored["next_round"] == 2
|
||
assert scored["next_round_questions"]
|
||
assert scored["next_round_selection"]["selected_questions"]
|
||
assert scored["candidate_cluster_rankings"][0]["score"] > scored["candidate_cluster_rankings"][-1]["score"]
|
||
assert "does not convert candidates into birth-time truth" in scored["boundary"]
|
||
|
||
|
||
def test_active_rectification_recasts_candidate_vargas_when_location_is_available() -> None:
|
||
report = build_questionnaire(
|
||
"2001-02-03 10:20",
|
||
uncertainty_minutes=1,
|
||
lat=25.04,
|
||
lon=121.56,
|
||
tz=8,
|
||
)
|
||
summary = report["candidate_scan"]["sensitivity_summary"]
|
||
assert "true_varga_recast" in summary["computed_layers"]
|
||
assert "true_arudha_recast" in summary["computed_layers"]
|
||
assert "true_kp_cusp_recast" in summary["computed_layers"]
|
||
assert "true_varga_recast" not in summary["blocked_layers"]
|
||
assert "true_kp_cusp_recast" not in summary["blocked_layers"]
|
||
sample = report["candidate_scan"]["samples"][1]
|
||
assert sample["varga_lagna"]["D2_Hora"]["sign"]
|
||
assert sample["varga_lagna"]["D4_Turyamsa"]["sign"]
|
||
assert sample["varga_lagna"]["D11_Rudramsa"]["sign"]
|
||
assert sample["varga_lagna"]["D9_Navamsa"]["sign"]
|
||
assert sample["varga_lagna"]["D10_Dasamsa"]["sign"]
|
||
assert sample["arudha"]["A7"]["sign"]
|
||
assert sample["arudha"]["A10"]["sign"]
|
||
assert sample["arudha"]["UL"]["sign"]
|
||
assert sample["kp_cusps"]["house_7"]["sub_lord"]
|
||
assert sample["kp_cusps"]["house_10"]["sub_sub_lord"]
|
||
|
||
|
||
def test_active_rectification_requires_dated_event_review_after_all_question_rounds() -> None:
|
||
"""Synced from upstream: once no question can separate candidates, ask for dated events."""
|
||
report = {
|
||
"question_bank": [
|
||
{
|
||
"id": "fine_only",
|
||
"domain": "fine_timing",
|
||
"prompt": "关键变化更像先有内在转向、后有外部结果,还是几乎同时发生?",
|
||
"sensitivity": ["KP_cusp"],
|
||
"scoring_map": {
|
||
"A": {"cluster": "neutral", "points": 0},
|
||
"B": {"cluster": "neutral", "points": 0},
|
||
"C": {"cluster": "neutral", "points": 0},
|
||
"D": {"cluster": "neutral", "points": 0},
|
||
},
|
||
}
|
||
],
|
||
"candidate_scan": {"candidate_count": 61},
|
||
}
|
||
scored = score_answers(report, {"fine_only": "A"})
|
||
|
||
assert scored["next_round_questions"] == []
|
||
assert scored["workflow_status"] == "dated_event_review_required"
|
||
assert scored["can_apply"] is False
|
||
assert scored["required_next_evidence"] == {
|
||
"kind": "dated_life_events",
|
||
"minimum_events": 4,
|
||
"minimum_domains": 3,
|
||
}
|
||
|
||
|
||
def test_active_rectification_questions_expose_why_and_audit_bindings() -> None:
|
||
"""Synced from upstream: every question says why it is asked and what each answer does."""
|
||
report = build_questionnaire("2001-02-03 10:20", uncertainty_minutes=30)
|
||
|
||
for question in report["question_bank"]:
|
||
assert any("为什么问" in line for line in question["why_this_question"])
|
||
assert {"A", "B", "C", "D"} <= set(question["answer_impact"].keys())
|
||
assert question["audit_binding"]["primary_varga"]
|
||
assert question["audit_binding"]["dasha_tracks"]
|
||
assert question["audit_binding"]["reason"]
|
||
|
||
|
||
def test_active_rectification_questions_accept_precomputed_minute_scan() -> None:
|
||
"""LOCAL: an in-process minute scan is used as given, no engine subprocess is started."""
|
||
scan = {"rows": [{"time": "2001-02-03 10:20", "sensitivity_count": 0, "sensitive_layers": []}], "transitions": []}
|
||
report = build_questionnaire("2001-02-03 10:20", uncertainty_minutes=1, minute_scan=scan)
|
||
|
||
assert report["candidate_scan"]["minute_scan"] is scan
|