"""Validate the Info9 selector change in its real frozen pre-NLF batch, without rewriting logs.""" from __future__ import annotations import hashlib import io import json import os import subprocess import sys import tarfile import tempfile from build_definition import OUT, REPO from rebuild import BASE def main(): frozen = REPO / "docs/hel-892/openpose-document-evidence" snapshot = { p.name: hashlib.sha256(p.read_bytes()).hexdigest() for p in frozen.iterdir() if p.is_file() } gitdir = subprocess.check_output( ["git", "rev-parse", "--absolute-git-dir"], cwd=REPO, text=True ).strip() with tempfile.TemporaryDirectory() as directory: archive = subprocess.check_output(["git", "archive", BASE], cwd=REPO) from pathlib import Path root = Path(directory) with tarfile.open(fileobj=io.BytesIO(archive)) as t: t.extractall(root, filter="data") script = root / "docs/hel-892/openpose-document-evidence/recompute.py" script.write_bytes((frozen / "recompute.py").read_bytes()) env = { **os.environ, "PYTHONPATH": str(root / "calliope-backend/src"), "GIT_DIR": gitdir, "GIT_WORK_TREE": str(root), } results = [] for command in [ ["uv", "build", "--project", str(root / "calliope-backend"), "--offline"], [sys.executable, str(script)], ]: run = subprocess.run(command, cwd=root, env=env, capture_output=True, text=True) results.append( dict( command=command[0:2], code=run.returncode, stdout=run.stdout, stderr=run.stderr ) ) if run.returncode: (OUT / "old-context.json").write_text( json.dumps(results, ensure_ascii=False, indent=2) + "\n" ) raise RuntimeError("旧批次复算失败;详见old-context.json,不修改历史日志") assert snapshot == { p.name: hashlib.sha256(p.read_bytes()).hexdigest() for p in frozen.iterdir() if p.is_file() } (OUT / "old-context.json").write_text( json.dumps( dict( base=BASE, python=sys.version, isolated_archive=True, old_logs_unchanged=True, assertions_unchanged=True, info_selector="node id=9", results=results, ), ensure_ascii=False, indent=2, ) + "\n" ) print( "PASS patched Info9 selector in actual 7e76510 pre-NLF code/context; " "historical logs unchanged" ) if __name__ == "__main__": main()