from pathlib import Path import json,re,hashlib,zipfile from pypdf import PdfReader import pdfplumber R=Path(__file__).resolve().parent.parent;O=R/'share';checks={} for p in (O/'reports').rglob('*.pdf'): a=PdfReader(p);texts=[x.extract_text() or '' for x in a.pages] assert len(a.pages)==15 and min(map(len,texts))>100 assert not any('\ufffd' in t for t in texts) if p.parent.name=='en':assert not re.search('[\u4e00-\u9fff]',''.join(texts)) with pdfplumber.open(p) as pdf: for page in pdf.pages: assert all(c['x0']>=20 and c['x1']<=page.width-20 and c['top']>=12 and c['bottom']<=page.height-12 for c in page.chars) checks[p.name]={'pages':len(a.pages),'sha256':hashlib.sha256(p.read_bytes()).hexdigest()} ips=set() for p in (R/'private-raw').glob('*_http.json'): for a in json.loads(p.read_text(encoding='utf-8-sig')): ips.update(x.split('=',1)[1] for x in a['before']['body'].splitlines() if x.startswith('ip=')) for d in ['data','evidence']: for p in (O/d).rglob('*'): if p.suffix not in ['.txt','.csv','.json','.jsonl']:continue t=p.read_text(encoding='utf-8-sig');assert not re.search('[\u4e00-\u9fff]',t),p assert not any(ip in t for ip in ips),p assert not re.search(r'us_losangeles|us_beta|singapore_to_us',t,re.I),p for p in (R/'private-raw').glob('*.json*'): assert not re.search(r'us_losangeles|us_beta|singapore_to_us',p.read_text(encoding='utf-8-sig'),re.I),p for line in (O/'SHA256SUMS.txt').read_text().splitlines(): h,n=line.split(' ',1);assert hashlib.sha256((O/n).read_bytes()).hexdigest()==h,n facts=json.loads((O/'data/facts.json').read_text());assert all(x['webrtc_http_exit_match'] for x in facts['dns']) assert len(list((O/'evidence').glob('*.png')))==20 assert len(facts['performance'])==8 and all(x['runs']==3 for x in facts['performance']) assert [x['exact_overlap_with_baseline'] for x in facts['dns']]==[10,3,9,8,10] assert all(x['fallback_successful_http_samples']>0 for x in facts['faults']) out={'pdfs':checks,'structured_data_and_integrity':'PASS','English_evidence_PNGs':20,'performance_rounds':24,'scope_specific_removed_region_check':'PASS','text_privacy_scan':'PASS','visual_QA':'All 15 pages per language rendered; contact sheets and full-size representative pages visually checked separately.'} (R/'qa/validation.json').write_text(json.dumps(out,indent=2),encoding='utf-8');print(json.dumps(out,indent=2))