Files
aigc-home/docs/hel-892/singleloop-document-evidence/package_delivery.py
T
2026-11-01 17:00:01 +08:00

124 lines
5.1 KiB
Python

"""Package a clean pushed narrow correction, immutable source closure and new screenshots."""
import hashlib
import json
import socket
import subprocess
import zipfile
from build_definition import OUT, REPO
from rebuild import BASE
def git(*args):
return subprocess.check_output(["git", *args], cwd=REPO).decode().strip()
def main():
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"
output = REPO / ".local-evidence/singleloop-delivery"
output.mkdir(exist_ok=True)
for row in json.loads((OUT / "file-purpose-sha256.json").read_bytes())["files"]:
assert hashlib.sha256((REPO / row["path"]).read_bytes()).hexdigest() == row["sha256"]
old = OUT.parent / "director-story-document-evidence"
closure = json.loads((OUT / "source-closure.json").read_bytes())
assert closure["implementation_sources"] > 0 and closure["count"] >= 4
files = {}
for row in closure["files"]:
p = REPO / row["path"]
assert hashlib.sha256(p.read_bytes()).hexdigest() == row["sha256"], str(p)
files[row["path"]] = p
for name in git("diff", "--name-only", "-z", BASE, head).strip("\0").split("\0"):
files[name] = REPO / name
p = REPO / "docs/hel-892/singleloop-reference/sources.json"
files[str(p.relative_to(REPO))] = p
browser = REPO / ".local-evidence/singleloop-document/browser"
for p in browser.glob("*.png"):
files["screenshots/" + p.name] = p
histories = sorted(browser.parent.glob("browser-*-failed")) + sorted(
browser.parent.glob("browser-*-superseded")
)
for failed in histories:
for p in failed.iterdir():
if p.is_file():
files["prior-runs/" + failed.name + "/" + p.name] = p
assert len(list(browser.glob("*.png"))) >= 30
(output / "complete.patch").write_bytes(
subprocess.check_output(["git", "diff", "--binary", BASE, head], cwd=REPO)
)
for port in [8247, 5173]:
with socket.socket() as probe:
probe.settimeout(1)
assert probe.connect_ex(("127.0.0.1", port)) != 0
with socket.socket() as probe:
probe.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
probe.bind(("127.0.0.1", port))
final = {
"base": BASE,
"head": head,
"remote_head": remote,
"branch": branch,
"pr": "https://gitea.xbay.cc/leefer/aigc-home/pulls/25",
"pr_base": "main",
"working_tree_clean": True,
"prior_browser_screenshots_retained": {
p.name: len(list(p.glob("*.png"))) for p in histories
},
"pins": json.loads((OUT / "pins.json").read_bytes()),
"validation": json.loads((OUT / "validation-results.json").read_bytes()),
"source_closure_files": closure["count"],
"service_ports_refused_and_bindable": [8247, 5173],
"reference_only": {"documents": 138, "saved_positions": 8480, "notes": 246},
"final_documents": 0,
"new_conversions": 0,
"real_executions": 0,
}
(output / "final-head.json").write_text(json.dumps(final, ensure_ascii=False, indent=2) + "\n")
for name in ["complete.patch", "final-head.json"]:
files[name] = output / name
index = []
for name, p in sorted(files.items()):
purpose = (
"本轮最终通过浏览截图,未入Git"
if name.startswith("screenshots/")
else "本轮被替代浏览截图/GET/服务日志,未计最终通过,未入Git"
if name.startswith("prior-runs/")
else "本图必要原件和身份缺口证据;无准确实现来源,未获取候选源码/资产"
if name in {r["path"] for r in closure["files"]} or str(old.relative_to(REPO)) in name
else "本图固定参考/派生中文或实际验证证据;逐文件用途另见file-purpose-sha256.json"
)
index.append(
{
"path": name,
"purpose": purpose,
"bytes": p.stat().st_size,
"sha256": hashlib.sha256(p.read_bytes()).hexdigest(),
}
)
name = "bundle-purpose-sha256.json"
(output / name).write_text(
json.dumps(
{"base": BASE, "self_excluded": True, "files": index}, ensure_ascii=False, indent=2
)
+ "\n"
)
files[name] = output / name
archive = output / "HEL-892-batch157-singleloop-evidence.zip"
with zipfile.ZipFile(archive, "w", zipfile.ZIP_DEFLATED) as z:
for name, p in sorted(files.items()):
z.write(p, name)
with zipfile.ZipFile(archive) as z:
assert z.testzip() is None
for row in index:
assert hashlib.sha256(z.read(row["path"])).hexdigest() == row["sha256"]
digest = hashlib.sha256(archive.read_bytes()).hexdigest()
(output / "archive-sha256.txt").write_text(digest + "\n")
print("PASS", head, "bundle files", len(files), "archive SHA256", digest)
if __name__ == "__main__":
main()