Branchwell

PulseCanvas / app · pulsecanvas.ai / scripts / validate-store-artifact.py

Raw 6.6 KB on 87dd19288bbd69b69b6ac6e250fb5d18bfebb877
1#!/usr/bin/env python3
2"""Fail closed on malformed store bundles; --local accepts the Apple Development sandbox test."""
3import argparse, datetime, hashlib, json, pathlib, plistlib, re, subprocess
4p=argparse.ArgumentParser();m=p.add_mutually_exclusive_group();m.add_argument('--local',action='store_true');m.add_argument('--archive',action='store_true',help='Validate a signed archive before distribution export; its development signature may have no profile.');p.add_argument('app',type=pathlib.Path);a=p.parse_args()
5root=a.app.resolve();info=plistlib.loads((root/'Contents/Info.plist').read_bytes())
6exe=root/'Contents/MacOS'/info['CFBundleExecutable']
7assert info['LSMinimumSystemVersion']=='14.0'
8config_root=pathlib.Path(__file__).resolve().parent.parent
9release_config=(config_root/'Version.xcconfig').read_text()+'\n'+(config_root/'macOS/Release.xcconfig').read_text()
10expected_version=re.search(r'^MARKETING_VERSION\s*=\s*(\S+)',release_config,re.M).group(1)
11expected_build=re.search(r'^CURRENT_PROJECT_VERSION\s*=\s*(\S+)',release_config,re.M).group(1)
12assert info['CFBundleShortVersionString']==expected_version
13assert info['CFBundleVersion']==expected_build
14assert info['CFBundleIdentifier']==('com.protomota.pulsecanvas.storevalidation' if a.local else 'com.protomota.pulsecanvas')
15for binary in [exe]:
16 arch=subprocess.check_output(['lipo','-archs',str(binary)],text=True).strip()
17 assert arch=='arm64', (binary,arch)
18subprocess.run(['codesign','--verify','--deep','--strict',str(root)],check=True)
19raw=subprocess.check_output(['codesign','-d','--entitlements',':-',str(root)],stderr=subprocess.DEVNULL)
20ent=plistlib.loads(raw[raw.index(b'<?xml'):])
21for key in ['com.apple.security.app-sandbox','com.apple.security.files.user-selected.read-write','com.apple.security.files.bookmarks.app-scope']:
22 assert ent.get(key) is True,key
23assert not ent.get('com.apple.security.get-task-allow',False)
24# Radio downloads the public catalog and tracks; incoming connections remain disabled.
25assert ent.get('com.apple.security.network.client') is True
26assert not any(ent.get(k) for k in ['com.apple.security.network.server','com.apple.security.device.audio-input','com.apple.security.cs.disable-library-validation'])
27assert not any('temporary-exception' in k for k in ent)
28for binary in [root]:
29 sig=subprocess.check_output(['codesign','-dv','--verbose=4',str(binary)],stderr=subprocess.STDOUT,text=True)
30 assert 'TeamIdentifier=22HV69L32T' in sig and 'runtime' in sig,sig
31if not a.local and not a.archive:
32 assert (root/'Contents/embedded.provisionprofile').exists(),'Provisioning profile missing'
33 assert any(s in subprocess.check_output(['codesign','-dv','--verbose=4',str(root)],stderr=subprocess.STDOUT,text=True) for s in ['Authority=Apple Distribution:', 'Authority=3rd Party Mac Developer Application:']),'App Store distribution signature required'
34 profile=plistlib.loads(subprocess.check_output(['security','cms','-D','-i',str(root/'Contents/embedded.provisionprofile')]))
35 assert profile['TeamIdentifier']==['22HV69L32T']
36 assert profile['Entitlements']['com.apple.application-identifier']=='22HV69L32T.com.protomota.pulsecanvas'
37 assert not profile['Entitlements'].get('com.apple.security.get-task-allow',False)
38 assert not profile.get('ProvisionedDevices') and not profile.get('ProvisionsAllDevices',False),'App Store profile required'
39 assert profile['ExpirationDate'] > datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None),'Provisioning profile expired'
40res=root/'Contents/Resources';privacy=plistlib.loads((res/'PrivacyInfo.xcprivacy').read_bytes())
41assert not privacy['NSPrivacyTracking'] and not privacy['NSPrivacyCollectedDataTypes']
42# Every visual is compiled from PulseCanvas Metal sources; no prebuilt shader modules ship.
43assert not list(res.rglob('*.ll')) and not list(res.rglob('VisualShaders*')),'Retired shader modules must not be bundled'
44for f in ['AppIcon.icns','Legal/Edition.txt','Legal/PulseCanvas-LICENSE.txt']:
45 assert (res/f).is_file(),f
46assert (res/'Legal/PulseCanvas-LICENSE.txt').read_bytes() == (pathlib.Path(__file__).resolve().parent.parent/'LICENSE').read_bytes(),'Bundled application license must match the release source'
47assert not (res/'Legal/PulseCanvas-MIT-LICENSE.txt').exists(),'Obsolete application-license copy must not be bundled'
48# Inspect the actual app, including nested resources and executable imports.
49assert not list(root.rglob('*.milk')), 'OpenGL presets must not be bundled'
50assert not any('projectm' in path.name.lower() or path.name == 'Sparkle.framework' for path in root.rglob('*')), 'Excluded engine/updater resource found'
51assert not any(key.startswith(('SU', 'SPU')) for key in info), 'Sparkle settings must not enter store builds'
52imports=subprocess.check_output(['otool','-L',str(exe)],text=True)
53assert 'OpenGL.framework' not in imports and 'Sparkle' not in imports and 'libprojectM' not in imports, imports
54symbols=subprocess.check_output(['nm','-u',str(exe)],text=True)
55assert 'CGLCreateContext' not in symbols and '_projectm_' not in symbols, 'OpenGL engine symbols found'
56native_catalog = res/'Resources/NativeVisualizers.json'
57if native_catalog.is_file():
58 catalog = json.loads(native_catalog.read_text())
59 slots = catalog['nativeCount']
60 assert catalog['schema'] == 1 and slots == len(catalog['effects'])
61 assert [e['id'] for e in catalog['effects']] == [f'native:{i}' for i in range(slots)]
62 assert [e['scene'] for e in catalog['effects']] == list(range(slots))
63 # Retired designs keep their IDs for migration; the edition counts offered designs.
64 offered = [e for e in catalog['effects'] if not e.get('retired')]
65 count = catalog.get('activeCount', slots)
66 assert count == len(offered) and len({e['name'] for e in offered}) == count
67 for shader, digest in catalog['shaders'].items():
68 assert pathlib.Path(shader).name == shader
69 assert hashlib.sha256((res/'Resources'/shader).read_bytes()).hexdigest() == digest, shader
70else:
71 # Historical 1.0.2 (10) predates native catalog expansion; inspect its own
72 # edition receipt rather than claiming it contains newly developed effects.
73 count = 31
74assert f'{count} native Metal visualizers' in (res/'Legal/Edition.txt').read_text()
75print(json.dumps({'bundle':info['CFBundleIdentifier'],'version':info['CFBundleShortVersionString'],'build':info['CFBundleVersion'],'architecture':'arm64','sandbox':True,'presets':0,'nativeVisualizers':count,'edition':'metal','sparkle':False,'openGL':False,'signing': 'Apple Development local test' if a.local else ('team-signed archive; distribution export required' if a.archive else 'App Store distribution signature; Apple processing status checked separately')},indent=2))