"""Compile one standalone probe against the exact completed desktop dependencies.""" from pathlib import Path from datetime import datetime, timezone import hashlib import json import subprocess import sys root = Path(__file__).resolve().parent.parent source, label, probe = sys.argv[1:4] assert label.replace('-', '').isalnum() probe = (root / probe).resolve() assert probe.is_relative_to(root / '.local') and probe.suffix == '.rs' gate = root / '.local/allocation-union-20260912' result = json.loads((gate / ('full-' + source[:7] + '.result.json')).read_text()) assert result['source'] == source and result['exit'] == 0 and not result['changed_inputs'] manifest = json.loads((gate / result['inputs']).read_text()) for item in manifest['inputs']: if item['path'].startswith(('crates/oa-core/', '.cargo/')) or item['path'] in ['Cargo.toml', 'Cargo.lock', 'rust-toolchain.toml']: assert hashlib.sha256((root / item['path']).read_bytes()).hexdigest() == item['sha256'], item['path'] current_head = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=root).decode().strip() fingerprints = root / 'target/debug/.fingerprint' anchor = fingerprints / 'oa-desktop-e358a5ed59b1de41/test-bin-arcadia-studio.json' desktop = json.loads(anchor.read_text()) dependencies = {} for _, name, _, expected in desktop['deps']: if name not in ['oa_core', 'serde_json']: continue matches = [] for path in fingerprints.glob('*/lib-' + name): if int.from_bytes(bytes.fromhex(path.read_text().strip()), 'little') == expected: suffix = path.parent.name.rsplit('-', 1)[1] rlib = root / 'target/debug/deps' / ('lib' + name + '-' + suffix + '.rlib') if rlib.is_file(): matches.append(rlib) assert len(matches) == 1, (name, matches) dependencies[name] = matches[0] out = root / '.local/native-qa' / label assert not out.exists(), 'Do not overwrite identified experiment output' out.mkdir() command = ['rustc', '--edition=2024', '-D', 'warnings', '-C', 'linker=clang.exe', '-L', 'dependency=' + str(root / 'target/debug/deps')] for name, rlib in dependencies.items(): command += ['--extern', name + '=' + str(rlib)] binary = out / (label + '.exe') command += [str(probe), '-o', str(binary)] start = datetime.now(timezone.utc).isoformat() run = subprocess.run(command, cwd=root, capture_output=True) (out / 'build.log').write_bytes(run.stdout + run.stderr) files = [probe, anchor, *dependencies.values()] if binary.exists(): files.append(binary) record = {'source': source, 'current_head': current_head, 'scope': 'Core-only standalone probe; core/configuration/lock inputs match identified full test run. Desktop changes do not become core evidence.', 'start': start, 'end': datetime.now(timezone.utc).isoformat(), 'command': command, 'exit': run.returncode, 'files': [{'path': str(p.relative_to(root)), 'bytes': p.stat().st_size, 'sha256': hashlib.sha256(p.read_bytes()).hexdigest()} for p in files]} (out / 'build.json').write_text(json.dumps(record, indent=2) + '\n', encoding='utf-8', newline='\n') print((run.stdout + run.stderr).decode('utf-8', errors='replace')) print(json.dumps({'source': source, 'output': str(out), 'exit': run.returncode, 'dependencies': {k: str(v) for k, v in dependencies.items()}})) sys.exit(run.returncode)