125 lines
4.6 KiB
Python
125 lines
4.6 KiB
Python
"""Foreground, bounded delivery ZIP with per-member purposes, SHA, byte and CRC checks."""
|
|
|
|
import hashlib
|
|
import json
|
|
import subprocess
|
|
import zipfile
|
|
|
|
from acquire import sha
|
|
from build import HERE, ROOT
|
|
|
|
LOCAL = ROOT / ".local-evidence/batch178-aio-protocol"
|
|
DELIVERY = LOCAL / "delivery"
|
|
|
|
|
|
def read(name):
|
|
return json.loads((HERE / name).read_text())
|
|
|
|
|
|
def save(path, value):
|
|
with path.open("x", encoding="utf-8") as stream:
|
|
json.dump(value, stream, ensure_ascii=False, indent=2)
|
|
stream.write("\n")
|
|
|
|
|
|
def git(*args):
|
|
return subprocess.check_output(["git", *args], cwd=ROOT)
|
|
|
|
|
|
def main():
|
|
base = read("baseline.json")["commit"]
|
|
head = git("rev-parse", "HEAD").decode().strip()
|
|
branch = git("branch", "--show-current").decode().strip()
|
|
assert branch == "agent/agent/a64a969a6a44"
|
|
assert not git("status", "--porcelain")
|
|
remote = git("ls-remote", "origin", f"refs/heads/{branch}", "refs/heads/main").decode()
|
|
assert f"{head}\trefs/heads/{branch}" in remote
|
|
save(
|
|
DELIVERY / "final-head.json",
|
|
dict(
|
|
baseline=base,
|
|
head=head,
|
|
branch=branch,
|
|
remote_refs=remote,
|
|
worktree_clean=True,
|
|
pull_request="https://gitea.xbay.cc/leefer/aigc-home/pulls/25",
|
|
target="main",
|
|
merged=False,
|
|
),
|
|
)
|
|
patch = git("diff", "--binary", base, head, "--")
|
|
(DELIVERY / "complete.patch").write_bytes(patch)
|
|
changed = [p.decode() for p in git("diff", "--name-only", "-z", base, head).split(b"\0") if p]
|
|
assert all(p.startswith("docs/hel-892/batch178-aio-protocol/") for p in changed)
|
|
members = {
|
|
p: (ROOT / p, "new offline mapping tools/reports/retained iterations") for p in changed
|
|
}
|
|
prior_dir = "docs/hel-892/batch177-controlnet-provenance/"
|
|
evidence_paths = {
|
|
"docs/hel-892/supplied-api/01.api.json",
|
|
"docs/hel-892/supplied-api/manifest.json",
|
|
prior_dir + "class-schema-matrix.json",
|
|
prior_dir + "core-bindings.json",
|
|
prior_dir + "core-support-proofs.json",
|
|
prior_dir + "release-member-proofs.json",
|
|
prior_dir + "release-directory.json",
|
|
prior_dir + "network/registry-version.body",
|
|
prior_dir + "network/registry-version.json",
|
|
}
|
|
for item in read("reused-source-records.json"):
|
|
evidence_paths.add(prior_dir + item["original_record"]["file"])
|
|
for path in sorted(evidence_paths):
|
|
members[path] = (ROOT / path, "existing selected original/API/reference bytes; unchanged")
|
|
for folder in ("logs", "records"):
|
|
for path in sorted((LOCAL / folder).iterdir()):
|
|
if path.name.startswith("batch178-aio-protocol-package-final."):
|
|
continue
|
|
members[f"execution/{folder}/{path.name}"] = (
|
|
path,
|
|
"exclusive raw formal command record",
|
|
)
|
|
for name in ("mapping.bundle", "complete.patch", "final-head.json"):
|
|
members[f"delivery/{name}"] = (
|
|
DELIVERY / name,
|
|
"complete delta / verified Git transport / pushed head",
|
|
)
|
|
purposes = [
|
|
dict(path=name, purpose=purpose, bytes=path.stat().st_size, sha256=sha(path.read_bytes()))
|
|
for name, (path, purpose) in sorted(members.items())
|
|
]
|
|
save(
|
|
DELIVERY / "purpose-sha256.json",
|
|
dict(
|
|
self_excluded=True,
|
|
members=purposes,
|
|
package_command_record="attached separately after completion",
|
|
),
|
|
)
|
|
members["delivery/purpose-sha256.json"] = (DELIVERY / "purpose-sha256.json", "manifest")
|
|
archive = DELIVERY / "HEL-892-batch178-aio-protocol.zip"
|
|
with zipfile.ZipFile(archive, "x", compression=zipfile.ZIP_DEFLATED, compresslevel=9) as bundle:
|
|
for name, (path, _) in sorted(members.items()):
|
|
bundle.write(path, name)
|
|
with zipfile.ZipFile(archive) as bundle:
|
|
assert bundle.testzip() is None
|
|
assert len(bundle.namelist()) == len(members) == len(set(bundle.namelist()))
|
|
for name, (path, _) in members.items():
|
|
raw = bundle.read(name)
|
|
assert len(raw) == path.stat().st_size and sha(raw) == sha(path.read_bytes())
|
|
checked = len(bundle.namelist())
|
|
save(
|
|
DELIVERY / "archive-verification.json",
|
|
dict(
|
|
filename=archive.name,
|
|
bytes=archive.stat().st_size,
|
|
sha256=hashlib.sha256(archive.read_bytes()).hexdigest(),
|
|
members=checked,
|
|
bytes_sha_crc_verified=True,
|
|
),
|
|
)
|
|
print((DELIVERY / "archive-verification.json").read_text())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|