From bf37929df3df2d063fdb5e4b994f9577466a959e Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 21:50:54 +0800 Subject: [PATCH] fix(report): the additional timing block groups each technique's variants under one chapter (94 to 69 chapters, no data dropped) (BUG-2100) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq --- docs/BUG_HISTORY.md | 13 ++ scripts/report_render/upstream_coverage.py | 10 +- scripts/research_timing/render.py | 195 +++++++++++++++++++-- tests/test_full_data_parity_chapters.py | 4 + tests/test_report_chapter_grouping_2100.py | 170 ++++++++++++++++++ tests/test_research_timing.py | 13 ++ 6 files changed, 388 insertions(+), 17 deletions(-) create mode 100644 tests/test_report_chapter_grouping_2100.py diff --git a/docs/BUG_HISTORY.md b/docs/BUG_HISTORY.md index 44c516a31..94fec6692 100644 --- a/docs/BUG_HISTORY.md +++ b/docs/BUG_HISTORY.md @@ -28358,3 +28358,16 @@ - 验证与防复发:`tests/test_chart_choice_astrologer.py`、`tests/test_chart_choice.py` 通过(读同一常量);生时纠正前端测试通过。 - 关联记录:BUG-2097(年运依据去掉同类说法)。 - 修复版本:`claude/rect-reference-line`。 + +## BUG-2100 | 个人报告「补充推运计算数据」一段有三十多个同类章节,目录很长 + +- 状态:fixed-pending-verify(待测试环境重新生成报告确认)。 +- 首次发现 / 最近更新:2026-11-20 / 2026-11-20。 +- 触发与现象:证据包窗口复测时看到一份个人报告有约 100 个数据章节,其中二十多章是「年度 Tithi Ashtottari … 配对 N」这一类,目录展开很长。公开盘乔布斯一份有 94 章,其中 38 章在这一段。产品负责人 2026-11-20 同意归并:同一类的变体放到一个大标题下当小标题,数据一条不少,并确认了归并后的章节清单。 +- 触发条件:任何用户生成个人报告。 +- 根因:`scripts/research_timing/render.py` 给每个变体(每年每种余额每个方向、每个辅助系统)都单独出一个二级标题。 +- 修复:这一段每种技法一个二级标题,变体作为三级标题:本命 Tithi Ashtottari(顺行、逆行)、年度 Tithi Ashtottari(年份和组数取自数据)、年度 Yoga Pravesha、年度 Nakshatra Pravesha、年度主星(Julene、PVR 象限、PVR 360 太阴月年)、Sudasa、Varnada、辅助大运次小运数据(Sthira、Drig、Shoola、Navamsha、Niryaana Shoola、Kalachakra);本命 Yoga Vimshottari、七分盘星座主、Buddhi Gati、Kaala 仍各自一章。同一类里逐字相同的说明(研究材料横幅、「收录的教程没有写明第三层」等)只在大标题下印一次,各表自己的时钟说明留在各自的变体下。中英文两版同样处理。章节数:乔布斯 94 → 69,奥巴马 92 → 69。`upstream_coverage.py` 的覆盖检查也认三级标题。 +- 影响:目录里「年度主星」和六个辅助系统现在归「推运」组(原来单独成章时归「本命数据」),这和它们的内容一致。报告内提问按二级章节取材料,每章上限 2 万字;归并后几个大标题下的内容远超这个上限(辅助大运次小运数据约 50 万字),此前单章也有超过的(约 14 万字),按三级标题分段取材料由证据包窗口处理。 +- 验证与防复发:`tests/test_report_chapter_grouping_2100.py`(9 条):两张公开盘中英文两版的二级、三级标题结构,没有四级标题、没有「·」,横幅和共用说明只印一次,12 条时钟说明保留,各表行数与改前一致,目录分组。改前改后四版去掉标题后逐行比对:没有新增行,表格行(乔布斯 19178 行、奥巴马 16385 行)完全相同且顺序不变,只有重复的说明句变少。`tests/test_research_timing.py`、`tests/test_full_data_parity_chapters.py` 按原值、新值、原因更新。 +- 关联记录:BUG-2088(研究章节时钟说明)、BUG-2093 / BUG-2096(目录与报告内提问)。 +- 修复版本:`claude/report-chapters-2100`。 diff --git a/scripts/report_render/upstream_coverage.py b/scripts/report_render/upstream_coverage.py index 38b60f9aa..c2107338e 100644 --- a/scripts/report_render/upstream_coverage.py +++ b/scripts/report_render/upstream_coverage.py @@ -143,7 +143,10 @@ TOPICS: tuple[Topic, ...] = ( Topic("Saptavarga lord relationships", "七分盘星座主", "Saptavarga lords"), Topic("Buddhi Gati", "Buddhi Gati", "Buddhi Gati"), Topic("Kaala", "Kaala", "Kaala"), - Topic("Sudasa", "Sudasa 出生周期", "Sudasa birth cycle"), + # 原值: ("Sudasa 出生周期", "Sudasa birth cycle") 是一个 `##` 标题 + # 新值: 「## Sudasa」下的「### 出生周期 / Birth cycle」,按连起来的名字对上 + # 原因: BUG-2100 研究章节按技法分组 + Topic("Sudasa", "Sudasa 出生周期", "Sudasa Birth cycle"), Topic("Independent Annual Method Reference", "独立年度方法参考", "Independent Annual Method Reference", "group"), Topic("Three-Year Predictive Ephemeris", "三年逐月星历", "Three-Year Predictive Ephemeris"), Topic("Narayana Method Comparison", "Narayana 口径对照", "Narayana Method Comparison"), @@ -206,6 +209,11 @@ def _sections(markdown: str) -> list[tuple[str, str]]: end = later_no break out.append((text, "\n".join(lines[line_no + 1:end]))) + # BUG-2100: a research variant is a `###` under its family `##` (「Sudasa」 then + # 「出生周期」); it is also listed under the joined name 「Sudasa 出生周期」. + parent = next((head for head in reversed(heads[:index]) if head[1] < level), None) + if level == 3 and parent is not None and parent[1] == 2: + out.append((f"{parent[2]} {text}", out[-1][1])) return out diff --git a/scripts/research_timing/render.py b/scripts/research_timing/render.py index 4239a73e1..3c36b249d 100644 --- a/scripts/research_timing/render.py +++ b/scripts/research_timing/render.py @@ -220,6 +220,7 @@ def _timing_chapter(bundle: dict, language: str, zone: timezone | None = None) - ) parts.append(note + "\n\n" + count_line) families = bundle.get("families") or {} + members: list[dict] = [] for key, family in families.items(): if key in ("annual-returns", "research-vargas"): continue @@ -229,22 +230,170 @@ def _timing_chapter(bundle: dict, language: str, zone: timezone | None = None) - for group in groups: number = group.get("index") or "" suffix = f"return {number}" if language == "en" else f"第 {number} 次" - parts.extend(_variant_sections(group, language, "Karana", suffix, zone)) + members.extend(_variant_members(group, language, "Karana", suffix, zone, number)) else: - parts.extend(_variant_sections(family, language, "Karana", "", zone)) + members.extend(_variant_members(family, language, "Karana", "", zone, None)) continue if key == "varnada" and isinstance(family.get("variants"), list): - parts.extend(_variant_sections(family, language, "Varnada", "", zone)) + members.extend(_variant_members(family, language, "Varnada", "", zone, None)) continue title = _heading(key, language) if not title: continue - parts.append(_family_section(title, family, language, bundle.get("query"), zone)) + members.append({ + "group": _group_key(key), "key": key, "title": title, + "body": _section_body(family, language, bundle.get("query"), zone), + }) + parts.extend(_grouped_blocks(members, language)) return "\n\n".join(parts) +# BUG-2100 (owner 2026-11-20): the ~38 research chapters become family chapters. +# 原值: 每个变体一个 `##`(年度 Tithi Ashtottari 12 个、Varnada 每个星座一个……) +# 新值: 一个技法一个 `##`,变体是它下面的 `###`;同一家族逐字相同的说明只印一次 +# 原因: BUG-2100,目录与自选章节被 38 个同名前缀的章节淹没 +_GROUP_PATTERNS = ( + (re.compile(r"tithi-natal-(forward|reverse)"), "natal-tithi"), + (re.compile(r"tithi-\d{4}-\d+(?:-.*)?"), "annual-tithi"), + (re.compile(r"yoga-\d+-.+"), "annual-yoga"), + (re.compile(r"nakshatra-\d+-.+"), "annual-nakshatra"), + (re.compile(r"sudasa-(confirmed|birth)"), "sudasa"), +) +_REFERENCE_LABEL = ("Reference row", "参考时刻所在") +_SUDASA_SUB = {"sudasa-confirmed": ("confirmed start", "已确认起点"), "sudasa-birth": ("birth cycle", "出生周期")} +_KARANA_SHORT = {"julene": ("Julene", "Julene"), "pvr": ("PVR quadrant", "PVR 象限"), "pvr-tithi-year": ("PVR 360 tithi year", "PVR 360 太阴月年")} + + +def _group_key(key: str) -> str: + for pattern, group in _GROUP_PATTERNS: + if pattern.fullmatch(key): + return group + return key + + +def _sets(count: int, language: str) -> str: + if language == "en": + return f"{count} set" if count == 1 else f"{count} sets" + return f"共 {count} 组" + + +def _group_titles(group: str, members: list[dict], language: str) -> tuple[str, list[str]] | None: + """The family `##` title and one `###` per member; None keeps the members flat.""" + en = language == "en" + sep = ", " if en else "," + if group == "natal-tithi": + subs = [_KIND[language][m["key"].rsplit("-", 1)[1]] for m in members] + return ("Natal Tithi Ashtottari" if en else "本命 Tithi Ashtottari"), subs + if group == "sudasa": + subs = [_SUDASA_SUB[m["key"]][0 if en else 1] for m in members] + return "Sudasa", subs + if group == "annual-tithi": + parsed = [re.fullmatch(r"tithi-(\d{4})-(\d+)(?:-pair-(\d+)-(arc|time)-(forward|reverse))?", m["key"]) for m in members] + if not all(parsed): + return None + pairs = {item.group(3) for item in parsed if item.group(3)} + years = sorted({int(item.group(1)) for item in parsed}) + subs = [] + for item in parsed: + year, number, pair, kind, direction = item.groups() + pieces = [f"{year} return {number}" if en else f"{year} 年第 {number} 次"] + if kind: + pieces += [_KIND[language][kind], _KIND[language][direction]] + if pair and len(pairs) > 1: + pieces.append(f"pair {pair}" if en else f"配对 {pair}") + subs.append(sep.join(pieces)) + span = str(years[0]) if years[0] == years[-1] else f"{years[0]}–{years[-1]}" + title = (f"Annual Tithi Ashtottari ({span}, {_sets(len(members), language)})" if en + else f"年度 Tithi Ashtottari({span} 年,{_sets(len(members), language)})") + return title, subs + if group in ("annual-yoga", "annual-nakshatra"): + tech = _TECH[group.split("-", 1)[1]] + parsed = [re.fullmatch(r"(?:yoga|nakshatra)-(\d+)-(successor|tithi-year)(?:-(\d+))?", m["key"]) for m in members] + if not all(parsed): + return None + numbers = {item.group(1) for item in parsed} + pairs = {item.group(3) for item in parsed if item.group(3)} + subs = [] + for item in parsed: + number, kind, pair = item.groups() + pieces = [] + if len(numbers) > 1: + pieces.append(f"return {number}" if en else f"第 {number} 次") + pieces.append(_KIND[language][kind]) + if pair and len(pairs) > 1: + pieces.append(f"pair {pair}" if en else f"配对 {pair}") + subs.append(sep.join(pieces)) + title = f"Annual {tech} ({_sets(len(members), language)})" if en else f"年度 {tech}({_sets(len(members), language)})" + return title, subs + if group == "karana": + numbers = {m.get("number") for m in members} + profiles: list[str] = [] + subs = [] + for m in members: + profile = m["profile"] + if profile not in profiles: + profiles.append(profile) + label = _KARANA[profile][0 if en else 1] + if len(numbers) > 1: + label = sep.join((label, f"return {m.get('number')}" if en else f"第 {m.get('number')} 次")) + subs.append(label) + names = [_KARANA_SHORT[profile][0 if en else 1] for profile in profiles] + title = f"Annual lords ({', '.join(names)})" if en else f"年度主星({'、'.join(names)})" + return title, subs + if group == "varnada": + return "Varnada", [m["sub"] for m in members] + return None + + +def _grouped_blocks(members: list[dict], language: str) -> list[str]: + order: list[str] = [] + grouped: dict[str, list[dict]] = {} + for member in members: + if member["group"] not in grouped: + order.append(member["group"]) + grouped[member["group"]] = [] + grouped[member["group"]].append(member) + blocks = [] + for group in order: + items = grouped[group] + titles = _group_titles(group, items, language) + if titles is None or (len(items) == 1 and titles[0] == titles[1][0]): + blocks.extend(_family_block(item["title"], language, item["body"]) for item in items) + continue + blocks.append(_group_block(titles[0], language, list(zip(titles[1], items)))) + return blocks + + +def _group_block(title: str, language: str, members: list[tuple[str, dict]]) -> str: + """One `##` family: banner once, captions shared word for word by every member once, then each member as `###`.""" + paragraphs = [] + for _sub, member in members: + note = _pyjhora_note(member["title"], language) + paragraphs.append([part for part in ([note] + member["body"].split("\n\n")) if part.strip()]) + shared: list[str] = [] + if len(members) > 1: + for column in zip(*paragraphs): + first = column[0] + # A table, or the label that introduces one, stays with its member. + if first.lstrip().startswith("|") or first in _REFERENCE_LABEL or any(item != first for item in column): + break + shared.append(first) + text = f"## {title}\n\n{BANNER[language]}" + if shared: + text += "\n\n" + "\n\n".join(item.strip() for item in shared) + for (sub, _member), body in zip(members, paragraphs): + if language == "en" and sub[:1].islower(): + sub = sub[:1].upper() + sub[1:] + text += f"\n\n### {sub}" + rest = body[len(shared):] + if rest: + text += "\n\n" + "\n\n".join(item.strip() for item in rest) + return text + + def _auxiliary_chapter(packet: dict, chart: dict, language: str) -> str: - parts = [_chapter("Auxiliary dasha subperiods" if language == "en" else "辅助大运次小运数据", language, "")] + title = "Auxiliary dasha subperiods" if language == "en" else "辅助大运次小运数据" + parts: list[tuple[str, dict]] = [] birth = datetime(chart["year"], chart["month"], chart["day"]).date() longitudes = chart["longitudes"] original = calculate_rashi_dashas(birth, chart["ascendant"], longitudes) @@ -255,7 +404,6 @@ def _auxiliary_chapter(packet: dict, chart: dict, language: str) -> str: else "次小运从子运星座起顺行,把该子运的时间等分成十二段。主运和子运与原来的表相同。" ) for key, en, zh in _RASHI: - title = en if language == "en" else zh section = copied.get(key) if isinstance(copied.get(key), dict) else {} periods = _third_only(section.get("periods") or []) body = rule + "\n\n" + (_third_table(periods, language) if periods else _reason( @@ -263,7 +411,8 @@ def _auxiliary_chapter(packet: dict, chart: dict, language: str) -> str: "This system has no sub-period rows, so the third level is not listed.", "这个体系没有子运,所以不列次小运。", )) - parts.append(_family_block(title, language, body)) + system = en if language == "en" else zh + parts.append((system, {"title": system, "body": body})) # Product decision 2026-11-06: Niryaana Shoola follows the upstream export # (sub-periods forward from the MD sign, equal parts); the source gives no rule. section = copied.get("niryaana_shoola") if isinstance(copied.get("niryaana_shoola"), dict) else {} @@ -278,9 +427,10 @@ def _auxiliary_chapter(packet: dict, chart: dict, language: str) -> str: "This system has no sub-period rows, so the third level is not listed.", "这个体系没有子运,所以不列次小运。", )) - parts.append(_family_block("Niryaana Shoola", language, body)) - parts.append(_family_block("Kalachakra", language, _kalachakra(packet, language))) - return "\n\n".join(parts) + parts.append(("Niryaana Shoola", {"title": "Niryaana Shoola", "body": body})) + parts.append(("Kalachakra", {"title": "Kalachakra", "body": _kalachakra(packet, language)})) + # BUG-2100: the six systems are `###` under the one auxiliary chapter (were six `##`). + return _group_block(title, language, parts) def _varga_chapter(bundle: dict, language: str) -> str: @@ -297,25 +447,38 @@ def _varga_chapter(bundle: dict, language: str) -> str: return _chapter("Research divisional charts" if language == "en" else "研究型分盘", language, body) -def _variant_sections(family: dict, language: str, fallback: str, suffix: str = "", zone: timezone | None = None) -> list[str]: +def _variant_members(family: dict, language: str, fallback: str, suffix: str = "", zone: timezone | None = None, number=None) -> list[dict]: + group = fallback.lower() variants = family.get("variants") if not isinstance(variants, list) or not variants: - return [_family_block(fallback, language, _text(family, language))] - sections = [] + return [{"group": f"{group}-flat", "key": group, "title": fallback, "body": _text(family, language)}] + members = [] for index, variant in enumerate(variants, start=1): profile = variant.get("profile") + member = {"group": group, "key": group, "number": number} if profile in _KARANA: title = _KARANA[profile][0 if language == "en" else 1] + member["profile"] = profile else: seed = variant.get("seed_sign") + member["sub"] = _name(seed, language) if seed else str(index) title = f"{fallback} {_name(seed, language)}".strip() if seed else f"{fallback} {index}" + if group == "karana": + member["group"] = f"{group}-flat-{index}" if suffix: title = f"{title} {suffix}" - sections.append(_family_section(title, variant, language, None, zone)) - return sections + member["title"] = title + member["body"] = _section_body(variant, language, None, zone) + members.append(member) + return members def _family_section(title: str, family: dict, language: str, query: str | None, zone: timezone | None = None) -> str: + """One variant as its own `##` block (kept for callers that render a single table).""" + return _family_block(title, language, _section_body(family, language, query, zone)) + + +def _section_body(family: dict, language: str, query: str | None, zone: timezone | None = None) -> str: body = [_text(family, language)] periods = family.get("periods") or [] if periods and family.get("status") != "omitted": @@ -329,7 +492,7 @@ def _family_section(title: str, family: dict, language: str, query: str | None, rows = family.get("rows") if rows: body.append(_varga_table(rows, language)) - return _family_block(title, language, "\n\n".join(part for part in body if part)) + return "\n\n".join(part for part in body if part) def _third_only(periods: list[dict]) -> list[dict]: diff --git a/tests/test_full_data_parity_chapters.py b/tests/test_full_data_parity_chapters.py index 2b8461af6..5b70cca6a 100644 --- a/tests/test_full_data_parity_chapters.py +++ b/tests/test_full_data_parity_chapters.py @@ -442,6 +442,10 @@ def test_six_chapters_are_reader_chapters_and_sections_sit_below_them(monkeypatc tail = full.split("\n## " + chapters[0] + "\n", 1)[1] tail = tail.split("\n## " + audit_title + "\n", 1)[0] tail = tail.split("\n## " + sync_titles[0] + "\n", 1)[0] + # 原值: 截到上游同步章为止,研究章节里没有 `###` + # 新值: 再截到研究章节开头;研究章节的变体现在是 `###`,不属于六章的小节 + # 原因: BUG-2100 研究章节按技法分组 + tail = tail.split("\n## " + research_title + "\n", 1)[0] assert _heading_lines(tail, 3)[: len(_chapter_sections()[0])] == [ (dict(SECTIONS)[title] if chapters is zh_chapters else title) for title in _chapter_sections()[0] ] diff --git a/tests/test_report_chapter_grouping_2100.py b/tests/test_report_chapter_grouping_2100.py new file mode 100644 index 000000000..6107274b3 --- /dev/null +++ b/tests/test_report_chapter_grouping_2100.py @@ -0,0 +1,170 @@ +"""BUG-2100: the research timing chapters are grouped one `##` per technique. + +Before: 38 `##` chapters in the block from 「补充推运计算数据」 to the auxiliary +rashi systems (12 annual Tithi Ashtottari variants, one per Varnada sign, ...). +After: one `##` per family, each variant a `###` under it; a banner or caption +that every member of a family repeats word for word prints once under the family. +The parent commit's exports were compared line by line (headings stripped): no +line was added, only the repeated banners and shared captions were printed once, +and the table rows are the same rows in the same order. The checks below keep the +structural side of that comparison for CI. +""" + +from __future__ import annotations + +import re +from pathlib import Path + +import pytest + +from tests.public_chart_reports import public_chart_reports + +ROOT = Path(__file__).resolve().parents[1] + +_START = re.compile(r"(?m)^## (补充推运计算数据|Additional timing calculations)$") +_END = re.compile(r"(?m)^## (研究型分盘|Research divisional charts)$") + +# Measured on the parent commit (6e4b4a394): the table rows in the block, same in both editions. +_TABLE_ROWS = {"steve_jobs_1955_aa": 19178, "barack_obama_1961_aa": 16385} + +_FAMILIES = { + ("steve_jobs_1955_aa", "zh"): [ + ("补充推运计算数据", []), + ("本命 Tithi Ashtottari", ["顺行", "逆行"]), + ("本命 Yoga Vimshottari", []), + ("年度 Tithi Ashtottari(2026–2028 年,共 12 组)", [ + f"{year} 年第 {number} 次,{kind},{direction}" + for year, number in (("2026", 1), ("2027", 2), ("2028", 3)) + for direction in ("顺行", "逆行") for kind in ("角距", "时间余额") + ]), + ("年度 Yoga Pravesha(共 3 组)", ["后继角距,配对 1", "后继角距,配对 2", "360 太阴月年"]), + ("年度 Nakshatra Pravesha(共 2 组)", ["后继角距", "360 太阴月年"]), + ("年度主星(Julene、PVR 象限、PVR 360 太阴月年)", ["Julene 主星", "PVR 象限主星", "PVR 360 太阴月年"]), + ("七分盘星座主", []), + ("Buddhi Gati", []), + ("Kaala", []), + ("Sudasa", ["已确认起点", "出生周期"]), + ("Varnada", ["处女座", "狮子座"]), + ("辅助大运次小运数据", ["Sthira", "Drig", "Shoola", "Navamsha", "Niryaana Shoola", "Kalachakra"]), + ], + ("steve_jobs_1955_aa", "en"): [ + ("Additional timing calculations", []), + ("Natal Tithi Ashtottari", ["Forward", "Reverse"]), + ("Natal Yoga Vimshottari", []), + ("Annual Tithi Ashtottari (2026–2028, 12 sets)", [ + f"{year} return {number}, {kind}, {direction}" + for year, number in (("2026", 1), ("2027", 2), ("2028", 3)) + for direction in ("forward", "reverse") for kind in ("arc balance", "elapsed balance") + ]), + ("Annual Yoga Pravesha (3 sets)", ["Successor arc, pair 1", "Successor arc, pair 2", "360 tithi year"]), + ("Annual Nakshatra Pravesha (2 sets)", ["Successor arc", "360 tithi year"]), + ("Annual lords (Julene, PVR quadrant, PVR 360 tithi year)", ["Julene lords", "PVR quadrant lords", "PVR 360 tithi year"]), + ("Saptavarga lords", []), + ("Buddhi Gati", []), + ("Kaala", []), + ("Sudasa", ["Confirmed start", "Birth cycle"]), + ("Varnada", ["Virgo", "Leo"]), + ("Auxiliary dasha subperiods", ["Sthira", "Drig", "Shoola", "Navamsha", "Niryaana Shoola", "Kalachakra"]), + ], +} +# The second public chart: one Yoga pairing and one Varnada sign; the rest is the same shape. +_FAMILIES[("barack_obama_1961_aa", "zh")] = [ + ("年度 Yoga Pravesha(共 2 组)", ["后继角距", "360 太阴月年"]) if title.startswith("年度 Yoga") else + ("Varnada", ["摩羯座"]) if title == "Varnada" else (title, subs) + for title, subs in _FAMILIES[("steve_jobs_1955_aa", "zh")] +] +_FAMILIES[("barack_obama_1961_aa", "en")] = [ + ("Annual Yoga Pravesha (2 sets)", ["Successor arc", "360 tithi year"]) if title.startswith("Annual Yoga") else + ("Varnada", ["Capricorn"]) if title == "Varnada" else (title, subs) + for title, subs in _FAMILIES[("steve_jobs_1955_aa", "en")] +] + +_CASES = sorted(_FAMILIES) + + +def _block(case: str, language: str) -> str: + _packet, chinese, english = public_chart_reports(case) + text = chinese if language == "zh" else english + start = _START.search(text) + end = _END.search(text) + assert start and end and start.start() < end.start() + return text[start.start():end.start()] + + +def _structure(block: str) -> list[tuple[str, list[str]]]: + families: list[tuple[str, list[str]]] = [] + for line in block.splitlines(): + if line.startswith("## "): + families.append((line[3:].strip(), [])) + elif line.startswith("### "): + families[-1][1].append(line[4:].strip()) + return families + + +@pytest.mark.parametrize("case,language", _CASES) +def test_research_block_has_one_chapter_per_family_with_variants_below(case: str, language: str) -> None: + block = _block(case, language) + assert _structure(block) == _FAMILIES[(case, language)] + # Nothing in the block sits deeper than `###`, and no heading uses 「·」. + assert not re.search(r"(?m)^####", block) + assert all("·" not in line for line in block.splitlines() if line.startswith("#")) + + +@pytest.mark.parametrize("case,language", _CASES) +def test_shared_banner_prints_once_per_family_and_rows_stay(case: str, language: str) -> None: + block = _block(case, language) + banner = "研究口径:依赖所选方法,未经外部软件核对。" if language == "zh" else ( + "Research basis: method-dependent; not checked against external software.") + chapters = len(re.findall(r"(?m)^## ", block)) + assert chapters == 13 + assert block.count(banner) == chapters + # The 12 annual Tithi Ashtottari tables share one caption: printed once, under the family. + shared = "收录的教程没有写明第三层。" if language == "zh" else "No explicit third-level rule in the admitted tutorial." + family = block.split("\n## ")[3] + assert family.count(shared) == 1 + assert family.index(shared) < family.index("\n### ") + # Per-table captions (the return clock of each annual table) stay with their table. + clock = "时钟:" if language == "zh" else "Clock: " + assert family.count(clock) == 12 + assert sum(1 for line in block.splitlines() if line.startswith("|")) == _TABLE_ROWS[case] + + +def _timing_title() -> re.Pattern[str]: + source = (ROOT / "frontend" / "src" / "lib" / "report-toc-groups.ts").read_text(encoding="utf-8") + pattern = re.search(r"const TIMING_TITLE = /(.+)/i;", source).group(1) + return re.compile(pattern, re.IGNORECASE) + + +# The group (推运 timing / 本命数据 data) the old `##` member chapters had in the report contents. +_OLD_MEMBERS_TIMING = { + "本命 Tithi Ashtottari": ["本命 Tithi Ashtottari 顺行", "本命 Tithi Ashtottari 逆行"], + "Natal Tithi Ashtottari": ["Natal Tithi Ashtottari forward", "Natal Tithi Ashtottari reverse"], + "年度 Tithi Ashtottari(2026–2028 年,共 12 组)": ["年度 Tithi Ashtottari 角距 顺行 2026 年第 1 次,配对 1"], + "Annual Tithi Ashtottari (2026–2028, 12 sets)": ["Annual Tithi Ashtottari arc balance forward 2026 return 1 pair 1"], + "年度 Yoga Pravesha(共 3 组)": ["年度 Yoga Pravesha 后继角距 第 1 次,配对 1"], + "Annual Yoga Pravesha (3 sets)": ["Annual Yoga Pravesha successor arc return 1 pair 1"], + "年度 Nakshatra Pravesha(共 2 组)": ["年度 Nakshatra Pravesha 360 太阴月年 第 1 次"], + "Annual Nakshatra Pravesha (2 sets)": ["Annual Nakshatra Pravesha 360 tithi year return 1"], + "Sudasa": ["Sudasa 已确认起点", "Sudasa 出生周期", "Sudasa confirmed start", "Sudasa birth cycle"], + "Varnada": ["Varnada 处女座", "Varnada Virgo"], +} +# Two families change group, both by the owner-approved titles: 「年度主星(…)」 contains 年度 +# (its old members 「Julene 主星 第 1 次」… were 本命数据), and the six auxiliary systems now sit +# under 「辅助大运次小运数据」, which was already 推运 (as `##` of their own they were 本命数据). +_MOVED_TO_TIMING = { + "年度主星(Julene、PVR 象限、PVR 360 太阴月年)": ["Julene 主星 第 1 次", "PVR 象限主星 第 1 次"], + "Annual lords (Julene, PVR quadrant, PVR 360 tithi year)": ["Julene lords return 1", "PVR quadrant lords return 1"], + "辅助大运次小运数据": ["Sthira", "Kalachakra"], + "Auxiliary dasha subperiods": ["Sthira", "Kalachakra"], +} + + +def test_report_contents_keep_each_family_in_its_members_group() -> None: + timing = _timing_title() + for family, members in _OLD_MEMBERS_TIMING.items(): + old = {bool(timing.search(member)) for member in members} + assert len(old) == 1, family + assert bool(timing.search(family)) in old, family + for family, members in _MOVED_TO_TIMING.items(): + assert timing.search(family), family + assert not any(timing.search(member) for member in members), family diff --git a/tests/test_research_timing.py b/tests/test_research_timing.py index 08a7be866..3cd2989ac 100644 --- a/tests/test_research_timing.py +++ b/tests/test_research_timing.py @@ -199,12 +199,25 @@ def _sections(markdown: str) -> list[tuple[str, str]]: for part in parts[1:]: title, _, body = part.partition("\n") rows.append((title.strip(), body)) + # 原值: 只按 `## ` 切,每个研究变体就是一个 `##` 章节 + # 新值: 变体是家族 `##` 下的 `###`;也按变体名和「家族 变体」两种名字列出,正文带上家族开头那几行 + # 原因: BUG-2100 研究章节按技法分组,家族共用的说明只印一次 + pieces = re.split(r"(?m)^### ", body) + preamble = pieces[0] + for piece in pieces[1:]: + sub, _, text = piece.partition("\n") + rows.append((sub.strip(), preamble + text)) + rows.append((f"{title.strip()} {sub.strip()}", preamble + text)) return rows def _under(rows: list[tuple[str, str]], heading: str, match: str) -> list[str]: found = [] for title, body in rows: + # 原值: 标题逐字相等 + # 新值: 不分大小写(英文版变体小标题首字母大写:「Natal Tithi Ashtottari」下的「Forward」) + # 原因: BUG-2100 研究章节按技法分组 + title, heading = title.casefold(), heading.casefold() if title == heading or (match == "prefix" and title.startswith(heading + " ")): found.append(body) return found