76 lines
6.5 KiB
Python
76 lines
6.5 KiB
Python
import importlib.util
|
|
from pathlib import Path
|
|
import unittest
|
|
import tempfile,sys
|
|
from unittest.mock import patch
|
|
ROOT=Path(__file__).resolve().parents[2]
|
|
spec=importlib.util.spec_from_file_location('presence_package',ROOT/'scripts/package-avatar-emotion.py')
|
|
pack=importlib.util.module_from_spec(spec);spec.loader.exec_module(pack)
|
|
|
|
class PresencePackageTests(unittest.TestCase):
|
|
def test_direct_yuv_release_requires_diagnostics_and_new_version(self):
|
|
def stop_build(command,**kwargs):
|
|
if command[0]=='python3': return
|
|
for flag in ('-PcameraDirectYuv=true','-PcameraCompatibilityFix=true','-PfaceDiagnosticsFix=true',
|
|
'-PpresenceCandidate=true','-PavatarStartupFix=true','-PactionVersionCode=26'):
|
|
self.assertIn(flag,command)
|
|
raise RuntimeError('build_sentinel')
|
|
with patch.object(pack,'tested_source'),patch.object(pack,'packaging_tests_current'),patch.object(pack,'read_json',
|
|
return_value={'edges':[{'nativeLoop':True}],'camera_callback_replay':True}),patch.object(pack,'next_version',return_value=26),patch.object(pack.subprocess,'run',side_effect=stop_build):
|
|
with self.assertRaises(ValueError): pack.publish({'manifest_sha256':pack.RUNTIME_FIX_PIN},None,26,
|
|
full=True,startup_fix=True,presence_candidate=True,face_diagnostics_fix=True,camera_direct_yuv=True)
|
|
with self.assertRaisesRegex(RuntimeError,'build_sentinel'): pack.publish({'manifest_sha256':pack.RUNTIME_FIX_PIN},None,26,
|
|
full=True,startup_fix=True,presence_candidate=True,face_diagnostics_fix=True,camera_compatibility_fix=True,camera_direct_yuv=True)
|
|
def test_direct_yuv_cli_is_one_purpose(self):
|
|
with tempfile.TemporaryDirectory() as folder:
|
|
args=['package-avatar-emotion.py','--manifest',str(ROOT/'app/src/main/assets'/pack.ASSET_ROOT/'manifest.json'),
|
|
'--sha256',pack.RUNTIME_FIX_PIN,'--output',str(Path(folder)/'evidence'),'--camera-direct-yuv']
|
|
with patch.object(sys,'argv',args),patch.object(pack,'check_bundle',side_effect=RuntimeError('gate_sentinel')):
|
|
with self.assertRaisesRegex(RuntimeError,'gate_sentinel'): pack.main()
|
|
with patch.object(sys,'argv',args+['--camera-compatibility-fix']):
|
|
with self.assertRaisesRegex(ValueError,'choose one build purpose'): pack.main()
|
|
def test_face_diagnostics_release_preserves_startup_and_presence_and_uses_new_code(self):
|
|
def stop_build(command,**kwargs):
|
|
if command[0]=='python3':return
|
|
self.assertIn('-PfaceDiagnosticsFix=true',command)
|
|
self.assertIn('-PpresenceCandidate=true',command)
|
|
self.assertIn('-PavatarStartupFix=true',command)
|
|
self.assertIn('-PactionVersionCode=24',command)
|
|
raise RuntimeError('build_sentinel')
|
|
with patch.object(pack,'tested_source'),patch.object(pack,'packaging_tests_current'),patch.object(pack,'read_json',return_value={'edges':[{'nativeLoop':True}]}),patch.object(pack,'next_version',return_value=24),patch.object(pack.subprocess,'run',side_effect=stop_build):
|
|
with self.assertRaises(ValueError):pack.publish({'manifest_sha256':pack.RUNTIME_FIX_PIN},None,24,full=True,startup_fix=True,face_diagnostics_fix=True)
|
|
with self.assertRaisesRegex(RuntimeError,'build_sentinel'):pack.publish({'manifest_sha256':pack.RUNTIME_FIX_PIN},None,24,full=True,startup_fix=True,presence_candidate=True,face_diagnostics_fix=True)
|
|
def test_camera_compatibility_release_requires_diagnostics_replay_and_fresh_code(self):
|
|
def stop_build(command,**kwargs):
|
|
if command[0]=='python3': return
|
|
for flag in ('-PcameraCompatibilityFix=true','-PfaceDiagnosticsFix=true',
|
|
'-PpresenceCandidate=true','-PavatarStartupFix=true','-PactionVersionCode=25'):
|
|
self.assertIn(flag,command)
|
|
raise RuntimeError('build_sentinel')
|
|
with patch.object(pack,'tested_source'),patch.object(pack,'packaging_tests_current'),patch.object(pack,'read_json',
|
|
return_value={'edges':[{'nativeLoop':True}],'camera_callback_replay':True}),patch.object(pack,'next_version',return_value=25), patch.object(pack.subprocess,'run',side_effect=stop_build):
|
|
with self.assertRaises(ValueError): pack.publish({'manifest_sha256':pack.RUNTIME_FIX_PIN},None,25,
|
|
full=True,startup_fix=True,presence_candidate=True,camera_compatibility_fix=True)
|
|
with self.assertRaisesRegex(RuntimeError,'build_sentinel'): pack.publish({'manifest_sha256':pack.RUNTIME_FIX_PIN},None,25,
|
|
full=True,startup_fix=True,presence_candidate=True,face_diagnostics_fix=True,camera_compatibility_fix=True)
|
|
def test_camera_cli_is_one_purpose_not_two_inherited_flags(self):
|
|
with tempfile.TemporaryDirectory() as folder:
|
|
args=['package-avatar-emotion.py','--manifest',str(ROOT/'app/src/main/assets'/pack.ASSET_ROOT/'manifest.json'),
|
|
'--sha256',pack.RUNTIME_FIX_PIN,'--output',str(Path(folder)/'evidence'),'--camera-compatibility-fix']
|
|
with patch.object(sys,'argv',args),patch.object(pack,'check_bundle',side_effect=RuntimeError('gate_sentinel')):
|
|
with self.assertRaisesRegex(RuntimeError,'gate_sentinel'): pack.main()
|
|
with patch.object(sys,'argv',args+['--face-diagnostics-fix']):
|
|
with self.assertRaisesRegex(ValueError,'choose one build purpose'): pack.main()
|
|
def test_fresh_presence_version_requires_startup_and_frozen_pack(self):
|
|
report={'manifest_sha256':pack.RUNTIME_FIX_PIN}
|
|
def stop_build(command,**kwargs):
|
|
if command[0]=='python3': return
|
|
self.assertIn('-PpresenceCandidate=true',command)
|
|
self.assertIn('-PavatarStartupFix=true',command)
|
|
self.assertIn('-PactionVersionCode=23',command)
|
|
raise RuntimeError('build_sentinel')
|
|
with patch.object(pack,'tested_source'),patch.object(pack,'packaging_tests_current'),patch.object(pack,'read_json',return_value={'edges':[{'nativeLoop':True}]}),patch.object(pack,'next_version',return_value=23),patch.object(pack.subprocess,'run',side_effect=stop_build):
|
|
with self.assertRaises(ValueError):pack.publish(report,None,23,full=True,presence_candidate=True)
|
|
with self.assertRaises(ValueError):pack.publish({**report,'manifest_sha256':'a'*64},None,23,full=True,startup_fix=True,presence_candidate=True)
|
|
with self.assertRaisesRegex(RuntimeError,'build_sentinel'):pack.publish(report,None,23,full=True,startup_fix=True,presence_candidate=True)
|