"""Run the captured build gate and immediately retain its exact GUI/CLI artifacts.""" from pathlib import Path import hashlib, json, shutil, subprocess, sys base = Path(__file__).resolve().parent gate = base.parent / 'text-diagnostic-gates/gate.py' label = sys.argv[1] out = base / (label + '-binaries') assert not out.exists() code = subprocess.run([sys.executable, str(gate), label, 'build', '--locked', '--offline', '--message-format=json', '-p', 'oa-desktop', '-p', 'oa-cli']).returncode if code: sys.exit(code) result_path = gate.parent / label / 'result.json' result = json.loads(result_path.read_text(encoding='utf-8')) assert result['exitCode'] == 0 and result['inputsUnchanged'] def identity(path): data = path.read_bytes() return {'bytes':len(data), 'sha256':hashlib.sha256(data).hexdigest()} out.mkdir() copied = [] for name in ['arcadia-studio', 'arcadia']: candidates = [a for a in result['artifacts'] if a['cargo']['target']['name'] == name and a['cargo']['target']['kind'] == ['bin'] and not a['cargo']['profile']['test']] assert len(candidates) == 1, (name, len(candidates)) artifact = candidates[0] source = Path(artifact['cargo']['executable']) assert identity(source) == artifact['readback'] destination = out / (name + '.exe') shutil.copyfile(source, destination) assert identity(source) == identity(destination) == artifact['readback'] copied.append({'name':name, 'source':str(source), 'path':str(destination), **identity(destination)}) record = {'buildResult':{'path':str(result_path), **identity(result_path)}, 'sourceInputs':result['inputs'], 'helper':identity(Path(__file__)), 'binaries':copied} (out / 'preserved.json').write_text(json.dumps(record, indent=2) + '\n', encoding='utf-8') print(json.dumps(record, indent=2))