106 lines
6.6 KiB
Python
106 lines
6.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Clean-home source contracts. Complements compiled UI and optional real-device probe;
|
|
this does not claim to run Compose or prove device appearance/lifecycle."""
|
|
from pathlib import Path
|
|
import re
|
|
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
source=(ROOT/'app/src/main/java/com/gorios/lanvoice/avatar/CallScreen.kt').read_text()
|
|
# Blank comments/strings without changing offsets, so nested lambdas can be inspected.
|
|
pattern=r'"""[\s\S]*?"""|"(?:\\.|[^"\\])*"|//[^\n]*|/\*[\s\S]*?\*/'
|
|
clean=re.sub(pattern,lambda m:' '*len(m[0]),source)
|
|
|
|
def block(marker,within=None):
|
|
start,end=within or (0,len(source))
|
|
at=clean.index(marker,start,end)
|
|
body_at=at+len(marker)
|
|
if marker.startswith('fun '):
|
|
# Default callback lambdas belong to the parameter list, not the body.
|
|
params=clean.index('(',body_at,end)
|
|
depth=1;body_at=params+1
|
|
while depth:
|
|
assert body_at<end,'Unclosed Kotlin parameters'
|
|
depth+=(clean[body_at]=='(')-(clean[body_at]==')');body_at+=1
|
|
left=clean.index('{',body_at,end)
|
|
depth=1;right=left+1
|
|
while depth:
|
|
assert right<end,'Unclosed Kotlin block'
|
|
depth+=(clean[right]=='{')-(clean[right]=='}');right+=1
|
|
return left+1,right-1
|
|
|
|
def text(span): return source[slice(*span)]
|
|
def no_calls(span,names):
|
|
for name in names:
|
|
assert not re.search(r'\b'+name+r'\s*\(',clean[slice(*span)]),f'Forbidden {name} outside settings'
|
|
|
|
scaffold=block('fun CleanAvatarScaffold')
|
|
home=block('Box(',scaffold)
|
|
sheet=block('if(settingsOpen)',scaffold)
|
|
assert text(home).count('avatar()')==1
|
|
assert text(home).count('IconButton(')==1
|
|
assert 'Alignment.BottomEnd' in text(home) and 'size(48.dp)' in text(home)
|
|
assert 'WindowInsets.safeDrawing' in text(home)
|
|
assert 'settingsOpen=true' in text(home)
|
|
assert text(home).index('avatar()') < text(home).index('VoiceStatusView(it)')
|
|
assert 'Alignment.TopEnd' in text(home) and '.padding(12.dp).size(36.dp)' in text(home)
|
|
assert 'update={it.state=voiceStatus}' in text(home)
|
|
assert 'voiceStatus: com.gorios.lanvoice.VoiceStatusView.State=com.gorios.lanvoice.VoiceStatusView.State.IDLE' in source
|
|
no_calls(home,['Text','TextButton','Button','OutlinedButton','AvatarDiagnostics','ExpressionControls','settings'])
|
|
assert 'rememberSaveable { mutableStateOf(false) }' in text(scaffold)
|
|
assert text(sheet).count('settings()')==1 and text(sheet).count('settingsOpen=false')==2
|
|
no_calls(sheet,['avatar','AvatarPortrait','ContinuousPortrait','dial','render','startVoice','setContent'])
|
|
assert 'LaunchedEffect' not in text(scaffold) and 'DisposableEffect' not in text(scaffold)
|
|
for name in ('CallScreen','EngineeringPreviewScreen'):
|
|
fn=block('fun '+name)
|
|
avatar=block('CleanAvatarScaffold(avatar=',fn);settings=block('},settings=',fn)
|
|
assert text(avatar).count('AvatarPortrait(')==1
|
|
no_calls(avatar,['Text','AvatarDiagnostics','ExpressionControls','Button','TextButton'])
|
|
assert 'AvatarDiagnostics(pack,video)' in text(settings)
|
|
assert 'PermissionSettings(' in text(settings)
|
|
assert 'settingsOpen' not in text(fn)
|
|
if name=='CallScreen':
|
|
for expected in ('正在连接','重试连接','permissionMessage','onAuthorizeMic','onMute','onCamera','ExpressionControls','请求表达','onReport'):
|
|
assert expected in text(settings)
|
|
else:
|
|
for expected in ('离线 avatar','Idle','Talk','Abort','Trace','舞蹈 01','舞蹈 02','停止舞蹈','onReport'):
|
|
assert expected in text(settings)
|
|
for name in ('AvatarPortrait','ContinuousPortrait'):
|
|
fn=text(block('fun '+name))
|
|
assert 'remember(pack)' in fn and 'DisposableEffect(view)' in fn
|
|
assert 'settingsOpen' not in fn
|
|
activity=(ROOT/'app/src/main/java/com/gorios/lanvoice/MainActivity.kt').read_text()
|
|
offline=activity[activity.index('if (offlineAvatarPreview) {'):activity.index('audioOutput = AudioOutputGate')]
|
|
assert 'EngineeringPreviewScreen' in offline and 'return' in offline
|
|
for forbidden in ('VoiceSession(', 'ExpressionController(', 'permission.launch(', '.dial('): assert forbidden not in offline
|
|
assert 'conversationEnabled=false,automaticPermissions=false' in offline
|
|
assert 'isLaidOut' in activity and 'isAttachedToWindow' in activity
|
|
for method,next_method in (('authorizeMicrophone','authorizeCamera'),('authorizeCamera','retryConnection')):
|
|
body=activity[activity.index('private fun '+method):activity.index('private fun '+next_method)]
|
|
assert 'ConnectionStatus.CONNECTED' not in body,'Manual consent must not depend on HELLO'
|
|
assert 'granted(Manifest.permission.' in body and 'openSettings()' in body
|
|
assert 'entry.permissionPending!=permission' in activity
|
|
assert 'actionPlayer = avatarMedia' in activity and 'onPrepareExpression = avatarMedia::prepare' in activity
|
|
assert 'avatarMedia.beginTurn(it.turnId)' in activity and 'mediaBinding = avatarMedia' in activity
|
|
assert 'pack?.emotionAction!=null && mediaBinding!=null' in source
|
|
assert 'remember(pack,mediaBinding) { EmotionActionAvatarView' in source
|
|
assert 'onOfflinePreview' in text(block('},settings=',block('fun CallScreen')))
|
|
assert 'danceActive' in text(block('fun EngineeringPreviewScreen'))
|
|
assert 'if(::expressions.isInitialized) expressions.diagnosticsSnapshot()' in activity and 'if(::session.isInitialized) session.faceDiagnosticsSnapshot()' in activity
|
|
assert 'EMOTION_MANIFEST_SHA' in (ROOT/'app/src/main/java/com/gorios/lanvoice/avatar/AvatarPack.kt').read_text()
|
|
permissions=text(block('fun PermissionSettings'))
|
|
for label in ('已授权','未授权','申请麦克风权限','申请摄像头权限','系统权限设置'):
|
|
assert label in permissions
|
|
assert '本版仅修复界面;嘴层沿用 runtime03,变形问题尚未修复' in source
|
|
status=text(block('fun StartupStatus'))
|
|
assert 'if(stage!="preparing" && !connecting) return' in status
|
|
assert 'if(stage=="preparing")' in status and 'if(connecting)' in status
|
|
assert 'end=88.dp' in text(home) and 'StartupStatus(' in text(home)
|
|
assert 'VoiceStatusView.State.valueOf(state.voiceIndicator.name)' in text(block('fun CallScreen'))
|
|
assert 'voiceStatus=' not in text(block('fun EngineeringPreviewScreen'))
|
|
assert 'remember(mediaBinding) { StartupAvatarView' in source
|
|
assert 'LaunchedEffect(resumed,restart,override,danceActive,pack)' in source
|
|
assert 'if(!BuildConfig.AVATAR_STARTUP_FIX) avatarPack = AvatarPack.load(this)' in activity
|
|
assert activity.index('setContent {') < activity.index('private fun initializeNormal')
|
|
assert 'OnDrawListener' in activity and 'StartupAvatarRepository.request' in activity
|
|
print('PASS: clean home has persistent avatar + one 48dp safe-inset gear; normal/offline text and controls are sheet-only; sheet state never keys renderer/session; offline construction bypasses sensors/network. Source contracts only; real-device probe pending.')
|