Files
baji-vc/scripts/check-avatar-ui.py
T
zenord 7d8ea95f07 feat: add aperture mouth candidate and early foreground permissions
Route runtime04 curve values to five source-frame lip geometries with level0 body bypass and spatial opacity1 for all other levels. Preserve the continuous decoded body clock and clean home. Request normal permissions after foreground host layout independently of network; support offline manual consent without capture or connection. Add strict 97x5 parsing, renderer and permission regressions, offline EGL shader pixel goldens and exact debug-candidate packaging. Naturalness, visible talk, device colors and perceived response remain pending.
2026-10-12 22:55:20 +08:00

75 lines
4.4 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)
left=clean.index('{',at+len(marker),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)
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'):
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
permissions=text(block('fun PermissionSettings'))
for label in ('已授权','未授权','申请麦克风权限','申请摄像头权限','系统权限设置'):
assert label in permissions
assert '本版仅修复界面;嘴层沿用 runtime03,变形问题尚未修复' in source
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.')