import hashlib,json
from pathlib import Path
from pypdf import PdfReader
root=Path(__file__).resolve().parent
required=['paper.md','paper-content.json','paper-metadata.json','paper.pdf','README.md','CITATION.cff','LICENSE','RIGHTS-NOTICE.txt','source-registry.json','data-dictionary.csv','cleaning-rules.md','analysis.py','outputs/analysis-results.json','claim-provenance.json']
missing=[p for p in required if not (root/p).is_file()]; assert not missing,missing
doi='10.5281/zenodo.21904782'; doi_url='https://doi.org/'+doi
meta=json.loads((root/'paper-metadata.json').read_text(encoding='utf-8')); assert meta['reportNumber']=='SHWRP-2026-039' and meta['slug']=='taiwan-price-index-wedge-2026' and meta['version']=='1.0'; assert meta['doi']==doi and meta['doiUrl']==doi_url and meta['zenodoDepositId']==21904782; assert '第三方' in meta['licenseScope'] and '原創' in meta['licenseScope']
sources=json.loads((root/'source-registry.json').read_text(encoding='utf-8'))['sources']; assert len(sources)>=3 and sum(bool(s['firstPartyOrOfficial']) for s in sources)>=2
reader=PdfReader(root/'paper.pdf'); texts=[p.extract_text() or '' for p in reader.pages]; assert len(reader.pages)>=6 and all(len(t.strip())>80 for t in texts); assert sum(map(len,texts))>5000; assert all(doi in t for t in texts)
for name in ['README.md','CITATION.cff','paper.md','paper-content.json','paper-metadata.json']:
    legacy_notice='DOI'+'將於通過機器驗證後建立'
    value=(root/name).read_text(encoding='utf-8'); assert doi in value and legacy_notice not in value,name
digest=hashlib.sha256((root/'paper.pdf').read_bytes()).hexdigest(); print(json.dumps({'status':'PASSED','reportNumber':'SHWRP-2026-039','slug':'taiwan-price-index-wedge-2026','version':'1.0','reservedDoi':doi,'pages':len(reader.pages),'textCharacters':sum(map(len,texts)),'pdfSha256':digest},ensure_ascii=False))
