feat(android): add isolated lvbu persona build and pinned asset selection

This commit is contained in:
zenord
2026-10-14 16:41:36 +08:00
parent 3371997252
commit 5a7be557d0
23 changed files with 1507 additions and 31 deletions
+95
View File
@@ -0,0 +1,95 @@
#!/usr/bin/env python3
"""Production Android AUTH/HELLO -> isolated existing ASGI gateway, no live services.
Run with the existing gori-speech interpreter. Compiles Kotlin against deterministic
Android main/transport/JSON adapters. All server identities and history are synthetic.
"""
import ast
import asyncio
import json
from pathlib import Path
import shutil
import subprocess
import sys
import tempfile
ROOT=Path(__file__).resolve().parents[1]
tree=ast.parse((ROOT/'scripts/check-reply-regressions.py').read_text())
nodes=[]
for node in tree.body:
if isinstance(node,ast.Assign) and any(isinstance(t,ast.Name) and t.id=='parser' for t in node.targets):break
nodes.append(node)
ns={'__file__':str(ROOT/'scripts/check-reply-regressions.py')}
exec(compile(ast.Module(body=nodes,type_ignores=[]),'test-toolchain','exec'),ns)
with tempfile.TemporaryDirectory(prefix='character-handshake-') as folder:
stage=Path(folder)
source=ROOT/'app/src/main/java/com/gorios/lanvoice'
files=list((ROOT/'tests/character').glob('*.kt'))
files+=[ROOT/'tests/session'/n for n in ('AndroidMain.kt','AndroidLog.kt','DebugUploadDouble.kt')]
files+=[ROOT/'tests/protocol/JSONArrayDouble.kt']
files+=[source/n for n in ('net/DialogueClient.kt','net/DialogueProtocol.kt','diag/DiagnosticLog.kt',
'diag/StartupTrace.kt','avatar/ActionController.kt','dialogue/ReplyEmotion.kt',
'expression/FaceCueRules.kt','expression/ExpressionRules.kt','expression/PresenceRules.kt')]
subprocess.run([ns['JAVA'],'-cp',ns['compiler'],'org.jetbrains.kotlin.cli.jvm.K2JVMCompiler',
'-no-stdlib','-no-reflect','-jvm-target','17','-nowarn','-classpath',ns['cp'],
'-d',str(stage/'classes'),*map(str,files)],check=True)
hello_file=stage/'hello.jsonl'
subprocess.run([ns['JAVA'],'-Dcharacter.helloFile='+str(hello_file),'-cp',
str(stage/'classes')+':'+ns['cp'],'HandshakeCheckKt'],check=True,timeout=30)
hellos=[json.loads(row) for row in hello_file.read_text().splitlines()]
for path in (ROOT/'gateway').glob('*.py'):shutil.copyfile(path,stage/path.name)
shutil.copyfile(ROOT/'gateway/reviewed_action_packs.json',stage/'reviewed_action_packs.json')
shutil.copytree(ROOT/'gateway/personas',stage/'personas')
(stage/'web').mkdir()
(stage/'.runtime/personas').mkdir(parents=True)
for persona in ('lvbu','yangmi_fiction'):
(stage/'.runtime/personas'/ (persona+'.json')).write_text(json.dumps({'voice_id':'synthetic-'+persona}))
# New interpreter: imports never reach a live gateway or its private configuration.
runner=r'''
import asyncio,json
from pathlib import Path
from unittest.mock import patch
from fastapi.testclient import TestClient
import gateway
from history import History
from guest_sessions import GuestSessions
state=gateway.app.state
state.busy=False;state.token='synthetic-character-token-'+('x'*24)
class NoInferenceModel:
def new_state(self): return None
def infer(self,*args): raise AssertionError('no ASR/VAD/model calls authorized by this fixture')
state.model=NoInferenceModel();state.client=None;state.guests=GuestSessions()
state.guest_enabled=False;state.lan_open=False;state.debug=None
state.voices=[dict(id=v) for v in (gateway.DEFAULT_VOICE_ID,'synthetic-lvbu','synthetic-yangmi_fiction')]
history=History(Path('synthetic.sqlite3'));asyncio.run(history.initialize());state.history=history
client=TestClient(gateway.app) # no lifespan/model loading
hellos=[json.loads(row) for row in Path('hello.jsonl').read_text().splitlines()]
ids=[]
for hello in hellos:
with patch('gateway.load_active_profile',return_value={'persona':'yangmi_fiction','voice_id':'synthetic-yangmi_fiction'}) as profile:
with client.websocket_connect('/ws/dialogue',headers={'Origin':'https://192.168.31.61:5011'}) as ws:
ws.send_json(dict(type='auth',token=state.token));assert ws.receive_json()['type']=='auth'
ws.send_json(hello)
ack=ws.receive_json();assert ack['type']=='hello'
assert ack['voice_id']==('synthetic-lvbu' if hello['persona']=='lvbu' else 'synthetic-yangmi_fiction')
assert profile.call_count==(0 if hello['persona']=='lvbu' else 1)
assert ack['action_available']==('action_pack_sha256' in hello)
assert ack['action_pending']==('action_pending_pack_sha256' in hello)
assert ack['conversation_id'] not in ids;ids.append(ack['conversation_id'])
assert ws.receive_json()['type']=='history'
assert state.busy is False, 'disconnect did not release existing gateway busy owner'
# A non-default persona stays server-locked even if a caller offers another voice/CID.
hello=next(x for x in hellos if x['persona']=='lvbu' and 'action_pack_sha256' in x)
with patch('gateway.load_active_profile',side_effect=AssertionError('lvbu must ignore global profile')):
with client.websocket_connect('/ws/dialogue',headers={'Origin':'https://192.168.31.61:5011'}) as ws:
ws.send_json(dict(type='auth',token=state.token));ws.receive_json()
ws.send_json(dict(hello,voice_id=gateway.DEFAULT_VOICE_ID,conversation_id=ids[0]))
ack=ws.receive_json()
assert ack['voice_id']=='synthetic-lvbu' and ack['conversation_id'] not in ids
ws.receive_json()
assert state.busy is False
print('PASS: five existing ASGI WS handshakes from actual Android HELLO; lvbu ignores active_profile, server-locks voice, fresh CID, ready/pending exact pin and disconnect busy cleanup; 0 ASR/LLM/TTS calls, synthetic-only')
'''
subprocess.run([sys.executable,'-c',runner],cwd=stage,check=True,timeout=30)