Files
digital-drosophila/models/male-cns-lif/conditioning-pipeline-acceleration-v1/prepost.py
T
2026-10-01 14:56:32 +08:00

52 lines
2.4 KiB
Python

"""Verify previous independent engineering artifacts and original saved science."""
import argparse
import hashlib
import json
from pathlib import Path
import subprocess
import sys
import time
BASE = Path('/home/qishizhe/phase4ar-pipeline-acceleration-20261001')
OLD = Path('/home/qishizhe/phase4ar-v100-acceleration-20261001')
OLD_SOURCE = Path(__file__).resolve().parent.parent / 'conditioning-acceleration-v1'
OLD_MANIFEST_SHA = '6efdec34c96cdc79f786b91bd7a99b0e8ef64d0c4dcfa525646c82659a77d44f'
FIXTURE_SHA = '481df128d39bf28e5984a6f2e5757f83d45cb7a6136f8d2843ecc0a67eca437b'
def sha(path):
h = hashlib.sha256()
with Path(path).open('rb') as f:
for b in iter(lambda:f.read(8 << 20), b''): h.update(b)
return h.hexdigest()
p = argparse.ArgumentParser()
p.add_argument('--stage', choices=('before','after'), required=True)
a = p.parse_args()
BASE.mkdir(exist_ok=True)
assert not BASE.is_symlink()
report_path = BASE / ('integrity-' + a.stage + '.json')
assert not report_path.exists()
start = time.perf_counter()
assert sha(OLD / 'artifact-manifest.json') == OLD_MANIFEST_SHA
assert sha(OLD / 'fixtures/manifest.json') == FIXTURE_SHA
manifest = json.loads((OLD / 'artifact-manifest.json').read_text())
bad = []
for rel, item in manifest['files'].items():
path = OLD / rel
assert path.resolve().is_relative_to(OLD) and not path.is_symlink()
if not path.is_file() or path.stat().st_size != item['bytes'] or sha(path) != item['sha256']: bad.append(rel)
for name, expected in manifest['source_files'].items():
if sha(OLD_SOURCE / name) != expected: bad.append('source:' + name)
assert not bad, bad
science = BASE / ('original-integrity-' + a.stage + '.json')
result = subprocess.run([sys.executable, '-B', str(OLD_SOURCE / 'audit_integrity.py'), '--output', str(science)],
capture_output=True, text=True, timeout=120)
assert result.returncode == 0, result.stdout + result.stderr
records = json.loads(science.read_text())
report = dict(status='PASS', previous_engineering_files_checked=len(manifest['files']),
previous_engineering_sources_checked=len(manifest['source_files']), original=records,
previous_manifest_sha256=OLD_MANIFEST_SHA, fixture_manifest_sha256=FIXTURE_SHA,
old_artifacts_modified=False, original_AR_resumed=False, wall_seconds=time.perf_counter()-start)
with report_path.open('x') as f: json.dump(report, f, indent=2)
print(json.dumps(report), flush=True)