from pathlib import Path import json,shutil,zipfile,re,html,hashlib B=Path(__file__).resolve().parents[1];OUT=B.parents[1]/'outputs/01a1e261-9424-7620-9eb8-641798779213';OUT.mkdir(parents=True,exist_ok=True) text=(B/'article-working.md').read_text() text=text.replace('(evidence/','(evidence/').replace('../../outputs/01a1e261-9424-7620-9eb8-641798779213/candidate-inputs.zip','candidate-inputs.zip') (OUT/'qwen4-practical-guide.md').write_text(text) shutil.copytree(B/'evidence',OUT/'evidence',dirs_exist_ok=True) for name in ['TRANSPARENCY.md','METHOD-CORRECTIONS.md','FINAL-STATUS.json']: shutil.copy(B/name,OUT/name) with zipfile.ZipFile(OUT/'qwen4-evidence.zip','w',zipfile.ZIP_DEFLATED)as z: for p in sorted((B/'evidence').rglob('*')): if p.is_file():z.write(p,Path('evidence')/p.relative_to(B/'evidence')) with zipfile.ZipFile(OUT/'qwen4-guide-and-evidence.zip','w',zipfile.ZIP_DEFLATED)as z: for name in ['qwen4-practical-guide.md','qwen4-practical-guide.html','grading.xlsx','candidate-inputs.zip','TRANSPARENCY.md','METHOD-CORRECTIONS.md','FINAL-STATUS.json']: z.write(OUT/name,name) for p in sorted((B/'evidence').rglob('*')): if p.is_file():z.write(p,Path('evidence')/p.relative_to(B/'evidence')) # HTML guide is generated separately before packaging. for p in [OUT/'qwen4-practical-guide.html']: if p.exists(): for href in re.findall(r'href="([^"]+)"',p.read_text()): if not href.startswith(('http','#')) and not(p.parent/href).exists():raise RuntimeError('Broken guide link: '+href) # Check the ZIP itself contains every local document target. with zipfile.ZipFile(OUT/'qwen4-guide-and-evidence.zip')as z: names=set(z.namelist()) for href in re.findall(r'href="([^"]+)"',(OUT/'qwen4-practical-guide.html').read_text()): if not href.startswith(('http','#'))and href not in names:raise RuntimeError('Bundle missing guide target '+href) # Link existence checks, not remote publication claims. bad=[] for p in (B/'evidence').rglob('*.html'): for href in re.findall(r'href="([^"]+)"',p.read_text()): if not href.startswith(('http','#')) and not(p.parent/href).exists():bad.append([str(p),href]) if bad:raise RuntimeError('Broken evidence links: '+str(bad[:20])) manifest={p.name:hashlib.sha256(p.read_bytes()).hexdigest()for p in OUT.iterdir()if p.is_file()and p.suffix in ['.zip','.xlsx','.md','.json','.html'] and p.name!='sha256.json'} (OUT/'sha256.json').write_text(json.dumps(manifest,indent=2)) print(json.dumps({'output':str(OUT),'broken_evidence_links':bad,'guide_words':len(text.split()),'bundle_bytes':(OUT/'qwen4-guide-and-evidence.zip').stat().st_size},indent=2))