budget-app/app/tests/verify_apk.py
Arena Assistant 1988457dd1 feat: add macOS capture panel and Android Makepad review
Reuse shared review and confirmation state. Android tile/setup and volatile OCR handoff route into Makepad; native floating controls remain. Android overlay rendering host is not implemented. Prior isolated checks: macOS ARM64 and Android ARM64 library checks, native Linux build/run and tests; native mobile/macOS runtime validation remains outstanding.
2026-10-28 05:02:41 +00:00

30 lines
2 KiB
Python

#!/usr/bin/env python3
"""Inspect the actual Cargo/Makepad APK, never a fake native-library fixture."""
import pathlib, subprocess, sys, tempfile, zipfile
root, sdk = map(pathlib.Path, sys.argv[1:3])
apks = list(root.rglob('*.apk'))
assert apks, 'No APK produced'
apk = max(apks, key=lambda p: p.stat().st_mtime)
aapt = next(p for p in sdk.rglob('aapt') if p.is_file())
permissions = subprocess.check_output([str(aapt), 'dump', 'permissions', str(apk)], text=True)
assert 'org.nigig.oldmutualbudget' in permissions
assert 'android.permission.INTERNET' not in permissions
assert 'android.permission.SYSTEM_ALERT_WINDOW' in permissions
xml = subprocess.check_output([str(aapt), 'dump', 'xmltree', str(apk), 'AndroidManifest.xml'], text=True)
with zipfile.ZipFile(apk) as z:
dex = b''.join(z.read(n) for n in z.namelist() if n.endswith('.dex'))
for name in ['BudgetTileService', 'BudgetOverlayService', 'CapturePermissionActivity', 'ShareToBudget', 'BudgetOcr', 'CapturePermissions', 'ProductExtraction', 'CaptureReviewInbox']:
assert ('Lorg/nigig/budgetshare/'+name+';').encode() in dex, name
if name in ['BudgetTileService', 'BudgetOverlayService', 'CapturePermissionActivity', 'ShareToBudget']:
assert 'org.nigig.budgetshare.'+name in xml, name
lib = z.read('lib/arm64-v8a/libmakepad.so')
assert lib[:4] == b'\x7fELF', 'Not a real native library'
with tempfile.TemporaryDirectory() as d:
path = pathlib.Path(d)/'libmakepad.so'; path.write_bytes(lib)
symbols = subprocess.check_output(['readelf', '--dyn-syms', '--wide', str(path)], text=True)
assert 'Java_org_nigig_budgetshare_BudgetOcr_recognize' in symbols
for model in ['text-detection.onnx', 'text-recognition.onnx']:
path = next(root.rglob(model))
assert path.read_bytes() in lib, 'Missing embedded offline model: '+model
assert any('CC-BY-SA-4.0' in n for n in z.namelist()), 'Missing model licence'
print('Actual APK verified: identity, permissions, native components/DEX, exported OCR JNI and bundled models:', apk)