test: harden TCS root freshness and ZCode entry

This commit is contained in:
冰朔 2026-09-08 13:50:03 +08:00
commit c78e90e1e4
4 changed files with 47 additions and 1 deletions

View file

@ -165,6 +165,11 @@ def refresh(repo: Path, output: Path, pointer: Path, trigger: str) -> dict[str,
snapshot = build(repo)
current_path = output / "CURRENT.json"
previous = json.loads(current_path.read_text()) if current_path.is_file() else None
if previous:
previous_for_hash = dict(previous)
previous_token = previous_for_hash.pop("freshness_token", None)
if previous_token != digest(stable(previous_for_hash)):
raise RootError("PREVIOUS_CURRENT_FRESHNESS_TOKEN_MISMATCH")
if previous and previous.get("source_commit") == snapshot["source_commit"] and previous.get("freshness_token") == snapshot["freshness_token"]:
return {"outcome": "PASS", "state": "CURRENT_IDEMPOTENT", "source_commit": snapshot["source_commit"], "current_sha256": digest(current_path.read_bytes())}
if previous: