Branchwell

PulseCanvas / app · pulsecanvas.ai / scripts / verify-native-artifact.py

Raw 2.0 KB on f7455f5645a899a3879cf752f3536fe6de471c90
1#!/usr/bin/env python3
2"""Verify a native-only app's bundled Metal catalog against the current sources."""
3import hashlib
4import json
5import plistlib
6import subprocess
7import sys
8from pathlib import Path
9
10app = Path(sys.argv[1]).resolve()
11flat = (app / 'NativeAssets').is_dir()
12resources = app / ('NativeAssets' if flat else 'Contents/Resources/Resources')
13catalog = json.loads((resources / 'NativeVisualizers.json').read_text())
14expected = json.loads(subprocess.check_output([sys.executable, 'scripts/native-visualizer-catalog.py'], text=True))
15assert catalog == expected, 'Bundled catalog does not match the current source'
16for name, digest in catalog['shaders'].items():
17 assert hashlib.sha256((resources / name).read_bytes()).hexdigest() == digest, name
18 assert hashlib.sha256((Path('Sources/PulseCanvas/Resources') / name).read_bytes()).hexdigest() == digest, name
19bundled = list(app.rglob('PulseCanvas.mp3'))
20assert len(bundled) == 1
21source = Path('Sources/PulseCanvas/Resources/Audio/PulseCanvas.mp3')
22digest = hashlib.sha256(source.read_bytes()).hexdigest()
23assert hashlib.sha256(bundled[0].read_bytes()).hexdigest() == digest, 'Bundled soundtrack changed'
24assert not any(app.rglob('*.milk')) and not any(app.rglob('*projectM*.dylib'))
25info = plistlib.loads((app / ('Info.plist' if flat else 'Contents/Info.plist')).read_bytes())
26executables = app if flat else app / 'Contents/MacOS'
27executable = executables / info['CFBundleExecutable']
28assert executable.is_file()
29for binary in [executable, *executables.glob('*.dylib')]:
30 libraries = subprocess.check_output(['otool', '-L', str(binary)], text=True)
31 assert 'OpenGL' not in libraries and 'projectM' not in libraries, binary
32receipt = {'activeDesigns': catalog['activeCount'], 'reservedIDs': catalog['nativeCount'],
33 'shaderFiles': len(catalog['shaders']), 'app': str(app), 'resourcesMatchSource': True,
34 'soundtrackSHA256': digest, 'engineAndPresetAssetsAbsent': True,
35 'signing': 'Not assessed; this check does not validate release signing or notarization'}
36print(json.dumps(receipt, indent=2))