Files

37 lines
2.4 KiB
Python

#!/usr/bin/env python3
"""Verify the actual shipped original stylesheet bytes and local dependency closure."""
from pathlib import Path
import re, hashlib, json, posixpath
ROOT=Path(__file__).resolve().parents[2]
OUT=ROOT/'theme/Fuc/assets/native'
manifest=json.loads((OUT/'manifest.json').read_text())
source=Path(manifest['source'])
checked=[]
for name in manifest['css']:
original=(source/name).read_text()
expected=re.sub(r'@import\s+url\([\'\"]?https?[^;]+;', '@import url("local-fonts.css");' if name=='assets/cool/style.css' and (OUT/'assets/cool/local-fonts.css').exists() else '',original)
expected=re.sub(r"url\(([\'\"]?)(/[^)\'\"]+)\1\)",lambda m: "url("+m[1]+posixpath.relpath(m[2].lstrip('/'),str(Path(name).parent))+m[1]+")",expected)
actual=(OUT/name).read_text()
assert actual == expected, f'Original CSS has drifted: {name}'
assert not re.search(r'(?:@import\s+[\'\"]?|url\(\s*[\'\"]?)https?://',actual), f'Unexpected remote CSS dependency: {name}'
checked.append(dict(path=name,sha256=hashlib.sha256(actual.encode()).hexdigest(),local_dependency_rewritten=expected!=original))
template_paths=sorted(OUT.glob('*.html'))
assert len(template_paths)==26
for template in template_paths:
name=template.stem
text=(OUT/f'{name}.html').read_text()
assert '<script' not in text.lower()
assert '{include' not in text
assert (OUT/'LICENSE.FUC').is_file()
report=dict(css_verified=len(checked),css=checked,templates_verified=len(template_paths),missing_legacy_font_alternatives=manifest['missing'],note='Legacy EOT/SVG/WOFF/TTF alternatives are absent in source; the supplied WOFF2/TTF candidates load in the browser. Original Google font families are vendored locally.')
path=ROOT/'codex/output/fuc-theme/native-integrity.json';path.write_text(json.dumps(report,ensure_ascii=False,indent=2)+'\n')
print(f'PASS: {len(checked)} original stylesheets byte-verified (remote font import localized); {len(template_paths)} inert templates; local LICENSE preserved')
vendor=(source/'theme/cool/assets/vendors/js/vendors.min.js').read_text()
a=vendor.index('/*! pace 1.0.2 */');b=vendor.index('}).call(this);',a)+len('}).call(this);')
assert (OUT/'pace.min.js').read_text()==vendor[a:b]+'\n'
original=(source/'theme/cool/assets/vendors/css/vendors.min.css').read_text()
rules=[rule.strip()+'}' for rule in original.split('}') if '.pace' in rule.split('{',1)[0]]
assert (OUT/'pace.css').read_text()=='\n'.join(rules)+'\n'
print('PASS: original Pace 1.0.2 script and progress CSS match FUC source')