feat(skill): merge upstream reader-report contract

This commit is contained in:
Jesse
2026-08-06 11:31:51 +08:00
parent 685ed00e2f
commit 03d3b58ff7
8 changed files with 1163 additions and 2 deletions
@@ -0,0 +1,53 @@
"""Reader-report and commercial Skill import contracts."""
from __future__ import annotations
import hashlib
import json
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_commercial_root_remains_router() -> 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"
assert hashlib.sha256(snapshot.read_bytes()).hexdigest() == manifest["skill_sha256"]
assert manifest["source_mode"] == "snapshot"
assert manifest["source_commit"] is None
assert linked_skill.resolve() == (ROOT / "SKILL.md").resolve()
assert "商业运行时路由(最高优先级)" in root_skill
assert "references/upstream/yinduzhanxing/SKILL.md" in root_skill
assert "consumer_context.answer_policy" in root_skill
assert "executive_summary -> thematic_narrative -> evidence_appendix" in root_skill
assert (ROOT / "SKILL.md").read_bytes() != snapshot.read_bytes()
@@ -3,8 +3,52 @@
from __future__ import annotations
from scripts.western_evidence_packet import build_western_evidence_packet
from scripts.unified_consultation_orchestrator import UnifiedConsultationOrchestrator
from scripts.western_evidence_packet import build_western_evidence_packet
def test_route_profile_and_reader_report_preserve_commercial_themes_and_blocked_boundary() -> None:
orchestrator = UnifiedConsultationOrchestrator()
commercial_themes = ["health", "migration", "family", "annual"]
for theme in commercial_themes:
profile = orchestrator.route_profile("研究模式原始数据", [theme])
assert profile["themes"] == [theme]
assert profile["presentation_mode"] == "research"
assert profile["appendix_expanded"] is True
report = orchestrator.build_reader_report(
orchestrator.route_profile("请看事业", ["career"]),
{"career": {"summary": "事业一定会成功。事业一定会成功。", "status": "used"}},
raw_data={"calculation_hash": "synthetic"},
technique_audit=[{"technique": "D10", "status": "blocked"}],
conflicts=[{"reason": "synthetic conflict"}],
)
assert list(report) == ["executive_summary", "thematic_narrative", "evidence_appendix"]
assert "一定" not in report["thematic_narrative"]["career"]["summary"]
assert report["thematic_narrative"]["career"]["summary"].count("事业") == 1
assert report["evidence_appendix"]["blocked_techniques"] == ["D10"]
assert report["evidence_appendix"]["technique_audit"][0]["confidence_label"] == "blocked"
def test_reader_report_exposes_parallel_system_views_without_majority_vote() -> None:
report = UnifiedConsultationOrchestrator().build_reader_report(
{"themes": ["career"], "presentation_mode": "default"},
{"career": {
"summary": "条件性结论",
"jyotish_summary": "D10 视图",
"western_summary": "Solar Return 视图",
"consensus_summary": "只记录共同方向,不作多数投票",
}},
technique_audit=[
{"technique": "D10", "status": "used"},
{"technique": "Solar Return", "status": "partial"},
{"technique": "Cross-System Arbitration", "status": "used"},
],
)
views = report["thematic_narrative"]["career"]["system_views"]
assert views == {"jyotish": "D10 视图", "western": "Solar Return 视图", "consensus": "只记录共同方向,不作多数投票"}
rows = report["evidence_appendix"]["technique_audit"]
assert [row["system"] for row in rows] == ["jyotish", "western", "cross_system"]
def test_unified_consultation_orchestrator_normalizes_themes_and_route() -> None:
@@ -63,6 +107,8 @@ def test_unified_consultation_orchestrator_exposes_surface_agnostic_contract() -
assert contract["themes"] == ["marriage"]
assert contract["source_priority"]["mode"] == "vedastro_official_snapshot_first"
assert contract["source_priority"]["priority"][0] == "vedastro_official_snapshot"
assert contract["route_profile_contract"]["route"] == "relationship"
assert "Technique Audit Table" in contract["route_profile_contract"]["execution_boundary"]
def test_unified_consultation_orchestrator_builds_runtime_planner() -> None: