"""Check artifact structure and internal links, not scientific peer review."""
from pathlib import Path
from html.parser import HTMLParser
import json,csv
root=Path(__file__).resolve().parents[1]
class Audit(HTMLParser):
 def __init__(self):super().__init__();self.links=[];self.images=[];self.h1=0
 def handle_starttag(self,tag,attrs):
  a=dict(attrs)
  if tag=='a':self.links.append(a.get('href',''))
  if tag=='img':self.images.append(a);assert a.get('alt')
  if tag=='h1':self.h1+=1
for p in (root/'release').glob('*.html'):
 a=Audit();a.feed(p.read_text());assert a.h1==1,p
 for link in a.links+[x['src'] for x in a.images]:
  if not link.startswith(('https:','http:','#')):assert (p.parent/link).exists(),(p,link)
 for text in ['turn0search','TODO','TBD']:assert text not in p.read_text()
for name in ['maturation-longevity','lifespan-endpoints']:
 p=json.loads((root/'papers'/f'{name}.json').read_text());assert p['status'].startswith('Unreviewed')
 sections={x['text'] for x in p['blocks'] if x['type']=='h2'}
 assert {'Abstract','Methods','Results','Discussion and limitations','References'}<=sections
 assert len([x for x in p['blocks'] if x['type']=='figure'])==2
print('PASS: HTML headings, image alt text, local links, manuscript structure.')
