from pathlib import Path
from html.parser import HTMLParser
from urllib.parse import urlsplit,urljoin,unquote,quote
import json,hashlib,subprocess,re,urllib.request,urllib.error,concurrent.futures,struct
r=Path('/Users/gavrilovdev/tmp/progcode.ru');w=r/'web';frozen=Path('/tmp/progcode-ds-frozen-f5d927948163');old=Path('/tmp/progcode-metrika-frozen-527ea7bf774e');out=r/'docs/design-system/candidates/f5d927948163/reviews';expected='f5d92794816398171b68a1d374b24bd0cd9ea0f85d005c7be92369b40d314900';base='http://127.0.0.1:50480'
# Independently enumerate current working sources following the inspected publication helper boundary.
names=sorted([str(p.relative_to(w)) for dirname in ['app','lib','fsd','scripts','data','public'] for p in (w/dirname).rglob('*') if p.is_file() and str(p.relative_to(w))!='public/build-identity.json']+['package.json','package-lock.json','next.config.mjs']);h=hashlib.sha256()
for name in names:h.update(name.encode());h.update((w/name).read_bytes())
assert len(names)==230 and h.hexdigest()==expected,(len(names),h.hexdigest());source=h.hexdigest();build=hashlib.sha256();outputFiles=sorted(p for p in frozen.rglob('*') if p.is_file())
for p in outputFiles:build.update(str(p.relative_to(frozen)).encode());build.update(p.read_bytes())
assert len(outputFiles)==722 and build.hexdigest()=='ea4fb0dc8934776e4e9d4213f07c27424962789bfadd1ba9ca51ad31d5736851'
assert json.loads((frozen/'build-identity.json').read_text())['sourceHash']==source
# Inspect actual import graph, not the implementer's reported graph.
ranks={'pages':0,'widgets':1,'features':2,'entities':3,'shared':4};edges=[];violations=[]
def resolve(p):
return next((q.resolve() for q in [p,*[Path(str(p)+suffix) for suffix in ['.js','.jsx','.mjs','.json','.css']],p/'index.js',p/'index.jsx'] if q.is_file()),None)
fsd=(w/'fsd').resolve()
for p in (w/'fsd').rglob('*'):
if p.suffix not in ['.js','.jsx','.mjs']:continue
src=p.relative_to(fsd).parts
for name in re.findall(r"(?:from\s*|import\s*)['\"]([^'\"]+)['\"]",p.read_text()):
if not name.startswith('.'):continue
target=resolve(p.parent/name);assert target,(p,name)
edges.append({'source':str(p.relative_to(w)),'import':name,'target':str(target.relative_to(w))})
if target.is_relative_to(fsd):
dst=target.relative_to(fsd).parts
if ranks[dst[0]]]*class="[^"]*\barticle-content\b[^"]*"[^>]*>',text);assert m
depth=1;start=m.end()
for tag in re.finditer(r'?div\b[^>]*>',text[start:]):
depth+=-1 if tag.group().startswith('') else 1
if not depth:return text[start:start+tag.start()]
raise AssertionError('unclosed article content')
oldpages={p.relative_to(old) for p in old.rglob('*.html')};newpages={p.relative_to(frozen) for p in frozen.rglob('*.html')};assert len(oldpages)==81 and oldpages<=newpages
bodyPaths=[];times=0
for path in oldpages:
a=(old/path).read_text();b=(frozen/path).read_text();pa=Page(a);pb=Page(b);assert pa.times==pb.times,str(path);times+=len(pa.times)
if 'class="article-shell"' in a:assert inner(a)==inner(b),str(path);bodyPaths.append(str(path))
assert len(bodyPaths)==28 and times==146
media=sorted(p.relative_to(old) for p in (old/'visuals').rglob('*') if p.is_file())
for path in media:assert (old/path).read_bytes()==(frozen/path).read_bytes()
assert len(media)==11
icons={}
for size in [16,32,48,180]:
b=(frozen/f'brand/favicon-{size}.png').read_bytes();assert b.startswith(b'\x89PNG\r\n\x1a\n');actual=struct.unpack('>II',b[16:24]);assert actual==(size,size);icons[str(size)]=actual
ico=(frozen/'brand/favicon.ico').read_bytes();reserved,kind,count=struct.unpack('