3"""Publish digest-rebound image-supervisor sources for runtime proofs."""
5from __future__
import annotations
9from pathlib
import Path
11CASES_PIN_PATTERN = re.compile(
r'CASES_RAW_SHA256 = "[0-9a-f]{64}"')
12PROCESS_PIN_PATTERN = re.compile(
r'PROCESS_RAW_SHA256 = "[0-9a-f]{64}"')
16class RuntimeSourceError(ValueError):
17 """Report ambiguous runtime source binding or publication."""
20def _rebind_pin(source: str, payload: str, pattern: re.Pattern[str], name: str) -> str:
21 """Replace one exact embedded source digest or refuse ambiguous bytes."""
22 replacement = f
'{name}_RAW_SHA256 = "{hashlib.sha256(payload.encode()).hexdigest()}"'
23 rebound, count = pattern.subn(replacement, source, count=1)
24 if count != 1
or len(pattern.findall(source)) != 1:
25 message = f
"supervisor {name.lower()} digest assignment is not unique"
26 raise RuntimeSourceError(message)
35) -> tuple[Path, Path, Path]:
36 """Write one exact main/process/cases source bundle under a private root."""
37 rebound = _rebind_pin(supervisor, process_source, PROCESS_PIN_PATTERN,
"PROCESS")
38 rebound = _rebind_pin(rebound, cases_source, CASES_PIN_PATTERN,
"CASES")
39 main_path = root /
"supervisor.py"
40 process_path = root /
"supervisor_process.py"
41 cases_path = root /
"supervisor_cases.py"
42 main_path.write_text(rebound, encoding=
"utf-8")
43 process_path.write_text(process_source, encoding=
"utf-8")
44 cases_path.write_text(cases_source, encoding=
"utf-8")
45 for path
in (main_path, process_path, cases_path):
46 path.chmod(SOURCE_MODE)
47 return main_path, process_path, cases_path