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)
+14 -7
View File
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
"""Build/verify one trusted Lvbu debug profile over unchanged code33 media.
"""Build/verify one trusted persona debug profile over unchanged code33 media.
No gateway mutations, voice selection, model calls or device installation.
Default profile can be built and verified separately without publishing a main APK.
@@ -116,8 +116,13 @@ def verify(apk, profile, version):
'actual_dex_verified': True, 'device': 'not_run', 'gateway_changed': False}
def artifact_name(profile, version):
require(profile in ('lvbu-test', 'liam-test'), 'main publication outside this task')
return f"lan-voice-v0714-{profile}-code{version}-arm64-debug.apk"
def publish(apk, report):
name = f"lan-voice-v0714-lvbu-test-code{report['version_code']}-arm64-debug.apk"
name = artifact_name(report['profile'], report['version_code'])
artifact = ROOT/'artifacts'/name
with artifact.open('xb') as out, apk.open('rb') as src:
shutil.copyfileobj(src, out)
@@ -136,16 +141,18 @@ def publish(apk, report):
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--profile', choices=['main', 'lvbu-test'], default='lvbu-test')
parser.add_argument('--version-code', type=int, default=34)
parser.add_argument('--profile', choices=sorted(select.catalog()['profiles']), default='lvbu-test')
parser.add_argument('--version-code', type=int)
parser.add_argument('--build', action='store_true')
parser.add_argument('--publish', action='store_true')
parser.add_argument('--output', type=Path, required=True)
args = parser.parse_args()
require(args.version_code >= 34, 'fresh character version required')
require(not args.publish or args.profile == 'lvbu-test', 'main publication outside this task')
minimum = select.catalog()['profiles'][args.profile].get('minimumVersionCode', 34)
args.version_code = args.version_code if args.version_code is not None else minimum
require(args.version_code >= minimum, 'fresh character version required')
require(not args.publish or args.profile != 'main', 'main publication outside this task')
if args.publish:
require(not (ROOT/'artifacts'/f'lan-voice-v0714-lvbu-test-code{args.version_code}-arm64-debug.apk').exists(),
require(not (ROOT/'artifacts'/artifact_name(args.profile, args.version_code)).exists(),
'published character version is immutable; choose a new code')
if args.build:
subprocess.run([str(ROOT/'scripts/build.sh'), ':app:assembleDebug', ':app:compileDebugAndroidTestKotlin',
+2 -2
View File
@@ -34,7 +34,7 @@ def digest(data):
def catalog():
data = json.loads(CATALOG.read_bytes())
require(data['schemaVersion'] == 1 and set(data['profiles']) == {'main', 'lvbu-test'}, 'unsupported profile catalog')
require(data['schemaVersion'] == 1 and set(data['profiles']) == {'main', 'lvbu-test', 'liam-test'}, 'unsupported profile catalog')
return data
@@ -140,7 +140,7 @@ def stage(assets, output, report):
def main():
p = argparse.ArgumentParser(description=__doc__)
p.add_argument('--profile', choices=['main', 'lvbu-test'], required=True)
p.add_argument('--profile', choices=sorted(catalog()['profiles']), required=True)
p.add_argument('--assets', type=Path, default=ROOT / 'app/src/main/assets')
p.add_argument('--emotion-sha', default='')
for flag in ('user-assets', 'mouth', 'startup'):