"""Reader-report and commercial Skill import contracts.""" from __future__ import annotations import hashlib import json import re from pathlib import Path from scripts.report_orchestrator import render_reader_report ROOT = Path(__file__).resolve().parents[1] def test_render_reader_report_defaults_to_collapsed_appendix_and_keeps_order() -> None: rendered = render_reader_report({ "thematic_narrative": {"career": {"text": "Provided narrative"}}, "evidence_appendix": {"raw_data": {"Sun": 12.3}}, "executive_summary": {"headline": "Provided summary"}, }) assert list(rendered) == ["presentation_mode", "executive_summary", "thematic_narrative", "evidence_appendix"] assert rendered["presentation_mode"] == "default" assert rendered["evidence_appendix"]["expanded"] is False def test_render_reader_report_expands_only_research_and_preserves_extensions() -> None: rendered = render_reader_report({ "presentation_mode": "research", "executive_summary": {"title": "Research"}, "thematic_narrative": {}, "evidence_appendix": {"raw_data": {"Moon": 3.4}}, "commercial_extension": {"health": True}, }) assert list(rendered) == [ "presentation_mode", "executive_summary", "thematic_narrative", "evidence_appendix", "commercial_extension", ] assert rendered["evidence_appendix"]["expanded"] is True assert rendered["commercial_extension"] == {"health": True} def test_upstream_skill_snapshot_matches_manifest_and_root_is_her_skill() -> None: snapshot = ROOT / "references/upstream/yinduzhanxing/SKILL.md" manifest = json.loads((snapshot.parent / "source-manifest.json").read_text(encoding="utf-8")) root_skill = (ROOT / "SKILL.md").read_text(encoding="utf-8") linked_skill = ROOT / "skills/jyotish-vedic-astrology/SKILL.md" snapshot_hash = hashlib.sha256(snapshot.read_bytes()).hexdigest() assert snapshot_hash == manifest.get("source_skill_sha256", manifest["skill_sha256"]) assert manifest["source_mode"] == "git" assert re.fullmatch(r"[0-9a-f]{40}", manifest["source_commit"]) assert re.fullmatch(r"[0-9a-f]{64}", manifest["source_tree_sha256"]) assert linked_skill.resolve() == (ROOT / "SKILL.md").resolve() # 原值: 根 SKILL.md 是商业路由(含「商业运行时路由(最高优先级)」、指向上游快照、answer_policy、报告顺序),且必须与上游快照不同 # 新值: 根 SKILL.md 就是上游快照原文;产品安全规则在 references/product_runtime_contract.md # 原因: BUG-1696 产品 2026-11-07:产品完整运行占星师 skill,不再用商业改写版替代她的方法 from tests.test_upstream_skill_parity import _split_skill assert _split_skill(root_skill) == _split_skill(snapshot.read_text(encoding="utf-8")) assert "## 关联技法完整调取" in root_skill contract = (ROOT / "references/product_runtime_contract.md").read_text(encoding="utf-8") assert "answer_policy" in contract and "interpretation_status_contract.md" in contract