Co-authored-by: multica <multica@users.noreply.github.com> Co-authored-by: multica-agent <github@multica.ai>
95 lines
3.4 KiB
Python
95 lines
3.4 KiB
Python
"""Verify inherited transport and every tracked baseline blob before the audit."""
|
|
|
|
import hashlib
|
|
import json
|
|
import subprocess
|
|
import zipfile
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[3]
|
|
LOCAL = ROOT / ".local-evidence/batch175-closure"
|
|
BASE = "c73d76527593707121cf4b137c4d594eeecd8230"
|
|
|
|
|
|
def digest(raw):
|
|
return hashlib.sha256(raw).hexdigest()
|
|
|
|
|
|
def write(path, data):
|
|
with path.open("x", encoding="utf-8") as f:
|
|
json.dump(data, f, ensure_ascii=False, indent=2)
|
|
f.write("\n")
|
|
|
|
|
|
def main():
|
|
assert subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=ROOT).decode().strip() == BASE
|
|
assert not subprocess.check_output(["git", "diff", "--name-only"], cwd=ROOT)
|
|
old = ROOT / ".local-evidence/batch174-h3extend/delivery"
|
|
manifest = json.loads((old / "delivery-parts-sha256.json").read_bytes())
|
|
original = old / manifest["original_archive"]
|
|
assert digest(original.read_bytes()) == manifest["original_archive_sha256"]
|
|
members = {}
|
|
for part in manifest["parts"]:
|
|
p = old / part["file"]
|
|
assert p.stat().st_size == part["bytes"] and digest(p.read_bytes()) == part["sha256"]
|
|
with zipfile.ZipFile(p) as z:
|
|
assert z.testzip() is None and len(z.namelist()) == part["entries"]
|
|
for name in z.namelist():
|
|
assert name not in members
|
|
members[name] = z.read(name)
|
|
assert len(members) == 159
|
|
with zipfile.ZipFile(original) as z:
|
|
assert z.testzip() is None and set(z.namelist()) == set(members)
|
|
assert all(z.read(n) == b for n, b in members.items())
|
|
for row in manifest["entries"]:
|
|
assert digest(members[row["path"]]) == row["sha256"]
|
|
purposes = json.loads(members["bundle-purpose-sha256.json"])
|
|
for row in purposes["files"]:
|
|
raw = members[row["path"]]
|
|
assert len(raw) == row["bytes"] and digest(raw) == row["sha256"]
|
|
index = json.loads(
|
|
(
|
|
ROOT / "docs/hel-892/minimax-extend-api-document-evidence/file-purpose-sha256.json"
|
|
).read_bytes()
|
|
)
|
|
for row in index["files"]:
|
|
assert digest((ROOT / row["path"]).read_bytes()) == row["sha256"]
|
|
files = []
|
|
for entry in (
|
|
subprocess.check_output(["git", "ls-tree", "-rz", BASE], cwd=ROOT)
|
|
.rstrip(b"\0")
|
|
.split(b"\0")
|
|
):
|
|
meta, name = entry.split(b"\t", 1)
|
|
mode, kind, blob = meta.decode().split()
|
|
assert kind == "blob"
|
|
path = name.decode()
|
|
raw = (ROOT / path).read_bytes()
|
|
assert hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest() == blob, (
|
|
path
|
|
)
|
|
files.append(dict(path=path, git_blob_sha1=blob, sha256=digest(raw)))
|
|
write(LOCAL / "baseline-files.json", dict(base=BASE, files=files))
|
|
write(
|
|
LOCAL / "preflight.json",
|
|
dict(
|
|
base=BASE,
|
|
directory_existed_before=False,
|
|
inherited_174_archive_sha256=manifest["original_archive_sha256"],
|
|
verified_members=159,
|
|
inherited_parts=manifest["parts"],
|
|
tracked_baseline_files=len(files),
|
|
product_change_allowlist=[],
|
|
historical_logs_mutated=False,
|
|
),
|
|
)
|
|
print(
|
|
"PASS inherited174 twoZIPs/159members byte/SHA/CRC, purpose index and",
|
|
len(files),
|
|
"baseline blobs",
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|