51 lines
4.4 KiB
Plaintext
51 lines
4.4 KiB
Plaintext
"""Package clean pushed batch164 and validate byte-exact source/screenshot closure."""
|
|
import hashlib,json,socket,subprocess,zipfile,urllib.request
|
|
from pathlib import Path
|
|
R=Path.cwd();D=R/'docs/hel-892/animate2-loop-document-evidence';O=R/'.local-evidence/a2loop-delivery';B=R/'.local-evidence/animate2-loop-document/browser';BASE='a3d8901b0c71d07fcac41bc05ee1f719759940ab'
|
|
def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest()
|
|
def git(*args):return subprocess.check_output(['git',*args],cwd=R).decode().strip()
|
|
assert not git('status','--porcelain')
|
|
head=git('rev-parse','HEAD');branch=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' and pr['state']=='open'
|
|
O.mkdir(exist_ok=True)
|
|
(O/'pr-verification.json').write_text(json.dumps(pr,ensure_ascii=False,indent=2)+'\n')
|
|
index=json.loads((D/'file-purpose-sha256.json').read_bytes())
|
|
for row in index['files']:assert sha(R/row['path'])==row['sha256'],row['path']
|
|
closure=json.loads((D/'source-closure.json').read_bytes())
|
|
files={}
|
|
for row in closure['files']:
|
|
p=R/row['path'];assert sha(p)==row['sha256'],str(p);files[row['path']]=p
|
|
changed=git('diff','--name-only','-z',BASE,head).strip('\0').split('\0')
|
|
assert set(changed)=={r['path']for r in index['files']}|{str((D/'file-purpose-sha256.json').relative_to(R))}
|
|
for n in changed:files[n]=R/n
|
|
for p in B.glob('*.png'):files['screenshots/'+p.name]=p
|
|
assert len(list(B.glob('*.png')))==68
|
|
histories=list(B.parent.glob('browser-*-superseded'))
|
|
for d in histories:
|
|
for p in d.iterdir():
|
|
if p.is_file():files['prior-runs/'+d.name+'/'+p.name]=p
|
|
for port in [8247,5173]:
|
|
with socket.socket()as s:s.settimeout(1);assert s.connect_ex(('127.0.0.1',port))!=0
|
|
with socket.socket()as s:s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1);s.bind(('127.0.0.1',port))
|
|
(O/'complete.patch').write_bytes(subprocess.check_output(['git','diff','--binary',BASE,head],cwd=R))
|
|
subprocess.run(['git','bundle','create',str(O/'batch164.bundle'),branch,'^'+BASE],cwd=R,check=True)
|
|
r=subprocess.run(['git','bundle','verify',str(O/'batch164.bundle')],cwd=R,capture_output=True,check=True);(O/'bundle-verify.txt').write_bytes(r.stdout+r.stderr)
|
|
final=dict(base=BASE,head=head,remote_head=remote,push_completed=True,branch=branch,pr='https://gitea.xbay.cc/leefer/aigc-home/pulls/25',pr_head=pr['head']['sha'],pr_base='main',pr_state=pr['state'],pr_draft=pr.get('draft'),working_tree_clean=True,pins=json.loads((D/'pins.json').read_bytes()),validation=json.loads((D/'validation-results.json').read_bytes()),reference_only=dict(documents=145,saved_positions=10215,notes=287,remaining=10),final_documents=0,new_conversions=0,real_executions=0,source_closure_files=closure['count'],service_ports_refused_and_bindable=[8247,5173],prior_browser_screenshots_retained={d.name:len(list(d.glob('*.png')))for d in histories})
|
|
(O/'final-head.json').write_text(json.dumps(final,ensure_ascii=False,indent=2)+'\n')
|
|
for n in ['complete.patch','batch164.bundle','bundle-verify.txt','final-head.json','pr-verification.json']:files[n]=O/n
|
|
for n in ['package-a2loop.py','split-a2loop.py']:files['delivery-tools/'+n]=R/'.local-evidence'/n
|
|
for n in ['a2loop-commit.txt','a2loop-push.txt','a2loop-push-stderr.txt']:files['delivery-records/'+n]=R/'.local-evidence'/n
|
|
rows=[]
|
|
for n,p in sorted(files.items()):rows.append(dict(path=n,bytes=p.stat().st_size,sha256=sha(p),purpose='最终浏览截图'if n.startswith('screenshots/')else'被替代首轮原证据,不计最终通过'if n.startswith('prior-runs/')else'本图代码/来源/复现/验证或最终提交证据;详细用途见file-purpose-sha256.json'))
|
|
(O/'bundle-purpose-sha256.json').write_text(json.dumps(dict(base=BASE,self_excluded=True,files=rows),ensure_ascii=False,indent=2)+'\n');files['bundle-purpose-sha256.json']=O/'bundle-purpose-sha256.json'
|
|
p=O/'HEL-892-batch164-a2loop-evidence.zip'
|
|
with zipfile.ZipFile(p,'w',zipfile.ZIP_DEFLATED)as z:
|
|
for n,s in sorted(files.items()):z.write(s,n)
|
|
with zipfile.ZipFile(p)as z:
|
|
assert z.testzip()is None
|
|
for row in rows:assert hashlib.sha256(z.read(row['path'])).hexdigest()==row['sha256']
|
|
(O/'archive-sha256.txt').write_text(sha(p)+'\n')
|
|
print('PASS',head,len(files),'archive bytes',p.stat().st_size,'SHA',sha(p))
|