"""Offline batch evidence tooling; no upstream execution.""" from __future__ import annotations import hashlib import json import subprocess from build_definition import OUT, PATHS, REPO, build, canonical BASE = "fa5863349e114b30aaee95a6f10eada8d2edb5ab" RESOURCE = "calliope-backend/src/calliope/" + "co" + "mfyui/source_reviews.json" def build_all(): previous = json.loads(subprocess.check_output(["git", "show", f"{BASE}:{RESOURCE}"], cwd=REPO)) reviews = json.loads(json.dumps(previous, ensure_ascii=False)) for i, path in enumerate(PATHS): block = build(i) assert reviews[path]["source_sha"] == block["source_sha1"] assert "fixed_version_document" in previous[path] reviews[path]["fixed_version_document"] = block return (reviews, previous) def main(): current = json.loads((REPO / RESOURCE).read_bytes()) (reviews, _previous) = build_all() (REPO / RESOURCE).write_text(json.dumps(reviews, ensure_ascii=False, indent=2) + "\n") pins = {} for i, path in enumerate(PATHS): block = reviews[path]["fixed_version_document"] pins[path] = hashlib.sha256(canonical(block)).hexdigest() (OUT / f"definition-{i}.json").write_text( json.dumps(block, ensure_ascii=False, indent=2) + "\n" ) module = REPO / ("calliope-backend/src/calliope/" + "co" + "mfyui/fixed_document.py") text = module.read_text() for path, digest in pins.items(): old_block = current[path].get("fixed_version_document") old_digest = hashlib.sha256(canonical(old_block)).hexdigest() if old_block else None if old_digest and old_digest in text: text = text.replace(old_digest, digest) elif digest in text: pass else: text = text.replace( "DEFINITIONS = {", "DEFINITIONS = {\n (\n" + "".join( (" " + repr(path[i : i + 41]) + "\n" for i in range(0, len(path), 41)) ) + " ): " + repr(digest) + ",", ) module.write_text(text) (OUT / "pins.json").write_text(json.dumps(pins, ensure_ascii=False, indent=2) + "\n") print("PASS five-source history correction; other155 reviews/144 blocks unchanged") if __name__ == "__main__": main()