robustnesslab-ai / preflight.py
Hugdrigo's picture
Upload 33 files
f4c6961 verified
Raw History Blame Contribute Delete
2.63 kB
"""Static Hugging Face release QA; no external dependencies."""
import hashlib,json,re,pathlib,zipfile,sys
ROOT=pathlib.Path(__file__).parent
text=(ROOT/'README.md').read_text('utf8')
assert text.startswith('---\n'),'README must start with YAML frontmatter'
parts=text.split('---\n',2)
assert len(parts)==3
meta={}
for line in parts[1].splitlines():
if ':' in line and not line.startswith(' '):
key,val=line.split(':',1);meta[key.strip()]=val.strip().strip('"\'')
for k in ['title','emoji','colorFrom','colorTo','sdk','app_file','license','short_description']:
assert meta.get(k),f'Missing metadata {k}'
assert meta['sdk']=='static' and meta['app_file']=='index.html','Invalid SDK configuration'
assert meta['license']=='mit'
COLORS={'red','yellow','green','blue','indigo','purple','pink','gray'}
assert meta['colorFrom'] in COLORS and meta['colorTo'] in COLORS
assert len(meta['short_description'])<=60,f'Short description too long: {len(meta["short_description"])}'
for file in ['index.html','styles.css','app.js','robustness_engine.js','source_modelops_engine.js','train.json','iid_test.json','challenge.json','robustness_snapshots.json','benchmark_manifest.json','LICENSE','DEPLOYMENT_ES.md']:
assert (ROOT/file).is_file() and (ROOT/file).stat().st_size>0,'Missing file '+file
snap=json.loads((ROOT/'robustness_snapshots.json').read_text());manifest=json.loads((ROOT/'benchmark_manifest.json').read_text())
assert len(snap['rows'])==4416
assert manifest['evaluationRecords']==4416 and manifest['trainingCount']==842 and manifest['iidCount']==130 and manifest['challengeCount']==54
for path,hashvalue in manifest['files'].items():
sha=hashlib.sha256((ROOT/path).read_bytes()).hexdigest()
assert sha==hashvalue,f'SHA256 mismatch {path}'
assert "source_modelops_engine.js" in (ROOT/'index.html').read_text()
assert "robustness_engine.js" in (ROOT/'index.html').read_text()
if len(sys.argv)>1:
z=pathlib.Path(sys.argv[1]);assert z.is_file()
with zipfile.ZipFile(z) as f:
assert f.testzip() is None,'Corrupt ZIP'
names=f.namelist();assert len(names)==len(set(names)),'Duplicate ZIP names'
assert all('/' not in n.strip('/') for n in names),'Unexpected nested directories'
assert sorted(names)==sorted(p.name for p in ROOT.iterdir() if p.is_file()),'Mismatch ZIP and working directory'
print('ZIP integrity PASS:',z.name,len(names),'root-level files')
print('HUGGING FACE METADATA PASS: sdk=static, app_file=index.html, license=mit, description='+str(len(meta['short_description']))+' chars, accepted colors')
print('DATA INTEGRITY PASS: 842 training, 130 IID, 54 challenge, 4416 records, source SHA-256 validated')