File size: 3,819 Bytes
84a242a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0feae48
 
84a242a
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
"""Verify the complete local HF payload; never upload, train, dock, or unpickle."""
from __future__ import annotations
import argparse
import csv
import hashlib
import json
from pathlib import Path
import sys

EXCLUDED = {'provenance/repository_files.json', 'provenance/final_verification.json', 'SHA256SUMS'}
IGNORED_PARTS = {'.git', '.cache', '__pycache__', '.venv', 'outputs', 'scratch'}

def files(root):
    return {p.relative_to(root).as_posix(): p for p in root.rglob('*')
            if p.is_file() and not any(x in IGNORED_PARTS for x in p.relative_to(root).parts)
            and p.name != '.DS_Store' and not p.name.endswith(('.pyc', '.pyo'))}

def digest(path):
    with path.open('rb') as f:
        return hashlib.file_digest(f, 'sha256').hexdigest()

def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--root', type=Path, default=Path(__file__).resolve().parents[1])
    parser.add_argument('--strict-release', action='store_true', help='Also require recorded upload readiness.')
    parser.add_argument('--include-large-data', action='store_true', help='Compatibility flag; graphs are always checked.')
    args = parser.parse_args()
    root = args.root.resolve()
    manifest = json.loads((root / 'provenance/repository_files.json').read_text())
    actual = files(root)
    expected = {x['path']: x for x in manifest['files']}
    errors = []
    if set(actual) - EXCLUDED != set(expected):
        errors.append({'error': 'missing or unmanifested upload files',
                       'missing': sorted(set(expected) - set(actual)),
                       'extra': sorted(set(actual) - EXCLUDED - set(expected))})
    for name, rec in expected.items():
        path = root / name
        if not path.resolve().is_relative_to(root) or path.is_symlink():
            errors.append({'path': name, 'error': 'unsafe path or symlink'})
        elif not path.is_file():
            errors.append({'path': name, 'error': 'missing'})
        elif getattr(path.stat(), 'st_flags', 0) & 0x40000000:
            errors.append({'path': name, 'error': 'cloud placeholder'})
        elif path.stat().st_size != rec['bytes'] or digest(path) != rec['sha256']:
            errors.append({'path': name, 'error': 'content mismatch'})
    sums = {}
    for line in (root / 'SHA256SUMS').read_text().splitlines():
        sha, name = line.split('  ', 1)
        sums[name] = sha
    wanted_sums = {name: rec['sha256'] for name, rec in expected.items()}
    wanted_sums['provenance/repository_files.json'] = digest(root / 'provenance/repository_files.json')
    if sums != wanted_sums:
        errors.append({'error': 'SHA256SUMS differs from the manifest'})
    source = json.loads((root / 'provenance/source_copy_verification.json').read_text())
    status = json.loads((root / 'provenance/release_status.json').read_text())
    report = {'scope': 'Complete local HF upload payload, including all graph bytes; no scientific experiments',
              'checked_files': len(expected), 'checked_bytes': sum(x['bytes'] for x in expected.values()),
              'protein_graph_files': len([n for n in expected if n.startswith('data/external/protein_graphs_esmc_600m/')]),
              'integrity_passed': not errors, 'errors': errors,
              'source_bytes_verified': source['passed'],
              'upload_payload_complete': status['upload_payload_complete'],
              'publication_ready': status['publication_ready'],
              'public_upload_performed': status.get('public_upload_performed', False),
              'new_scientific_experiments': False}
    print(json.dumps(report, indent=2))
    return 1 if errors else 2 if args.strict_release and not status['publication_ready'] else 0

if __name__ == '__main__':
    sys.exit(main())