budget-app/budget-capture/tests/test_android_contract.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

47 lines
2.5 KiB
Python

"""Source-level privacy/lifecycle guards; these are NOT Android device tests."""
from pathlib import Path
import unittest
JAVA = Path(__file__).resolve().parents[1]/'src/sys/android'
class AndroidContract(unittest.TestCase):
def test_projection_stops_before_offline_worker_and_recycles(self):
source = (JAVA/'BudgetOverlayService.java').read_text()
self.assertLess(source.index('releaseCapture(); foreground(false);'), source.index('ocrWorker.execute'))
self.assertIn('finally { pixels.recycle(); }', source)
self.assertIn('!destroyed && current==generation', source)
self.assertIn('START_NOT_STICKY', source)
self.assertNotIn('com.google.mlkit', source)
self.assertIn('ocrWorker.shutdown()', source)
def test_jni_library_and_consent_not_background_capture(self):
source = (JAVA/'BudgetOcr.java').read_text()
self.assertIn('System.loadLibrary("makepad")', source)
self.assertIn('Arrays.fill(pixels,0)', source)
permission = (JAVA/'CapturePermissionActivity.java').read_text()
self.assertIn('createScreenCaptureIntent', permission)
self.assertNotIn('SharedPreferences', permission)
def test_tile_opens_makepad_and_consent_activity_has_no_custom_ui(self):
tile = (JAVA/'BudgetTileService.java').read_text()
self.assertIn('CaptureReviewInbox.requestOpen()', tile)
self.assertIn('getLaunchIntentForPackage', tile)
self.assertNotIn('CapturePermissionActivity.class', tile)
consent = (JAVA/'CapturePermissionActivity.java').read_text()
self.assertNotIn('setContentView', consent)
self.assertNotIn('new Button', consent)
self.assertIn('createScreenCaptureIntent', consent)
def test_review_handoff_is_volatile_and_has_no_java_editor(self):
source = (JAVA/'BudgetOverlayService.java').read_text()
review = source[source.index(' private void showResult()'):source.index(' @Override public void onDestroy()')]
self.assertIn('CaptureReviewInbox.offer(recognized)', review)
self.assertNotIn('EditText', review)
self.assertNotIn('putExtra', review)
self.assertNotIn('ShareToBudget', review)
inbox = (JAVA/'CaptureReviewInbox.java').read_text()
for forbidden in ['SharedPreferences', 'FileOutputStream', 'Intent', 'Bitmap']:
self.assertNotIn(forbidden, inbox.split('public final class')[1])
self.assertIn('TTL_NANOS', inbox)
self.assertIn('MAX_CHARS', inbox)
if __name__ == '__main__': unittest.main()