mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-12-05 10:34:23 +01:00
Prepare only locked dependencies in owned release environments before installing the exact project. Preserve verified wheel-supplied caches outside import paths, require zero caches before compilation, and bind generated cache bytes to source and retained diagnostics. Keep project caches forbidden, preserve the no-write startup policy, sanitize inherited compilation settings, and retain bootstrap evidence separately without changing test selection or release gates. Refs #306
71 lines
3.2 KiB
Python
71 lines
3.2 KiB
Python
"""Bind coverage origins to the exact tested source, lock, and toolchain."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import importlib.metadata
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
from scripts.release_bytecode_policy import bytecode_identity, reject_project_bytecode
|
|
|
|
|
|
IDENTITY_FIELDS = ("checkout_tree_digest", "project_digest", "lock_digest", "coverage_version", "python_full_version", "source_files", "bytecode_policy")
|
|
|
|
|
|
def digest(path: Path) -> str:
|
|
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
|
|
|
|
def source_files(root: Path) -> dict[str, str]:
|
|
return {path.relative_to(root).as_posix(): digest(path)
|
|
for path in sorted((root / "obliteratus").rglob("*.py"))}
|
|
|
|
|
|
def source_identity(root: Path) -> dict:
|
|
reject_project_bytecode(root / "obliteratus")
|
|
sources = source_files(root)
|
|
if not sources:
|
|
raise ValueError("target has no project source inventory")
|
|
installed = Path(importlib.metadata.distribution("obliteratus").locate_file("obliteratus")).resolve()
|
|
reject_project_bytecode(installed)
|
|
for name, expected in sources.items():
|
|
path = installed / Path(name).relative_to("obliteratus")
|
|
if not path.is_file() or digest(path) != expected:
|
|
raise ValueError(f"installed package differs from target source: {name}")
|
|
return {
|
|
"project_digest": digest(root / "pyproject.toml"), "lock_digest": digest(root / "uv.lock"),
|
|
"coverage_version": importlib.metadata.version("coverage"), "python_full_version": sys.version.split()[0],
|
|
"source_files": sources, "source_roots": [str(root / "obliteratus"), str(installed)],
|
|
}
|
|
|
|
|
|
def check_report_source(root: Path, identity: dict) -> None:
|
|
reject_project_bytecode(root / "obliteratus")
|
|
if (source_files(root) != identity["source_files"]
|
|
or digest(root / "pyproject.toml") != identity["project_digest"]
|
|
or digest(root / "uv.lock") != identity["lock_digest"]
|
|
or importlib.metadata.version("coverage") != identity["coverage_version"]
|
|
or sys.version.split()[0] != identity["python_full_version"]):
|
|
raise ValueError("report source, lock/config, coverage tool, or Python identity differs from measured target")
|
|
if bytecode_identity()["bytecode_policy"] != identity["bytecode_policy"]:
|
|
raise ValueError("report bytecode startup policy differs from measured target")
|
|
|
|
|
|
def check_origins(data, identity: dict, *, unexecuted: bool = False) -> None:
|
|
expected_context = "release:" + identity["target_sha"]
|
|
contexts = data.measured_contexts()
|
|
if contexts != {expected_context} and not (unexecuted and contexts <= {"", expected_context}):
|
|
raise ValueError("coverage context does not identify the exact target revision")
|
|
for name in data.measured_files():
|
|
path = Path(name)
|
|
if ".." in path.parts:
|
|
raise ValueError("noncanonical coverage origin")
|
|
relative = name if not path.is_absolute() else None
|
|
for origin in identity["source_roots"]:
|
|
if path.is_relative_to(origin):
|
|
relative = "obliteratus/" + path.relative_to(origin).as_posix()
|
|
break
|
|
if relative not in identity["source_files"]:
|
|
raise ValueError(f"coverage has unknown or cross-target source origin: {name}")
|