"""Coverage contract against the upstream customer export (2026-11-06). Product: 「把上游的覆盖审计改写成我们的自动测试」. Every upstream topic maps to a section of our full data report in both editions; each must be present and carry real content. Topics we do not carry are on record in NOT_CARRIED. """ from __future__ import annotations import pytest from scripts.pl9_full_data_export import render_full_data_markdown from scripts.professional_report_reference import _english_edition from scripts.report_render.upstream_coverage import NOT_CARRIED, TOPICS, audit_report from tests.report_english_fictional import _load_packet @pytest.fixture(scope="module") def fictional_editions() -> dict[int, tuple[str, str]]: editions = {} for index in (0, 9): packet = _load_packet(index) english = _english_edition(packet, True).get("markdown_en") or "" chinese = render_full_data_markdown(packet) assert english and chinese editions[index] = (chinese, english) return editions def test_every_upstream_topic_is_carried_with_real_content(fictional_editions) -> None: for index, (chinese, english) in fictional_editions.items(): assert audit_report(chinese, "zh") == [], f"chart {index} zh" assert audit_report(english, "en") == [], f"chart {index} en" def test_the_contract_is_complete_and_has_no_overlap() -> None: assert len(TOPICS) >= 140 upstream = [topic.upstream for topic in TOPICS] assert len(upstream) == len(set(upstream)) assert not set(NOT_CARRIED) & set(upstream) assert all(reason.strip() for reason in NOT_CARRIED.values()) _GOOD = "\n".join([ "## 重点", "", "当前大运与三个领域的宫主,这段时间可能突出的主题,不是确定会发生的事。", "", "### 注明日期的行运", "", "| 行星 | 星座 | 落座度数 |", "|---|---|---|", "| 太阳 | 天秤座 | 19.96 |", "| 月亮 | 处女座 | 1.40 |", "", "### 瑜伽参与行星", "", "| 瑜伽 | 参与行星 |", "|---|---|", "| 水金合相格局 | 水星、金星 |", "", "### 当前多系统收敛", "", "| 领域 | 宫位 | 收敛等级 |", "|---|---|---|", "| 自身与健康 | 1 | L0 |", "", ]) def _findings(markdown: str) -> dict[str, set[str]]: by_check: dict[str, set[str]] = {} for item in audit_report(markdown, "zh"): by_check.setdefault(item["check"], set()).add(item["topic"]) return by_check def test_the_audit_flags_missing_empty_columns_and_degraded_markers() -> None: good = _findings(_GOOD) assert "Dated Transit Positions" not in good.get("empty_column", set()) assert "Current Dasha Convergence by Domain" not in good.get("empty_section", set()) bad = (_GOOD .replace("| 月亮 | 处女座 | 1.40 |", "| 月亮 | 未判定 | 未判定 |") .replace("| 水金合相格局 | 水星、金星 |", "| 水金合相格局 | 未判定 |") .replace("| 自身与健康 | 1 | L0 |", "| 未判定 | 未判定 | 未判定 |") + "\n### Kala Chakra 大运(简化模型)\n\n公开报告资料包未带此模块\n") flagged = _findings(bad) assert "Dated Transit Positions" in flagged["empty_column"] assert "Yoga Participants and Timing Links" in flagged["empty_section"] | flagged.get("empty_column", set()) assert "Current Dasha Convergence by Domain" in flagged["empty_section"] assert {"公开报告资料包未带此模块", "(简化模型)"} <= flagged["degraded_marker"] assert "AI Reading Guide" in flagged["missing_section"]