File size: 2,412 Bytes
ea14529
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Run all research checks while preserving delivered dataset snapshots."""
from pathlib import Path
import argparse
import json
import shutil
import subprocess
import sys
import tempfile


def run(output_dir: Path) -> dict:
    code_root = Path(__file__).resolve().parent
    snapshot_root = code_root.parent / 'results'
    pairs = [
        ('verify_ilyoxune.py', 'verification_results.json'),
        ('verify_strengthened_aggregation.py', 'strengthened_verification_results.json'),
        ('verify_strong_parameter_bound.py', 'strong_parameter_bound_results.json'),
        ('verify_lorentzian_obstruction.py', 'lorentzian_obstruction_results.json'),
    ]
    output_dir.mkdir(parents=True, exist_ok=True)
    results = []
    with tempfile.TemporaryDirectory(prefix='ilyoxune-check-scripts-') as directory:
        work = Path(directory)
        for script, filename in pairs:
            # Each delivered verifier is self-contained. Running a temporary
            # copy supports both fixed-output and CLI-configurable verifiers.
            shutil.copyfile(code_root / script, work / script)
            subprocess.run([sys.executable, str(work / script)], cwd=work, check=True)
            destination = output_dir / filename
            destination.write_bytes((work / filename).read_bytes())
            fresh = json.loads(destination.read_text(encoding='utf-8'))
            delivered = json.loads((snapshot_root / filename).read_text(encoding='utf-8'))
            results.append({'script': script, 'status': 'passed',
                            'matches_delivered_snapshot': fresh == delivered})
    summary = {'status': 'all verification scripts passed', 'results': results}
    (output_dir / 'VERIFICATION_RUN.json').write_text(json.dumps(summary, indent=2) + '\n')
    print(json.dumps(summary, indent=2))
    return summary


def main() -> int:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--output-dir', type=Path,
                        help='Keep fresh JSON results in this directory; default uses temporary files.')
    args = parser.parse_args()
    if args.output_dir is not None:
        run(args.output_dir.resolve())
    else:
        with tempfile.TemporaryDirectory(prefix='ilyoxune-verification-') as directory:
            run(Path(directory))
    return 0


if __name__ == '__main__':
    raise SystemExit(main())