"""Corrected, nonempty allocator gate supplement; preserves earlier zero-filter receipt.""" from pathlib import Path from datetime import datetime, timezone import hashlib import json import os import re import subprocess import time worktree = Path(__file__).resolve().parent.parent out = worktree / '.local/gate-7e25b3d-20260912-01' inputs = json.loads((out / 'inputs.json').read_text()) base = json.loads((out / 'summary.json').read_text()) assert base['all_passed'], 'Resolve a genuine base gate failure before this supplement' source = inputs['source'] assert subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=worktree).decode().strip() == source log_path = out / 'allocator-corrected.log' receipt = out / 'allocator-corrected.json' assert not log_path.exists() and not receipt.exists() def sha(path): return hashlib.sha256(path.read_bytes()).hexdigest() assert all(sha(worktree / path) == digest for path, digest in inputs['inputs'].items()) assert all(sha(Path(path)) == digest for path, digest in inputs['protected'].items()) env = os.environ.copy() env['CARGO_TARGET_DIR'] = inputs['target'] env['CARGO_BUILD_JOBS'] = '1' command = ['cargo', 'test', '--locked', '--jobs', '1', '-p', 'oa-core', '--lib', 'capacity_experiment::tests', '--', '--nocapture', '--test-threads=1'] start = datetime.now(timezone.utc).isoformat() clock = time.monotonic() print('START corrected allocator: ' + repr(command), flush=True) with log_path.open('wb') as log: run = subprocess.run(command, cwd=worktree, env=env, stdout=log, stderr=subprocess.STDOUT) text = log_path.read_text(errors='replace') matched = re.search(r'test result: ok\. (\d+) passed; (\d+) failed;', text) count = int(matched.group(1)) if matched else None changed = [path for path, digest in inputs['inputs'].items() if sha(worktree / path) != digest] protected_changed = [path for path, digest in inputs['protected'].items() if sha(Path(path)) != digest] artifacts = [] for path in Path(inputs['target']).rglob('oa_core-*.exe'): artifacts.append({'path': str(path.relative_to(worktree)), 'bytes': path.stat().st_size, 'sha256': sha(path)}) record = {'source': source, 'command': command, 'start': start, 'end': datetime.now(timezone.utc).isoformat(), 'elapsed_seconds': round(time.monotonic()-clock, 3), 'exit': run.returncode, 'passed_tests': count, 'expected_tests': 3, 'accepted': run.returncode == 0 and count == 3 and not changed and not protected_changed, 'changed_inputs': changed, 'changed_protected': protected_changed, 'log_sha256': sha(log_path), 'artifacts': artifacts, 'supersedes_as_test_evidence': 'allocator.json selected zero tests because its filter used the filename instead of module name'} receipt.write_text(json.dumps(record, indent=2) + '\n', encoding='utf-8', newline='\n') print(text, flush=True) print(json.dumps(record), flush=True) raise SystemExit(0 if record['accepted'] else 1)