Files
Jyotisha/tests/test_upstream_import_plan.py
T
ClaudeandClaude Opus 5.5 919c61814a docs(upstream): mirror record for astrologer branch d09feab7 (sync 12)
Import record from scripts/import_yinduzhanxing.py --apply on a clean d09feab7
clone (root SKILL.md unchanged since ea2a9d65); source-manifest and import plan
point at d09feab7; the ea2a9d65 record test becomes history.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
2026-11-07 20:05:45 +08:00

179 lines
8.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""PR-0 selective upstream import-plan and provenance contracts."""
from __future__ import annotations
import hashlib
import json
import re
from pathlib import Path
from jsonschema import Draft202012Validator, FormatChecker
ROOT = Path(__file__).resolve().parents[1]
UPSTREAM = ROOT / "references/upstream/yinduzhanxing"
PLAN = UPSTREAM / "import-plan.json"
SOURCE_MANIFEST = UPSTREAM / "source-manifest.json"
IMPORT_SCHEMA = ROOT / "references/cross_project_contract/import_manifest.schema.json"
LEGACY_SNAPSHOT = ROOT / "references/cross_project_contract/imports/snapshot-9034e1967032d09c.json"
PINNED_IMPORT_RECORD = ROOT / "references/cross_project_contract/imports/commit-5db72537741fcedaa7b5498502d4a31b0f9fc147.json"
EXPECTED_SOURCES = {
"scripts/evidence_maturity.py",
"scripts/assertion_policy.py",
"scripts/evidence_labeled_reporting.py",
"scripts/calculation_profile_contract.py",
"scripts/report_pack_contract.py",
"scripts/domain_profile_builder.py",
"scripts/unified_calculation_archive.py",
"scripts/specialized_evidence_packets.py",
"scripts/timing_evidence_packets.py",
}
EXPECTED_CATEGORIES = {
"calculation_contracts",
"evidence_assertion_contracts",
"report_domain_profile_contracts",
"research_oracle_assets",
}
EXPECTED_REJECTIONS = {
"fixed_event_domain_count_threshold",
"sparse_start_mid_end_rectification_scan",
"weaken_three_engine_gate",
"weaken_required_layers",
"weaken_stability_gate",
"remove_commercial_routes",
}
# 原值: ea2a9d65(树 392de36d…、git 树 74dc6abe…、提交时间 2026-11-07T06:15:35Z;更早为 5fb8379c)
# 新值: d09feab7(占星师工作分支 codex/public-sync-20261107 的 HEAD;根 SKILL.md 与 ea2a9d65 逐字节相同)
# 原因: 产品 2026-11-07 同步占星师工作分支 d09feab7;旧记录留作历史,见 test_upstream_git_import_ea2a9d65.py
EXPECTED_UPSTREAM_IDENTITY = {
"source_repository": "732642856/yinduzhanxing",
"source_repository_url": "https://github.com/732642856/yinduzhanxing",
"source_commit": "d09feab738fd7676865686b6dbb459a940d7793e",
"source_tree_sha256": "08e597d423dacfa50b3ce2fd04e0fb36c5d0a3359848ea4a0fc1887be3d5159a",
}
EXPECTED_SOURCE_GIT_TREE = "6af71564f0c70a1008a7bd92b5c8810bb081a5a9"
EXPECTED_SOURCE_SKILL_SHA256 = "12deb0d59eb820a482c6b709c34658178529c82823ae2a54d0ca8bc12f8b7a5c"
EXPECTED_SOURCE_COMMITTED_AT = "2026-11-07T10:27:07Z"
LEGACY_ARCHIVE_COMMIT = "5db72537741fcedaa7b5498502d4a31b0f9fc147"
CURRENT_IMPORT_RECORD = ROOT / "references/cross_project_contract/imports/commit-d09feab738fd7676865686b6dbb459a940d7793e.json"
def _load(path: Path) -> dict:
return json.loads(path.read_text(encoding="utf-8"))
def test_import_plan_records_all_nine_upstream_sources_and_semantic_destinations() -> None:
plan = _load(PLAN)
entries = plan["entries"]
assert len(entries) == 9
assert {entry["source"] for entry in entries} == EXPECTED_SOURCES
assert {entry["category"] for entry in entries} == EXPECTED_CATEGORIES
assert [entry["action"] for entry in entries].count("adapt") == 8
assert [entry["action"] for entry in entries].count("reference_only") == 1
for entry in entries:
assert set(("source", "category", "action", "reason", "targets", "tests")) <= set(entry)
assert entry["source"].startswith("scripts/")
assert entry["reason"]
assert entry["targets"] and all(target.startswith(("scripts/", "references/")) for target in entry["targets"])
assert entry["tests"] and all(test.startswith("tests/") for test in entry["tests"])
archive = next(entry for entry in entries if entry["source"] == "scripts/unified_calculation_archive.py")
assert archive["action"] == "reference_only"
assert "runtime truth" in archive["reason"]
assert "none of these research scripts is copied" in plan["boundary"]
def test_rejected_regressions_protect_server_truth_gates_and_commercial_routes() -> None:
plan = _load(PLAN)
rejections = plan["rejected_regressions"]
assert {item["id"] for item in rejections} == EXPECTED_REJECTIONS
assert all(item["action"] == "reject" for item in rejections)
by_id = {item["id"]: item for item in rejections}
fixed_count = by_id["fixed_event_domain_count_threshold"]["reason"].lower()
assert "3 events" in fixed_count and "2 domains" in fixed_count
assert "not sufficient" in fixed_count and "cannot bypass" in fixed_count
sparse_scan = by_id["sparse_start_mid_end_rectification_scan"]["reason"].lower()
assert all(token in sparse_scan for token in ("start", "midpoint", "end"))
assert "not a complete" in sparse_scan
for rejection_id in (
"weaken_three_engine_gate",
"weaken_required_layers",
"weaken_stability_gate",
):
assert by_id[rejection_id]["action"] == "reject"
assert by_id[rejection_id]["commercial_owner"].startswith("scripts/")
routes = by_id["remove_commercial_routes"]
assert routes["preserved_routes"] == ["migration", "family", "annual"]
assert "commercial-runtime-owned" in routes["reason"]
def test_formal_varga_is_evidence_only_and_cannot_close_local_truth() -> None:
policy = _load(PLAN)["formal_varga_policy"]
assert policy["action"] == "reference_only"
reason = policy["reason"].lower()
for token in ("evidence_only", "cannot claim", "cannot", "api key"):
assert token in reason
assert "local-formula parity" in reason
assert "required layers" in reason
def test_source_manifest_pins_valid_git_commit_tree_and_root_skill_hash() -> None:
manifest = _load(SOURCE_MANIFEST)
plan = _load(PLAN)
assert manifest["source_mode"] == "git"
assert manifest["import_policy_version"] == 2
assert manifest["imported_at"] != manifest["source_committed_at"]
assert {key: manifest[key] for key in EXPECTED_UPSTREAM_IDENTITY} == EXPECTED_UPSTREAM_IDENTITY
assert {key: plan[key] for key in EXPECTED_UPSTREAM_IDENTITY} == EXPECTED_UPSTREAM_IDENTITY
assert manifest["source_git_tree"] == EXPECTED_SOURCE_GIT_TREE
assert "archive_sha256" not in manifest
assert "archive_file_count" not in manifest
assert manifest["source_committed_at"] == EXPECTED_SOURCE_COMMITTED_AT
assert re.fullmatch(r"[0-9a-f]{40}", manifest["source_commit"])
assert re.fullmatch(r"[0-9a-f]{64}", manifest["source_tree_sha256"])
source_skill_sha256 = manifest.get("source_skill_sha256", manifest["skill_sha256"])
assert re.fullmatch(r"[0-9a-f]{64}", source_skill_sha256)
snapshot_hash = hashlib.sha256((UPSTREAM / "SKILL.md").read_bytes()).hexdigest()
assert source_skill_sha256 == snapshot_hash == EXPECTED_SOURCE_SKILL_SHA256
assert manifest["skill_sha256"] == manifest["source_skill_sha256"]
def test_import_manifest_schema_accepts_archive_and_legacy_snapshot_records() -> None:
schema = _load(IMPORT_SCHEMA)
validator = Draft202012Validator(schema, format_checker=FormatChecker())
legacy = _load(LEGACY_SNAPSHOT)
pinned = _load(PINNED_IMPORT_RECORD)
current = _load(CURRENT_IMPORT_RECORD)
validator.validate(legacy)
validator.validate(pinned)
validator.validate(current)
invalid_git = dict(pinned, source_mode="git", source_commit="unknown")
assert list(validator.iter_errors(invalid_git))
assert "archive" in schema["properties"]["source_mode"]["enum"]
source_manifest = _load(SOURCE_MANIFEST)
plan = _load(PLAN)
assert pinned["source_commit"] == LEGACY_ARCHIVE_COMMIT
assert current["source_repository"] == source_manifest["source_repository"] == plan["source_repository"]
assert current["source_repository_url"] == source_manifest["source_repository_url"] == plan["source_repository_url"] == EXPECTED_UPSTREAM_IDENTITY["source_repository_url"]
assert current["source_commit"] == source_manifest["source_commit"] == plan["source_commit"]
assert current["source_tree_hash"] == source_manifest["source_tree_sha256"] == plan["source_tree_sha256"]
assert current["source_skill_sha256"] == source_manifest["source_skill_sha256"] == EXPECTED_SOURCE_SKILL_SHA256
def test_raman_2026_08_20_packets_are_adapt_only_and_exclude_blocked_batches() -> None:
plan = _load(PLAN)
support = plan["raman_2026_08_20_support"]
assert support["action"] == "adapt"
packet_dir = ROOT / support["target"]
names = {path.name for path in packet_dir.glob("*.json")}
assert set(support["packets"]) <= names
assert "scripts/raman_support_observations.py" in support["targets"]
for prefix in support["rejected_packets"]:
assert not any(name.startswith(prefix) for name in names)
assert "health" in " ".join(support["rejected_packets"])
assert "unique-minute" in support["reason"] or "support-only" in support["reason"]