feat(vela): mock push-to-talk transcript updates
This commit is contained in:
@@ -14,6 +14,22 @@ const WEBSOCKET_GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
|
||||
const MOCKED_USER_TRANSCRIPT = '[mocked user] What is the current mocked vertical slice?';
|
||||
const MOCKED_ASSISTANT_RESPONSE = '[mocked assistant] This is a deterministic mocked response from the gateway vertical slice.';
|
||||
|
||||
function createPlaceholderPartialTranscript(audioChunkCount) {
|
||||
return audioChunkCount === 1
|
||||
? '[mocked partial] Placeholder push-to-talk transcript in progress.'
|
||||
: `[mocked partial] Placeholder push-to-talk transcript in progress (${audioChunkCount} chunks).`;
|
||||
}
|
||||
|
||||
function createPlaceholderFinalTranscript(audioChunkCount) {
|
||||
if (audioChunkCount === 0) {
|
||||
return '[mocked final] Placeholder push-to-talk transcript completed without appended audio.';
|
||||
}
|
||||
|
||||
return audioChunkCount === 1
|
||||
? '[mocked final] Placeholder push-to-talk transcript completed from 1 appended chunk.'
|
||||
: `[mocked final] Placeholder push-to-talk transcript completed from ${audioChunkCount} appended chunks.`;
|
||||
}
|
||||
|
||||
function createSessionRecord() {
|
||||
return {
|
||||
id: crypto.randomUUID(),
|
||||
@@ -238,6 +254,9 @@ function handleClientMessage(socket, session, rawMessage) {
|
||||
|
||||
session.audioChunkCount += 1;
|
||||
updateSessionState(socket, session, 'listening');
|
||||
sendSocketMessage(socket, 'transcript.partial', {
|
||||
text: createPlaceholderPartialTranscript(session.audioChunkCount)
|
||||
});
|
||||
break;
|
||||
case 'input_audio.commit':
|
||||
if (session.mockedTurnInFlight) {
|
||||
@@ -245,6 +264,9 @@ function handleClientMessage(socket, session, rawMessage) {
|
||||
break;
|
||||
}
|
||||
|
||||
sendSocketMessage(socket, 'transcript.final', {
|
||||
text: createPlaceholderFinalTranscript(session.audioChunkCount)
|
||||
});
|
||||
session.audioChunkCount = 0;
|
||||
updateSessionState(socket, session, 'idle');
|
||||
break;
|
||||
|
||||
@@ -293,8 +293,16 @@ test('websocket handles valid and invalid client messages safely', async () => {
|
||||
type: 'session.state',
|
||||
payload: { value: 'listening' }
|
||||
});
|
||||
assert.deepEqual(await client.nextMessage(), {
|
||||
type: 'transcript.partial',
|
||||
payload: { text: '[mocked partial] Placeholder push-to-talk transcript in progress.' }
|
||||
});
|
||||
|
||||
client.sendJson({ type: 'input_audio.commit', payload: {} });
|
||||
assert.deepEqual(await client.nextMessage(), {
|
||||
type: 'transcript.final',
|
||||
payload: { text: '[mocked final] Placeholder push-to-talk transcript completed from 1 appended chunk.' }
|
||||
});
|
||||
assert.deepEqual(await client.nextMessage(), {
|
||||
type: 'session.state',
|
||||
payload: { value: 'idle' }
|
||||
@@ -340,8 +348,16 @@ test('websocket accepts a placeholder input cycle before a mocked turn on the sa
|
||||
type: 'session.state',
|
||||
payload: { value: 'listening' }
|
||||
});
|
||||
assert.deepEqual(await client.nextMessage(), {
|
||||
type: 'transcript.partial',
|
||||
payload: { text: '[mocked partial] Placeholder push-to-talk transcript in progress.' }
|
||||
});
|
||||
|
||||
client.sendJson({ type: 'input_audio.commit', payload: {} });
|
||||
assert.deepEqual(await client.nextMessage(), {
|
||||
type: 'transcript.final',
|
||||
payload: { text: '[mocked final] Placeholder push-to-talk transcript completed from 1 appended chunk.' }
|
||||
});
|
||||
assert.deepEqual(await client.nextMessage(), {
|
||||
type: 'session.state',
|
||||
payload: { value: 'idle' }
|
||||
@@ -359,6 +375,53 @@ test('websocket accepts a placeholder input cycle before a mocked turn on the sa
|
||||
}
|
||||
});
|
||||
|
||||
test('websocket emits deterministic partials for repeated appends and a deterministic final for commit without append', async () => {
|
||||
const server = await startServer();
|
||||
|
||||
try {
|
||||
const client = await connectWebSocket(server.port);
|
||||
await client.nextMessage();
|
||||
await client.nextMessage();
|
||||
|
||||
client.sendJson({ type: 'input_audio.append', payload: { chunk: 'chunk-1' } });
|
||||
assert.deepEqual(await client.nextMessage(), {
|
||||
type: 'session.state',
|
||||
payload: { value: 'listening' }
|
||||
});
|
||||
assert.deepEqual(await client.nextMessage(), {
|
||||
type: 'transcript.partial',
|
||||
payload: { text: '[mocked partial] Placeholder push-to-talk transcript in progress.' }
|
||||
});
|
||||
|
||||
client.sendJson({ type: 'input_audio.append', payload: { chunk: 'chunk-2' } });
|
||||
assert.deepEqual(await client.nextMessage(), {
|
||||
type: 'transcript.partial',
|
||||
payload: { text: '[mocked partial] Placeholder push-to-talk transcript in progress (2 chunks).' }
|
||||
});
|
||||
|
||||
client.sendJson({ type: 'input_audio.commit', payload: {} });
|
||||
assert.deepEqual(await client.nextMessage(), {
|
||||
type: 'transcript.final',
|
||||
payload: { text: '[mocked final] Placeholder push-to-talk transcript completed from 2 appended chunks.' }
|
||||
});
|
||||
assert.deepEqual(await client.nextMessage(), {
|
||||
type: 'session.state',
|
||||
payload: { value: 'idle' }
|
||||
});
|
||||
|
||||
client.sendJson({ type: 'input_audio.commit', payload: {} });
|
||||
assert.deepEqual(await client.nextMessage(), {
|
||||
type: 'transcript.final',
|
||||
payload: { text: '[mocked final] Placeholder push-to-talk transcript completed without appended audio.' }
|
||||
});
|
||||
await assert.rejects(() => client.nextMessage(150), /timed out waiting for websocket message/);
|
||||
|
||||
await client.close();
|
||||
} finally {
|
||||
await server.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('websocket mocked turn emits deterministic transcript and response events in order', async () => {
|
||||
const server = await startServer();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user