#!/usr/bin/env python3 """Bounded publication gate; full historical restoration remains explicit.""" from pathlib import Path import argparse,json,os,subprocess,sys ROOT=Path(__file__).resolve().parents[1] p=argparse.ArgumentParser();p.add_argument('--manifest',required=True);p.add_argument('--base',required=True);p.add_argument('--report',required=True);args=p.parse_args() subprocess.run([sys.executable,str(ROOT/'deploy/release-artifact.py'),'verify','--manifest',args.manifest,'--tree','web-front/out'],cwd=ROOT,check=True) report=Path(args.report);report.unlink(missing_ok=True) env=dict(os.environ,PYTHONPATH=str(ROOT/'scripts/rebuild-v2/vendor'),PYTHONDONTWRITEBYTECODE='1',VIDEOREG_RASTER_DECODER='sharp') r=subprocess.run([sys.executable,'-S',str(ROOT/'scripts/rebuild-v2/check-built.py'),'--base',args.base,'--report',str(report)],cwd=ROOT,env=env) if not report.is_file():raise SystemExit('No fresh complete crawl report; cannot publish') x=json.loads(report.read_text());m=json.loads((ROOT/args.manifest).read_text());summary=x['summary'] if r.returncode not in (0,1) or summary['technicalStatus']!='passed' or summary['errors'] or x['errors']:raise SystemExit('Published corpus technical gate failed') if x['sourceCommit']!=m['sourceCommit'] or x['sourceManifestSha256']!=m['appSourceManifestSha256'] or x['exportManifestSha256']!=m['exportManifestSha256']:raise SystemExit('Crawl checked another artifact') print(json.dumps(dict(publishedCorpusTechnicalGate='passed',scope=m['scope'],sourceCommit=x['sourceCommit'],exportManifestSha256=x['exportManifestSha256'],roleApprovals=len(m['roleApprovals']),fullHistoricalRestorationAccepted=False,fullHistoricalRestorationStatus=summary['restorationStatus'],unresolved=summary['unresolvedInventoryItems'])))