Files
baji-vc/scripts/check-avatar-ui.py
T
zenord 9ea5eb31c1 feat: deliver clean avatar home in 0.6.2 UI debug candidate
Keep the avatar mounted while all connection, permission, privacy and diagnostic controls live in a settings sheet. Save the tested continuous-body renderer, safe transition driver and foreground HELLO/permission workflow from this session. Pin runtime03 for the code14 UI-only candidate; mouth deformation remains unresolved. Add source UI contracts, an optional sensor-free device probe, exact asset import and candidate packaging checks. Portrait binaries and diagnostics remain private and untracked.
2026-10-12 22:19:56 +08:00

64 lines
3.5 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 '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 '本版仅修复界面;嘴层沿用 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.')