#!/usr/bin/env python3 """Format-5 exchange across frozen V5/V7 writers and the current V8 engine.""" import hashlib import importlib.util import json from pathlib import Path import sys import tempfile HERE = Path(__file__).resolve().parent ROOT = HERE.parent sys.dont_write_bytecode = True def load(name, path): spec = importlib.util.spec_from_file_location(name, path) module = importlib.util.module_from_spec(spec) sys.modules[name] = module spec.loader.exec_module(module) return module def main(): paths = {'v5': HERE / 'baselines/v5.py', 'v7': HERE / 'baselines/v7.py', 'v8': ROOT / 'pagefs.py'} hashes = {name: hashlib.sha256(path.read_bytes()).hexdigest() for name, path in paths.items()} modules = {name: load('compat_' + name, path) for name, path in paths.items()} checks = [] for origin in ('v5', 'v7'): expected = {f'/entry/{i:04d}': bytes([i % 251]) * 128 for i in range(128)} receipts = {} with tempfile.TemporaryDirectory(prefix='nyarion-v8-compatible-') as tmp: image = Path(tmp) / 'compatible.img' with modules[origin].PageStore.create(image, initial_files=expected, pool_blocks=2048) as store: for i in range(100): key, data, token = f'/entry/{i:04d}', bytes([i]) * 1024, f'old-{i}' receipts[token] = store.transact({key: data}, token) expected[key] = data store.checkpoint() with modules['v8'].PageStore(image) as store: for key, data in expected.items(): assert store.get(key) == data for i in range(100): key, data, token = f'/entry/{i:04d}', bytes([i + 1]) * 128, f'new-{i}' receipts[token] = store.transact({key: data}, token) expected[key] = data store.checkpoint() for reader in ('v5', 'v7', 'v8'): with modules[reader].PageStore(image, writable=False) as store: assert store.epoch == 200 assert store.files() == sorted(expected) for key, data in expected.items(): assert store.get(key) == data for token, epoch in receipts.items(): assert store.query(token)['epoch'] == epoch checks.append({'initial_writer': origin, 'subsequent_writer': 'v8', 'reader': reader, 'transactions': 200, 'exact_receipt_epochs_and_contents_verified': True}) assert {name: hashlib.sha256(path.read_bytes()).hexdigest() for name, path in paths.items()} == hashes result = {'passed': True, 'persistent_format': 5, 'source_sha256': hashes, 'volumes': 2, 'transactions_per_volume': 200, 'reader_checks': checks, 'scope': 'format compatibility; older writers do not inherit V8 admission guarantees'} (HERE / 'compatibility_results.json').write_text(json.dumps(result, indent=2) + '\n') print(json.dumps(result, indent=2)) if __name__ == '__main__': main()