feat: validate per-body mouth timelines and reviewed conversation routes

This commit is contained in:
zenord
2026-10-13 01:23:43 +08:00
parent 4358fc9cae
commit 4ead34a944
17 changed files with 646 additions and 61 deletions
+2 -2
View File
@@ -341,8 +341,8 @@
},
"tests/test_action_protocol.py": {
"source": "workspace:gateway/tests/test_action_protocol.py",
"sha256": "2e19bb1471a2bab67bfb7adca1630151d466e50d9ebc103e54c2f92566f63b63",
"bytes": 9776,
"sha256": "fdc6c6206a6a0478166bc49b062c2981158cf1a6a8cdcf3e0d0df57a86fa4020",
"bytes": 15127,
"upstream_sha256": "ae564b6a6e51620a33250e160df2ae0ba6619c5ea6d1063e96bfcd8baa144a79"
},
"tests/test_action_reply.py": {
+83
View File
@@ -66,6 +66,89 @@ class ActionProtocolTests(unittest.TestCase):
class ActionDialogueTests(unittest.IsolatedAsyncioTestCase):
async def prepare_fixture_action(self, d):
d.action_capability=PACK;d.playback_waiting=True
queue=asyncio.Queue(2);metrics={}
await d.generate(0,'公开合成请求',queue,metrics,time.perf_counter())
await d.synthesize(0,queue,metrics,time.perf_counter())
await d.drained()
ticket=d.action_plans.ticket
self.assertTrue(ticket and d.action_holding)
start={'action_id':ticket.id,'turn_id':0,'status':'started','asset_id':'asset_01','mic_stopped':True}
await d.action_status(start);ticket.started-=1.1
return {**start,'status':'completed','video_ended':True,'audio_stopped':True,'idle_restored':True}
async def test_full_fixture_cancel_and_failure_never_synthesize_after(self):
for status in ('cancelled','failed'):
with self.subTest(status=status):
calls=[]
def backend(request):
calls.append(request.url.port)
if request.url.port==8888:
return httpx.Response(200,text='data: '+json.dumps({'choices':[{'delta':{'content':RAW},'finish_reason':'stop'}]})+'\n\ndata: [DONE]\n\n')
return httpx.Response(200,content=wav(b'\x10\x02'*4800,48000))
async with httpx.AsyncClient(transport=httpx.MockTransport(backend)) as client:
socket=Socket();d=Dialogue(socket,FakeModel(),client)
complete=await self.prepare_fixture_action(d)
before=len(socket.frames)
await d.action_status({**complete,'status':status})
await d.action_status(complete)
self.assertEqual(calls,[8888,5002])
self.assertEqual(len(socket.frames),before)
self.assertIsNone(d.task);self.assertIsNone(d.action_plans.ticket)
self.assertFalse(any(e['type']=='speech.start' for e in socket.events))
self.assertFalse(d.action_holding)
await d.close()
async def test_full_fixture_new_turn_aborts_inflight_after_generator(self):
calls=[];entered=asyncio.Event();release=asyncio.Event()
async def backend(request):
calls.append(request.url.port)
if request.url.port==8888:
return httpx.Response(200,text='data: '+json.dumps({'choices':[{'delta':{'content':RAW},'finish_reason':'stop'}]})+'\n\ndata: [DONE]\n\n')
if calls.count(5002)==2:
entered.set();await release.wait()
return httpx.Response(200,content=wav(b'\x10\x02'*4800,48000))
with tempfile.TemporaryDirectory() as folder:
h=History(Path(folder)/'h.db');await h.initialize();cid=await h.conversation()
async with httpx.AsyncClient(transport=httpx.MockTransport(backend)) as client:
socket=Socket();d=Dialogue(socket,FakeModel(),client,h,cid)
complete=await self.prepare_fixture_action(d)
before=len(socket.frames)
await d.action_status(complete)
task=d.task;await asyncio.wait_for(entered.wait(),2)
self.assertEqual(d.turn,1)
await d.invalidate('new_turn');release.set()
with self.assertRaises(asyncio.CancelledError): await task
await d.request_drained(1);await d.action_status(complete)
self.assertEqual(calls,[8888,5002,5002])
self.assertEqual(len(socket.frames),before)
self.assertIsNone(d.followup_pending)
self.assertEqual(await h.rows(cid),[])
self.assertEqual(await h.context(cid,'next'),[])
await d.close()
async def test_actual_generate_speculative_prepare_final_cancel_and_no_second_llm(self):
for tail,finish in [(',"emotion":"sad"}', 'stop'),(',"extra":1}', 'stop'),('', 'length')]:
with self.subTest(tail=tail,finish=finish):
raw=RAW[:-1]+tail;calls=[]
def backend(request):
calls.append(request.url.port)
chunks=[raw[i:i+1] for i in range(len(raw))]
data=''.join('data: '+json.dumps({'choices':[{'delta':{'content':chunk}}]})+'\n\n' for chunk in chunks)
return httpx.Response(200,text=data+'data: '+json.dumps({'choices':[{'finish_reason':finish,'delta':{}}]})+'\n\ndata: [DONE]\n\n')
async with httpx.AsyncClient(transport=httpx.MockTransport(backend)) as client:
socket=Socket();d=Dialogue(socket,FakeModel(),client);d.action_capability=PACK
queue=asyncio.Queue(2)
await d.generate(0,'公开合成请求',queue,{},time.perf_counter())
types=[e['type'] for e in socket.events]
self.assertLess(types.index('reply.emotion.prepare'),types.index('reply.emotion.prepare.cancel'))
self.assertLess(types.index('reply.emotion.prepare.cancel'),types.index('reply.emotion'))
self.assertEqual(calls,[8888]);self.assertIsNone(d.action_plans.ticket)
self.assertFalse((await queue.get()).startswith('{'))
self.assertIsNone(await queue.get())
await d.close()
async def test_single_llm_then_drained_music_then_single_followup_and_history(self):
calls=[]
def backend(request):