Files
progcode/docs/design-system/implementation-v3/verify-preservation.py
T
huncode 12562baeb5
Build and deploy / deploy (push) Successful in 2m39s
Implement ProgCode identity and real shared reading UI kit
2026-10-27 15:19:49 +03:00

39 lines
3.4 KiB
Python

from pathlib import Path
from html.parser import HTMLParser
from collections import Counter
import re,json,subprocess,hashlib,argparse
p=argparse.ArgumentParser();p.add_argument('--source',required=True);a=p.parse_args();r=Path(__file__).resolve().parents[3];c=r/'docs/design-system/implementation-v3/candidates'/a.source[:12];m=json.loads((c/'manifest.json').read_text());new=Path(m['staticRoot']);old=Path('/private/tmp/progcode-ds-frozen-7b11bf22fd24')
class Times(HTMLParser):
def __init__(self,html):super().__init__();self.current=None;self.values=[];self.feed(html)
def handle_starttag(self,tag,attrs):
if tag=='time':self.current=[dict(attrs).get('datetime'),'']
def handle_data(self,value):
if self.current is not None:self.current[1]+=value
def handle_endtag(self,tag):
if tag=='time' and self.current is not None:self.values.append(tuple(self.current));self.current=None
def inner(html):
match=re.search(r'<div\b[^>]*class="[^"]*\barticle-content\b[^"]*"[^>]*>',html);assert match;start=match.end();depth=1
for tag in re.finditer(r'</?div\b[^>]*>',html[start:]):
depth+=-1 if tag.group().startswith('</') else 1
if not depth:return html[start:start+tag.start()]
raise AssertionError('bodydiv')
oldpaths={p.relative_to(old) for p in old.rglob('*.html')};newpaths={p.relative_to(new) for p in new.rglob('*.html')};assert oldpaths==newpaths
body=[];oldtimes=0;added=[]
for path in sorted(oldpaths):
a=(old/path).read_text();b=(new/path).read_text();ot=Counter(Times(a).values);nt=Counter(Times(b).values);assert not ot-nt,(str(path),'historicaldatepairlost',ot-nt);oldtimes+=sum(ot.values())
extra=nt-ot
if extra:added.append({'path':str(path),'additionalDatePairs':[{'ISO':v[0],'text':v[1],'count':n} for v,n in extra.items()]})
if 'class="article-shell"' in a:assert inner(a)==inner(b),str(path);body.append(str(path))
media=[]
for p in (old/'visuals').rglob('*'):
if p.is_file():q=p.relative_to(old);assert p.read_bytes()==(new/q).read_bytes();media.append(str(q))
inputs=[]
for name in ['articles-v2.json','articles.json','publication-report.json','archive-routes.json','shortlinks.json','figure-placements.json']:
b=(r/'web/data'/name).read_bytes();assert b==subprocess.run(['git','show','0458a99:web/data/'+name],cwd=r,capture_output=True,check=True).stdout;inputs.append({'path':'data/'+name,'sha256':hashlib.sha256(b).hexdigest()})
assets=[];baseline=json.loads((r/'docs/design-system/candidates/7b11bf22fd24/source-inputs.json').read_text())
for f in baseline['files']:
if f['path'].startswith('public/brand/') or f['path']=='public/icon.svg':assert hashlib.sha256((r/'web'/f['path']).read_bytes()).hexdigest()==f['sha256'],f['path'];assets.append(f['path'])
report={'sourceHash':m['sourceHash'],'buildHash':m['buildHash'],'baseline':'F6 source7b11 exactrecoveredexport; bodies and6inputs originallypublished0458','HTMLRoutesIdentical':len(oldpaths),'canonicalLegacyBodiesByteEqual':len(body),'bodyPaths':body,'historicalDateTextISOPairsPreserved':oldtimes,'newAdditionalDateMetadata':added,'wholeHTMLByteParityClaimed':False,'historicalMediaByteEqual':len(media),'media':media,'publishedDataInputsByteEqual':inputs,'originalBrandAssetsByteEqual':assets,'newV3BrandIsAdditive':True,'fullHistoricalRestorationAccepted':False}
(c/'preservation.json').write_text(json.dumps(report,ensure_ascii=False,indent=2)+'\n');print(json.dumps({k:v for k,v in report.items() if k not in ['bodyPaths','media','publishedDataInputsByteEqual','originalBrandAssetsByteEqual']},ensure_ascii=False,indent=2))