Add isolated Liam persona test APK profile

This commit is contained in:
zenord
2026-10-14 17:50:40 +08:00
parent 5a7be557d0
commit 4c70ff665e
12 changed files with 197 additions and 54 deletions
+45 -17
View File
@@ -5,7 +5,9 @@ Run with the existing gori-speech interpreter. Compiles Kotlin against determini
Android main/transport/JSON adapters. All server identities and history are synthetic.
"""
import ast
import argparse
import asyncio
import hashlib
import json
from pathlib import Path
import shutil
@@ -14,6 +16,20 @@ import sys
import tempfile
ROOT=Path(__file__).resolve().parents[1]
parser=argparse.ArgumentParser(description=__doc__)
parser.add_argument('--gateway-source',type=Path,default=ROOT/'gateway',
help='Existing canonical source or read-only snapshot; never changes/deploys the gateway')
args=parser.parse_args()
gateway_root=args.gateway_source.resolve(strict=True)
snapshot=gateway_root/'SNAPSHOT.json'
if snapshot.exists():
for name,digest in json.loads(snapshot.read_bytes()).items():
path=(gateway_root/name).resolve(strict=True)
assert path.is_relative_to(gateway_root) and hashlib.sha256(path.read_bytes()).hexdigest()==digest,'canonical snapshot drift'
resolver=ast.parse((gateway_root/'persona_resolver.py').read_text())
registered=next(ast.literal_eval(n.value) for n in resolver.body if isinstance(n,ast.Assign) and
any(isinstance(t,ast.Name) and t.id=='PERSONAS' for t in n.targets))
personas=['default','lvbu']+(['liam'] if 'liam' in registered else [])
tree=ast.parse((ROOT/'scripts/check-reply-regressions.py').read_text())
nodes=[]
for node in tree.body:
@@ -35,15 +51,16 @@ with tempfile.TemporaryDirectory(prefix='character-handshake-') as folder:
'-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',
subprocess.run([ns['JAVA'],'-Dcharacter.helloFile='+str(hello_file),
'-Dcharacter.personas='+','.join(personas),'-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')
for path in gateway_root.glob('*.py'):shutil.copyfile(path,stage/path.name)
shutil.copyfile(gateway_root/'reviewed_action_packs.json',stage/'reviewed_action_packs.json')
shutil.copytree(gateway_root/'personas',stage/'personas')
(stage/'web').mkdir()
(stage/'.runtime/personas').mkdir(parents=True)
for persona in ('lvbu','yangmi_fiction'):
for persona in [p for p in personas if p!='default']+['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'''
@@ -62,34 +79,45 @@ class NoInferenceModel:
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')]
state.voices=[dict(id=v) for v in (gateway.DEFAULT_VOICE_ID,'synthetic-lvbu','synthetic-yangmi_fiction','synthetic-liam')]
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=[]
sessions=[]
original=gateway.Dialogue.send_history
async def observe_session(self):
sessions.append((self.persona,getattr(self,'persona_language','zh'),self.voice_id))
await original(self)
gateway.Dialogue.send_history=observe_session
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)
persona=hello['persona']
expected_voice='synthetic-'+(persona if persona!='default' else 'yangmi_fiction')
assert ack['voice_id']==expected_voice
assert profile.call_count==(1 if persona=='default' else 0)
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 sessions[-1]==('yangmi_fiction' if persona=='default' else persona,
'en' if persona=='liam' else 'zh',expected_voice)
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()
for persona in sorted({x['persona'] for x in hellos}-{'default'}):
hello=next(x for x in hellos if x['persona']==persona and 'action_pack_sha256' in x)
with patch('gateway.load_active_profile',side_effect=AssertionError('explicit persona 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-'+persona and ack['conversation_id'] not in ids
ws.receive_json();ids.append(ack['conversation_id'])
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')
print('PASS: '+str(len(ids))+' canonical ASGI WS handshakes from actual Android HELLO; personas='+','.join(sorted({x["persona"] for x in hellos}))+'; explicit persona ignores active_profile, server-locks voice/language, 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)