hop
Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.
Brought by drakestapleton
hop / Linux / tests / check.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Run the Linux acceptance instruments and retain a source-bound receipt.""" |
| 3 | import argparse |
| 4 | import hashlib |
| 5 | import json |
| 6 | from pathlib import Path |
| 7 | import subprocess |
| 8 | import sys |
| 9 | |
| 10 | |
| 11 | def main(): |
| 12 | parser = argparse.ArgumentParser(description=__doc__) |
| 13 | parser.add_argument('--evidence', required=True, type=Path) |
| 14 | args = parser.parse_args() |
| 15 | root = Path(__file__).resolve().parents[2] |
| 16 | evidence = args.evidence.resolve() |
| 17 | evidence.mkdir(parents=True, exist_ok=False) |
| 18 | head = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=root, text=True).strip() |
| 19 | assert not subprocess.check_output(['git', 'status', '--porcelain'], cwd=root), 'source is dirty' |
| 20 | omc = root / 'build/linux-toolchain/seed/out/omc' |
| 21 | runs = [ |
| 22 | ('build', ['sh', 'build.sh']), |
| 23 | ('build-record', [sys.executable, 'Linux/tests/build_record_check.py']), |
| 24 | ('shell-syntax', ['sh', '-n', 'build.sh', 'install.sh']), |
| 25 | ('window', [sys.executable, 'Linux/tests/window_check.py', '--compiler', str(omc), |
| 26 | '--evidence', str(evidence / 'window')]), |
| 27 | ('apps', [sys.executable, 'Linux/tests/apps_check.py', str(omc), |
| 28 | '--core', str(root / 'build/linux/hopcore')]), |
| 29 | ('chat', [sys.executable, 'Linux/tests/chat_check.py', str(omc)]), |
| 30 | ('files', [sys.executable, 'Linux/tests/files_check.py', str(omc), '--evidence', str(evidence / 'files')]), |
| 31 | ('install', [sys.executable, 'Linux/tests/install_check.py', '--compiler', str(omc), |
| 32 | '--evidence', str(evidence / 'install')]), |
| 33 | ('combined', [sys.executable, 'Linux/tests/combined_check.py', |
| 34 | '--binary', str(root / 'build/linux/hop'), |
| 35 | '--evidence', str(evidence / 'combined')]), |
| 36 | ] |
| 37 | receipt = {'head': head, 'results': [], 'status': 'RUNNING', |
| 38 | 'not_run': ['Mac build and desktop', 'physical Linux desktop session', |
| 39 | 'native Wayland', 'XWayland', 'live AI provider']} |
| 40 | for name, command in runs: |
| 41 | result = subprocess.run(command, cwd=root, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 42 | log = evidence / f'{name}.log' |
| 43 | log.write_bytes(result.stdout) |
| 44 | receipt['results'].append({'name': name, 'command': command, 'exit': result.returncode, |
| 45 | 'log': str(log), 'log_sha256': hashlib.sha256(result.stdout).hexdigest()}) |
| 46 | (evidence / 'RECEIPT.json').write_text(json.dumps(receipt, indent=2) + '\n') |
| 47 | print(f'{name}: exit {result.returncode}; {log}', flush=True) |
| 48 | if result.returncode: |
| 49 | receipt['status'] = 'FAIL' |
| 50 | (evidence / 'RECEIPT.json').write_text(json.dumps(receipt, indent=2) + '\n') |
| 51 | print(result.stdout.decode(errors='replace'), file=sys.stderr) |
| 52 | raise SystemExit(1) |
| 53 | assert not subprocess.check_output(['git', 'status', '--porcelain'], cwd=root), 'checks changed source' |
| 54 | receipt['status'] = 'PASS' |
| 55 | receipt['omega_head'] = (root / 'build/linux-toolchain/source-commit').read_text().strip() |
| 56 | receipt['compiler_sha256'] = hashlib.sha256(omc.read_bytes()).hexdigest() |
| 57 | receipt['artifacts'] = {p.name: hashlib.sha256(p.read_bytes()).hexdigest() |
| 58 | for p in (root / 'build/linux/hop', root / 'build/linux/hopcore', |
| 59 | root / 'build/linux/install')} |
| 60 | (evidence / 'RECEIPT.json').write_text(json.dumps(receipt, indent=2) + '\n') |
| 61 | print(f'PASS {evidence / "RECEIPT.json"}') |
| 62 | |
| 63 | |
| 64 | if __name__ == '__main__': |
| 65 | main() |