feat(reading): the writer's annual facts carry each year's bounded motion summary — up to 20 dated contacts, sign changes and stations tied to the year's named yogas and lords — with the astrologer's boundary sentence (BUG-2318)

Fictional-chart facts grow 119,739 -> 126,181; budget unchanged at 140,000.
Test sessions keep the motion cache in a temporary directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXp2U3BH1SxwAGyhhbe1
This commit is contained in:
2026-11-24 15:44:33 +08:00
co-authored by Claude Opus 5.5
parent 0ff2d1d395
commit 40b01b82e6
4 changed files with 139 additions and 1 deletions
+17
View File
@@ -31336,3 +31336,20 @@
- 防复发:上述测试。
- 关联记录:BUG-2315、BUG-2316、BUG-2104(读者用词闸)、BUG-2115 / 2129(不给读者写程序库名)。
- 修复版本:`claude/density-b4`。
## BUG-2318 | 写报告的模型拿不到每年的连续运动:哪对星什么时候精确成相、谁换座停滞,以及「这不是事件日期」的边界
- 状态:fixed-pending-verify。
- 首次发现 / 最近更新:2026-11-23(占星师信息密度交接 §2「必须进入报告或模型输入」、§4)/ 2026-11-24。
- 现象:BUG-2315 算出的年度连续运动只在报告附录里;写作用的事实包(`reading_facts` 的 `annual.years`)每年只有年主星、Muntha 和 Mudda 段。
- 触发条件:任何带写作的全资料报告。
- 根因:`reading_facts._annual_year` 没有读 `tajika_condition_status_pack`。
- 修复:`_annual_year` 每年加 `motion`:
- 算出的年份:范围(年盘所在地当地时间)、三类事件次数、最多 20 个事件(日期、类型、行星、角度 / 换入星座 / 转逆行或顺行、属于哪几条 Yoga 或年主星 / Muntha 主星)。先取本年每条具名 Yoga 那一对星的第一次精确成相,再按附录完整列出的那一组(BUG-2317)按时间补足;超出上限时写 `events_left_out` 条数。
- 没算出的年份:`status: not_computed` 和中文原因,不给事件。
- `annual.motion_boundary_zh` 写一次占星师的边界:这些时刻是算出的接触、换座和停滞,不是人生事件日期;某对星精确成相不等于这条 Yoga 已按传统完成兑现;没算出的年份不能写成「没有变化」。
- 体积:`tests/test_report_reading_facts.py` 的虚构盘夹具改为和报告接口一样先挂年度运动(缓存目录隔离在本模块),事实包 119,739 → 126,181(+6,442,每年约 2,100),上限仍是 140,000,没有调高。
- 验证:新增 `test_each_annual_year_carries_a_bounded_motion_summary`(三年各有自己的范围、事件按日期排列且不超过 20 个、类型为中文、边界句在);`test_report_reading_facts.py` 10 条全过。`tests/conftest.py` 加自动夹具,把年度运动缓存放到每次测试会话的临时目录,不写进仓库的 `scratch/local`。
- 防复发:上述测试与体积上限。
- 关联记录:BUG-2315、BUG-2317、BUG-2223(三年年度系列)。
- 修复版本:`claude/density-b4`。
+77
View File
@@ -1243,6 +1243,9 @@ def _annual_year(pack: Any) -> dict[str, Any]:
muntha = dig(pack, "muntha.data")
if isinstance(muntha, dict):
out["muntha"] = {**_pick(muntha, ("muntha_sign", "muntha_lord")), **_pick(pack.get("muntha"), ("status",))}
motion = _annual_motion(pack)
if motion:
out["motion"] = motion
periods = dig(pack, "mudda_dasha.periods")
out["mudda_periods"] = [
{**_pick(row, ("lord",)), **{key: _day(row.get(key)) for key in ("start", "end") if _day(row.get(key))}}
@@ -1251,6 +1254,77 @@ def _annual_year(pack: Any) -> dict[str, Any]:
return out
ANNUAL_MOTION_EVENT_CAP = 20
ANNUAL_MOTION_BOUNDARY_ZH = ("年度连续运动里的时刻是算出的行星接触、换座和停滞,不是人生事件日期;某条 Yoga 的那一对星在年内精确成相,"
"也不等于这条 Yoga 已按传统完成兑现。没有算出的年份不能写成「没有变化」。")
_MOTION_KIND_ZH = {"exact_contact": "精确成相", "ingress": "换座", "station": "停滞"}
def _annual_motion(pack: dict) -> dict[str, Any]:
"""BUG-2318: a bounded summary of one year's continuous motion for the writer (her §4 fields, at most 20 events).
Events chosen in this order until the cap: each of the year's named-yoga rows' first exact contact, then the
events the appendix lists in full (the rows' own contacts and the year lord's / Muntha lord's changes, Moon
left out), in time order. Each event names the rows it belongs to. A year that was not computed says why.
"""
from .annual_motion_appendix import REASON_WORDS, _Clock, _folded, _lords, _shown_rows, select_events
condition = pack.get("tajika_condition_status_pack")
if not isinstance(condition, dict):
return {}
timeline = condition.get("motion_timeline") if isinstance(condition.get("motion_timeline"), dict) else {}
if timeline.get("execution_status") != "executed":
reason = REASON_WORDS.get(str(timeline.get("reason")), {}).get("zh") or "计算没有完成"
return {"status": "not_computed", "reason_zh": reason}
clock = _Clock(dig(pack, "solar_return.data.annual_location") or {})
events = timeline.get("events") if isinstance(timeline.get("events"), list) else []
tags: dict[int, list[str]] = {}
first: list[int] = []
for row in _shown_rows(condition):
evidence = row.get("motion_evidence") if isinstance(row.get("motion_evidence"), dict) else {}
refs = [i for i in evidence.get("contact_refs") or [] if isinstance(i, int) and 0 <= i < len(events)]
for index in refs:
names = tags.setdefault(index, [])
if row.get("yoga") not in names:
names.append(str(row.get("yoga")))
if refs and refs[0] not in first:
first.append(refs[0])
shown, _rest = select_events(pack, condition)
year_lord, muntha_lord = _lords(pack)
chosen = list(dict.fromkeys(first + [index for index, _ in shown]))[:ANNUAL_MOTION_EVENT_CAP]
rows = []
for index in sorted(chosen, key=lambda i: str(events[i].get("timestamp_local"))):
event = events[index]
entry: dict[str, Any] = {"date": clock.local(event.get("timestamp_local"))[:10],
"kind": _MOTION_KIND_ZH.get(str(event.get("kind")), str(event.get("kind"))),
"planets": list(event.get("planets") or [])}
if event.get("kind") == "exact_contact":
entry["angle"] = _folded(event.get("directed_angle"))
elif event.get("kind") == "ingress":
from .text import SIGNS
entry["to_sign"] = SIGNS[event["to_sign_idx"]] if isinstance(event.get("to_sign_idx"), int) else None
elif event.get("kind") == "station":
entry["turns"] = "逆行" if event.get("direction_after") == "retrograde" else "顺行"
names = list(tags.get(index, []))
planets = set(entry["planets"])
if event.get("kind") == "exact_contact" and year_lord and muntha_lord and planets == {year_lord, muntha_lord}:
names.append("年主星与 Muntha 主星")
if year_lord in planets and event.get("kind") != "exact_contact":
names.append("年主星")
if muntha_lord in planets and event.get("kind") != "exact_contact":
names.append("Muntha 主星")
if names:
entry["for"] = names
rows.append(entry)
counts = {_MOTION_KIND_ZH[kind]: sum(1 for event in events if event.get("kind") == kind) for kind in _MOTION_KIND_ZH}
span = timeline.get("range") if isinstance(timeline.get("range"), dict) else {}
return {"status": "computed",
"range": {"start": clock.local(span.get("start")), "end": clock.local(span.get("end_exclusive"))},
"event_counts": counts, "events": rows,
**({"events_left_out": len(set(first) | {index for index, _ in shown}) - len(rows)}
if len(set(first) | {index for index, _ in shown}) > len(rows) else {})}
def _annual_series(packet: dict) -> list[dict[str, Any]]:
years = dig(packet, ANNUAL_SERIES)
if not isinstance(years, dict):
@@ -1294,6 +1368,9 @@ def _annual(packet: dict) -> dict[str, Any]:
series = _annual_series(packet)
if series:
out["years"] = series
# BUG-2318: the astrologer's claim boundary for the motion summaries, said once.
if any("motion" in row for row in series):
out["motion_boundary_zh"] = ANNUAL_MOTION_BOUNDARY_ZH
return out
+9
View File
@@ -56,6 +56,15 @@ def _isolate_vedastro_snapshot_cache(tmp_path_factory, monkeypatch) -> None:
monkeypatch.setenv("JYOTISH_VEDASTRO_SNAPSHOT_NEGATIVE_CACHE_DIR", str(negative_dir))
@pytest.fixture(autouse=True)
def _isolate_annual_motion_cache(tmp_path_factory, monkeypatch) -> None:
"""BUG-2315: the report's per-year motion cache stays out of the repository's scratch/local.
One directory per test session, so the public charts are scanned once per session.
"""
monkeypatch.setenv("JYOTISH_ANNUAL_MOTION_CACHE_DIR", str(tmp_path_factory.getbasetemp() / "annual_motion_timeline"))
_FOREGROUND_EXECUTOR_MODULES = (
"scripts.vedastro_foreground",
"vedastro_foreground",
+36 -1
View File
@@ -9,6 +9,7 @@ from __future__ import annotations
import copy
import json
import os
import pytest
@@ -21,11 +22,23 @@ from tests.test_report_reader_main import FICTIONAL
@pytest.fixture(scope="module")
def chart():
def chart(tmp_path_factory):
case = dict(FICTIONAL)
reading = cmd_full_reading(type("Args", (), case)())
packet = dict(build_professional_report_reference_packet(reading, _export_args(case), []))
packet["report_version"] = "pl9_personal_long_report.v3"
# BUG-2318: as the report API does (BUG-2315), each year's continuous motion is on the packet, so the
# size budget below covers the motion summaries. Cache isolated to this module.
from scripts.report_render.annual_motion import attach_annual_motion
saved = os.environ.get("JYOTISH_ANNUAL_MOTION_CACHE_DIR")
os.environ["JYOTISH_ANNUAL_MOTION_CACHE_DIR"] = str(tmp_path_factory.mktemp("annual_motion"))
try:
attach_annual_motion(packet)
finally:
if saved is None:
os.environ.pop("JYOTISH_ANNUAL_MOTION_CACHE_DIR", None)
else:
os.environ["JYOTISH_ANNUAL_MOTION_CACHE_DIR"] = saved
return case, reading, packet
@@ -75,9 +88,31 @@ def test_reading_facts_are_packet_leaves(chart) -> None:
# BUG-2289–2296 原值 < 120000;新值 < 140000;原因:占星师 2026-11-23 信息密度交接,负责人 2026-11-24 同意分批补回
# 已算出的结构(完整定位链、Argala、年度格局参与星、每条格局的支持与限制,约 7,000)和她的作用路径(约 10,000),
# 这张虚构盘约 130,800。
# BUG-2318: with each year's motion summary (at most 20 events a year, about 2,100 per year) this chart is
# about 126,200; the budget is unchanged.
assert len(encoded) < 140_000
def test_each_annual_year_carries_a_bounded_motion_summary(chart) -> None:
"""BUG-2318: her §4 fields per year for the writer, bounded, with her claim boundary said once."""
_case, reading, packet = chart
facts = build_report_reading_facts(packet, reading, minute_confirmed=True, today="2026-04-07")
years = facts["annual"]["years"]
assert len(years) == 3
starts = []
for row in years:
motion = row["motion"]
assert motion["status"] == "computed"
assert 0 < len(motion["events"]) <= 20
assert [event["date"] for event in motion["events"]] == sorted(event["date"] for event in motion["events"])
assert set(motion["event_counts"]) == {"精确成相", "换座", "停滞"}
assert all(event["kind"] in {"精确成相", "换座", "停滞"} and event["planets"] for event in motion["events"])
starts.append(motion["range"]["start"])
assert len(set(starts)) == 3
assert "不是人生事件日期" in facts["annual"]["motion_boundary_zh"]
assert "已按传统完成兑现" in facts["annual"]["motion_boundary_zh"]
def test_reading_facts_carry_the_full_contract(chart) -> None:
"""产品 2026-11-07 占星师方案 item 10: every layer of the contract is present and packet-sourced."""
_case, reading, packet = chart