Co-authored-by: multica <multica@users.noreply.github.com> Co-authored-by: multica-agent <github@multica.ai>
160 lines
5.5 KiB
Python
160 lines
5.5 KiB
Python
"""Package only this docs/tools change plus this run's evidence; never old closure."""
|
|
|
|
import hashlib
|
|
import json
|
|
import subprocess
|
|
import urllib.request
|
|
import zipfile
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[3]
|
|
HERE = Path(__file__).resolve().parent
|
|
LOCAL = ROOT / ".local-evidence/batch175-closure"
|
|
BASE = "c73d76527593707121cf4b137c4d594eeecd8230"
|
|
|
|
|
|
def git(*args):
|
|
return subprocess.check_output(["git", *args], cwd=ROOT).decode().strip()
|
|
|
|
|
|
def sha(raw):
|
|
return hashlib.sha256(raw).hexdigest()
|
|
|
|
|
|
def write(path, data):
|
|
with path.open("x") as f:
|
|
json.dump(data, f, ensure_ascii=False, indent=2)
|
|
f.write("\n")
|
|
|
|
|
|
def main():
|
|
out = LOCAL / "delivery"
|
|
out.mkdir()
|
|
assert not git("status", "--porcelain")
|
|
head, branch = git("rev-parse", "HEAD"), git("branch", "--show-current")
|
|
remote = git("ls-remote", "origin", "refs/heads/" + branch).split()[0]
|
|
assert head == remote and branch == "agent/agent/a64a969a6a44"
|
|
with urllib.request.urlopen(
|
|
"https://gitea.xbay.cc/api/v1/repos/leefer/aigc-home/pulls/25", timeout=45
|
|
) as response:
|
|
pr = json.load(response)
|
|
assert pr["head"]["sha"] == head and pr["base"]["ref"] == "main"
|
|
assert pr["state"] == "open"
|
|
changed = git("diff", "--name-only", "-z", BASE, head).strip("\0").split("\0")
|
|
assert all(n.startswith(HERE.relative_to(ROOT).as_posix() + "/") for n in changed)
|
|
assert not git("diff", "--diff-filter=MDTR", "--name-only", BASE, head)
|
|
assert not any(n.endswith((".png", ".pyc")) for n in changed)
|
|
index = json.loads((HERE / "file-purpose-sha256.json").read_bytes())
|
|
assert set(changed) == {r["path"] for r in index["files"]} | {
|
|
(HERE / "file-purpose-sha256.json").relative_to(ROOT).as_posix()
|
|
}
|
|
for row in index["files"]:
|
|
assert sha((ROOT / row["path"]).read_bytes()) == row["sha256"]
|
|
(out / "complete.patch").write_bytes(
|
|
subprocess.check_output(["git", "diff", "--binary", BASE, head], cwd=ROOT)
|
|
)
|
|
subprocess.run(
|
|
["git", "bundle", "create", str(out / "batch175.bundle"), branch, "^" + BASE],
|
|
cwd=ROOT,
|
|
check=True,
|
|
)
|
|
result = subprocess.run(
|
|
["git", "bundle", "verify", str(out / "batch175.bundle")],
|
|
cwd=ROOT,
|
|
capture_output=True,
|
|
check=True,
|
|
)
|
|
(out / "bundle-verify.stdout.txt").write_bytes(result.stdout)
|
|
(out / "bundle-verify.stderr.txt").write_bytes(result.stderr)
|
|
write(
|
|
out / "final-head.json",
|
|
dict(
|
|
base=BASE,
|
|
head=head,
|
|
remote_head=remote,
|
|
branch=branch,
|
|
pr="https://gitea.xbay.cc/leefer/aigc-home/pulls/25",
|
|
pr_head=pr["head"]["sha"],
|
|
pr_base="main",
|
|
pr_state=pr["state"],
|
|
clean=True,
|
|
product_changes=0,
|
|
independent_review="pending HEL-893; self checks are not acceptance",
|
|
),
|
|
)
|
|
files = {n: ROOT / n for n in changed}
|
|
for name in [
|
|
"complete.patch",
|
|
"batch175.bundle",
|
|
"bundle-verify.stdout.txt",
|
|
"bundle-verify.stderr.txt",
|
|
"final-head.json",
|
|
]:
|
|
files[name] = out / name
|
|
# Run-local artifacts are owned exclusively by this batch. Explicit directories only.
|
|
for dirname in [
|
|
"records",
|
|
"threads",
|
|
"audit-second",
|
|
"audit-third",
|
|
"audit-fourth",
|
|
"render-initial",
|
|
]:
|
|
for path in sorted((LOCAL / dirname).iterdir()):
|
|
assert path.is_file()
|
|
files["run-evidence/" + dirname + "/" + path.name] = path
|
|
for name in [
|
|
"instruction.json",
|
|
"history-reads.json",
|
|
"baseline-files.json",
|
|
"preflight.json",
|
|
"startup-limitations.md",
|
|
"wrap_literals.py",
|
|
"failed-csv.csv",
|
|
"file-purpose-incomplete.json",
|
|
]:
|
|
files["run-evidence/" + name] = LOCAL / name
|
|
for key in ["commit", "push"]:
|
|
r = json.loads((LOCAL / "records" / (key + ".json")).read_bytes())
|
|
for log in r["logs"]:
|
|
files["delivery-logs/" + Path(log["path"]).name] = ROOT / log["path"]
|
|
purposes = [
|
|
dict(
|
|
path=n,
|
|
bytes=p.stat().st_size,
|
|
sha256=sha(p.read_bytes()),
|
|
purpose="本轮docs/tools或正式命令/原CLI线程/失败中间产物;旧闭包仅继承SHA,不重包",
|
|
)
|
|
for n, p in sorted(files.items())
|
|
]
|
|
write(
|
|
out / "bundle-purpose-sha256.json",
|
|
dict(base=BASE, head=head, self_excluded=True, files=purposes),
|
|
)
|
|
files["bundle-purpose-sha256.json"] = out / "bundle-purpose-sha256.json"
|
|
archive = out / "HEL-892-batch175-closure-audit-evidence.zip"
|
|
with zipfile.ZipFile(archive, "x", zipfile.ZIP_DEFLATED) as z:
|
|
for n, p in sorted(files.items()):
|
|
z.write(p, n)
|
|
with zipfile.ZipFile(archive) as z:
|
|
assert z.testzip() is None and set(z.namelist()) == set(files)
|
|
for n, p in files.items():
|
|
assert z.read(n) == p.read_bytes()
|
|
assert sha(z.read(n)) == sha(p.read_bytes())
|
|
write(
|
|
out / "archive-verification.json",
|
|
dict(
|
|
archive=archive.name,
|
|
bytes=archive.stat().st_size,
|
|
sha256=sha(archive.read_bytes()),
|
|
members=len(files),
|
|
all_bytes_sha_crc_equal=True,
|
|
independent_zip=True,
|
|
),
|
|
)
|
|
print("PASS pushed head", head, ";", len(files), "members; ZIP bytes", archive.stat().st_size)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|