portable_workload.py (2415B)
1 #!/usr/bin/env python3 2 """Shared Nix-free Python/IO workload; caller supplies /tests and /work.""" 3 import hashlib, json, os, subprocess, sys 4 from pathlib import Path 5 release = Path(sys.argv[1]).resolve() 6 assert not Path('/nix/store').exists() 7 assert not Path('/proc/self/root/nix/store').exists() 8 assert not os.environ.get('TRICU_LIB') 9 from tricu import Library, find_library 10 assert find_library() == release/'lib/libtricu-haskell.so' 11 library = Library() 12 from python_filecheck import reuse 13 report = reuse('/work') 14 # Installed application CLI: record, verify and same-length mutation. 15 cli = [sys.executable, '-c', 'from tricu_filecheck.cli import main; raise SystemExit(main())'] 16 for arguments in [('record', '/work/checks.json', 'reused.bin'), ('verify', '/work/checks.json')]: 17 result = subprocess.run(cli+list(arguments), check=True, text=True, capture_output=True, timeout=30) 18 assert json.loads(result.stdout)['ok'] is True 19 entry = json.loads(Path('/work/checks.json').read_text())['files'][0] 20 assert entry['sha256'] == hashlib.sha256(Path('/work/reused.bin').read_bytes()).hexdigest() 21 changed = Path('/work/reused.bin') 22 original = changed.read_bytes() 23 changed.write_bytes(b'x'*len(original)) 24 result = subprocess.run(cli+['verify', '/work/checks.json'], text=True, capture_output=True, timeout=30) 25 assert result.returncode == 1 and json.loads(result.stdout)['files'][0]['status'] == 'changed' 26 changed.write_bytes(original) 27 report['cli_record_verify_mutation'] = True 28 # Full installed ABI/IO controls execute in fresh foreign processes. 29 for script, extra in [('test_embedding.py', ['--copy-bundle', '/tests/copy.arboricx']), 30 ('test_scopes.py', [])]: 31 subprocess.run([sys.executable, '/tests/'+script, 32 str(release/'lib/libtricu-haskell.so'), '/tests/fixtures', *extra], 33 check=True, timeout=90) 34 # No hidden Nix mappings or library-resolution fallback. 35 from tricu_filecheck import FileChecker 36 with FileChecker() as checker: 37 assert checker.hash_file('/work/reused.bin').sha256 == hashlib.sha256(Path('/work/reused.bin').read_bytes()).hexdigest() 38 maps = Path('/proc/self/maps').read_text() 39 assert '/nix/store/' not in maps 40 assert str(release/'lib/libtricu-haskell.so') in maps 41 assert str(release/'lib/libgmp.so') in maps 42 report['nix_store_absent'] = True 43 Path('/work/report.json').write_text(json.dumps(report, indent=2)+'\n')