35 lines
4.0 KiB
Python
35 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Compare original corpus, anchors and binary payload against published R3."""
|
|
from pathlib import Path
|
|
import hashlib,json,subprocess,sys
|
|
sys.path.insert(0,str(Path('scripts/rebuild-v2/vendor').resolve()))
|
|
from bs4 import BeautifulSoup
|
|
root=Path('.');out=root/'web-front/out';checks=[]
|
|
def check(kind,path,ok):
|
|
checks.append(dict(kind=kind,path=path,same=bool(ok)))
|
|
def digest(data):return hashlib.sha256(data).hexdigest()
|
|
for name in ['web-front/src/content/v2-articles.json','web-front/src/content/v2-community.json','deploy/legacy-map.conf','deploy/legacy-routes.json','deploy/legacy-matchers.json']:
|
|
check('immutable-source/legacy',name,(root/name).read_bytes()==subprocess.check_output(['git','show','6405a8d:'+name]))
|
|
public=subprocess.check_output(['git','ls-tree','-r','--name-only','6405a8d','--','web-front/public'],text=True).splitlines()
|
|
for name in public:
|
|
relative=name.removeprefix('web-front/public/');before=subprocess.check_output(['git','show','6405a8d:'+name]);check('original-public-source-bytes',relative,digest((root/name).read_bytes())==digest(before));check('original-public-export-bytes',relative,(out/relative).is_file()and digest((out/relative).read_bytes())==digest(before))
|
|
articles=json.loads((root/'web-front/src/content/v2-articles.json').read_text())+json.loads((root/'web-front/src/content/v2-community.json').read_text())
|
|
for article in articles:
|
|
path=article['path'];soup=BeautifulSoup((out/(path.lstrip('/')+'.html')).read_bytes(),'html.parser');body=soup.select_one('article.article-body');check('real-reader',path,body is not None)
|
|
if body is None:continue
|
|
for i,s in enumerate(article['sections']):
|
|
section=body.find('section',id='section-'+str(i));key=path+'#section-'+str(i);check('anchor-and-toc',key,section is not None and soup.find('a',href='#section-'+str(i))is not None)
|
|
if section is None:continue
|
|
check('exact-heading',key,section.h2.get_text()==s['heading']);check('exact-paragraphs',key,[p.get_text()for p in section.find_all('p',recursive=False)]==s['paragraphs'])
|
|
if s.get('list'):check('exact-list',key,[n.get_text()for n in section.find('ol').find_all('li')]==s['list'])
|
|
if s.get('note'):check('exact-note',key,section.select_one('.reading-note').get_text()==s['note'])
|
|
if s.get('code'):check('exact-code',key,section.find('code').get_text()==s['code'])
|
|
if s.get('table'):
|
|
t=s['table'];table=section.find('table');check('exact-table-caption',key,table.caption.get_text()==t['caption']);check('exact-table-headers',key,[c.get_text()for c in table.thead.find_all('th')]==t['head']);check('exact-table-cells',key,[[c.get_text()for c in row.find_all(['th','td'])]for row in table.tbody.find_all('tr')]==t['rows'])
|
|
if s.get('figure'):f=s['figure'];check('exact-figure/caption',key,section.find('img',src=f['src'])is not None and section.find('figcaption').get_text()==f['caption'])
|
|
for link in s.get('links',[]):a=section.find('a',href=link['href']);check('exact-resource-link',key+' '+link['href'],a is not None and a.get_text()==link['label']+' ↗')
|
|
for frame in s.get('gallery',[])[:6]:check('original-frame/name',key+' '+frame['filename'],section.find('img',src=frame['src'])is not None and frame['filename']in section.get_text())
|
|
check('exact-related-targets',path,[a['href']for a in body.select('.related-reading a')]==article['related'])
|
|
x=dict(scope='Actual rendered historical body/anchors/related and all original public bytes; brand/UI utility additions excluded from historical count',baselineCommit='6405a8d',sourceCommit=json.loads((out/'health/ready').read_text())['metadata']['commitSha'],originalArticles=len(articles),originalPublicFiles=len(public),checks=checks,failures=[x for x in checks if not x['same']],newUtilityRoutes=['/sources','/privacy','/ui-kit'],fullHistoricalRestorationAccepted=False)
|
|
(root/'docs/design-system/evidence/preservation.json').write_text(json.dumps(x,ensure_ascii=False,indent=2)+'\n');print(json.dumps(dict(checks=len(checks),failures=x['failures'],originalArticles=len(articles),originalPublicFiles=len(public)),ensure_ascii=False));raise SystemExit(1 if x['failures']else 0)
|