"""Copy existing missing transport bytes; no old command rerun or log synthesis.""" import hashlib import json import zipfile from pathlib import Path HERE = Path(__file__).resolve().parent ROOT = HERE.parents[2] OLD = ROOT / ".local-evidence/batch179-target-snapshots" def sha(raw): return hashlib.sha256(raw).hexdigest() def write(name, value): with (HERE / name).open("x", encoding="utf-8") as stream: json.dump(value, stream, ensure_ascii=False, indent=2) stream.write("\n") def copy(name, source): with (HERE / name).open("xb") as stream: stream.write(source.read_bytes()) def main(): record_path = OLD / "records/package.json" record = json.loads(record_path.read_text()) assert record["key"] == "package" and len(record["logs"]) == 2 copy("original-logs/package.json", record_path) copy("original-logs/original-execution-register.json", OLD / "delivery/execution-register.json") old_archive = OLD / "delivery/HEL-892-batch179-target-snapshots.zip" with zipfile.ZipFile(old_archive) as bundle: assert bundle.read("execution/records/package.json") == record_path.read_bytes() additions = [] for log in record["logs"]: source = ROOT / log["path"] assert source.is_file(), "original log absent; do not regenerate" raw = source.read_bytes() assert len(raw) == log["bytes"] and sha(raw) == log["sha256"] name = source.name assert "execution/logs/" + name not in bundle.namelist() copy("original-logs/" + name, source) additions.append( dict( original_record_log=log, original_path=log["path"], original_mtime_ns=source.stat().st_mtime_ns, preserved_file="original-logs/" + name, supplement_member="execution/logs/" + name, bytes_found=True, copied_existing_bytes=True, command_rerun=False, synthesized=False, mtime_recreated=False, ) ) register = json.loads((OLD / "delivery/execution-register.json").read_text()) coverage = [] for command in register["records"]: for log in command["logs"]: source = ROOT / log["path"] raw = source.read_bytes() assert len(raw) == log["bytes"] and sha(raw) == log["sha256"] member = "execution/logs/" + source.name if member in bundle.namelist(): assert bundle.read(member) == raw location = "original179_zip:" + member elif command["key"] == "package": location = "correction_supplement:" + member else: assert command["key"] == "finalize" location = "original179_separate_attachment:" + source.name coverage.append( dict(key=command["key"], original_log=log, delivery_location=location) ) assert register["formal_commands"] == 20 and register["streams"] == 40 assert len(coverage) == 40 and len(additions) == 2 write( "log-supplement-index.json", dict( original_commands=20, original_streams=40, previously_delivered_streams=38, supplied_now=2, original_streams_now_accounted=40, old_archive_sha256=sha(old_archive.read_bytes()), additions=additions, coverage=coverage, counts_are_not_new_test_results=True, original_failures_retained=True, ), ) print( "two existing original package streams verified/copied; original 20/40 accounted, not rerun" ) if __name__ == "__main__": main()