The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(e2e): drive voice note flow through the real composer and player
Steven Enamakel2eaefae40a24
diff --git a/app/test/e2e/specs/chat-voice-note.spec.ts b/app/test/e2e/specs/chat-voice-note.spec.tsindex d0cd4f6a3e..d8fe336a6b 100644--- a/app/test/e2e/specs/chat-voice-note.spec.ts+++ b/app/test/e2e/specs/chat-voice-note.spec.ts@@ -1,131 +1,108 @@// @ts-nocheck-/**- * Chat voice notes - a recorded note and a spoken assistant reply survive a- * reload and stay replayable.- *- * The microphone and the hosted STT/TTS engines are not part of the mock- * backend, so the two audio-producing steps are driven through the same core- * RPCs the composer and the turn runner call:- *- * - `channel_web_voice_note_store` is what the composer calls after a- * recording (user note) and what the turn runner calls with synthesized- * speech (assistant reply, stored under `reply-<request_id>`).- * - `threads_message_append` writes the rows with `extraMetadata.voiceNote`.- *- * What is asserted is the part users see: after a full app reload both rows- * render a voice-note player, the user note offers its transcript, and the- * core still serves the stored audio for playback.- */+/** Full mocked recording -> transcription -> assistant speech -> reload flow. */import { waitForApp } from '../helpers/app-helpers';-import { chatMounted, clickByTitle, getSelectedThreadId } from '../helpers/chat-harness';-import { callOpenhumanRpc } from '../helpers/core-rpc';+import { chatMounted, clickByTitle, getSelectedThreadId, waitForAssistantReplyContaining } from '../helpers/chat-harness';import { clickTestId, textExists, waitForTestId } from '../helpers/element-helpers';import { resetApp } from '../helpers/reset-app';import { navigateViaHash } from '../helpers/shared-flows';-import { startMockServer, stopMockServer } from '../mock-server';+import { setMockBehavior, startMockServer, stopMockServer } from '../mock-server';const USER_ID = 'e2e-chat-voice-note';-const TRANSCRIPT = 'voice-note-canary remind me about the dentist';-const REPLY = 'Sure, I will remind you about the dentist.';-// "abc" - the store only cares that the bytes decode and are non-empty.-const AUDIO_B64 = 'YWJj';+const TRANSCRIPT = 'Please remind me about the dentist';+const REPLY = 'I will remind you about the dentist.';-describe('Chat voice notes', () => {- let threadId: string;+function silentWavBase64() {+ const sampleRate = 8000;+ const samples = new Uint8Array(sampleRate / 2);+ const bytes = new Uint8Array(44 + samples.length);+ const view = new DataView(bytes.buffer);+ const tag = (offset, value) => [...value].forEach((char, index) => (bytes[offset + index] = char.charCodeAt(0)));+ tag(0, 'RIFF'); view.setUint32(4, 36 + samples.length, true); tag(8, 'WAVE');+ tag(12, 'fmt '); view.setUint32(16, 16, true); view.setUint16(20, 1, true);+ view.setUint16(22, 1, true); view.setUint32(24, sampleRate, true);+ view.setUint32(28, sampleRate, true); view.setUint16(32, 1, true);+ view.setUint16(34, 8, true); tag(36, 'data'); view.setUint32(40, samples.length, true);+ bytes.set(samples, 44);+ return Buffer.from(bytes).toString('base64');+}++const AUDIO_B64 = silentWavBase64();- before(async function beforeSuite() {+describe('Chat voice notes', () => {+ before(async function () {this.timeout(90_000);await startMockServer();await waitForApp();await resetApp(USER_ID);+ setMockBehavior('audioTranscriptionText', TRANSCRIPT);+ setMockBehavior('audioSpeechBase64', AUDIO_B64);+ setMockBehavior('audioSpeechMime', 'audio/wav');+ setMockBehavior('audioSpeechVisemes', JSON.stringify([+ { viseme: 'aa', start_ms: 0, end_ms: 180 },+ { viseme: 'PP', start_ms: 180, end_ms: 420 },+ ]));+ setMockBehavior('llmStreamScript', JSON.stringify([{ text: REPLY }, { finish: 'stop' }]));});after(async () => {+ setMockBehavior('audioTranscriptionText', '');+ setMockBehavior('audioSpeechBase64', '');+ setMockBehavior('audioSpeechMime', '');+ setMockBehavior('audioSpeechVisemes', '');+ setMockBehavior('llmStreamScript', '');await stopMockServer();});- it('seeds a user voice note and a spoken assistant reply', async function () {- this.timeout(60_000);+ it('records, sends the transcription, receives voiced reply, reloads, and replays both notes', async function () {+ this.timeout(180_000);await navigateViaHash('/chat');await browser.waitUntil(async () => await chatMounted(), { timeout: 15_000 });expect(await clickByTitle('New thread', 8_000)).toBe(true);- threadId = (await browser.waitUntil(async () => await getSelectedThreadId(), {- timeout: 8_000,- })) as string;+ const threadId = await browser.waitUntil(async () => await getSelectedThreadId(), { timeout: 8_000 });- const userNote = await callOpenhumanRpc('openhuman.channel_web_voice_note_store', {- note_id: 'vn_e2e_user',- audio_base64: AUDIO_B64,- mime: 'audio/webm',- });- expect(userNote.ok).toBe(true);- const replyNote = await callOpenhumanRpc('openhuman.channel_web_voice_note_store', {- note_id: 'reply-e2e-req',- audio_base64: AUDIO_B64,- mime: 'audio/mpeg',- });- expect(replyNote.ok).toBe(true);+ // The browser recorder emits a valid short WAV so both stored user and synthesized+ // assistant audio can be decoded by the real player without a microphone/device.+ await browser.execute(wav => {+ const raw = Uint8Array.from(atob(wav), char => char.charCodeAt(0));+ Object.defineProperty(navigator, 'mediaDevices', { configurable: true, value: {+ getUserMedia: async () => ({ getTracks: () => [{ stop() {} }] }),+ } });+ window.MediaRecorder = class {+ static isTypeSupported() { return true; }+ constructor() { this.state = 'inactive'; this.mimeType = 'audio/wav'; this.listeners = {}; }+ addEventListener(type, fn) { this.listeners[type] = fn; }+ start() { this.state = 'recording'; }+ stop() {+ this.state = 'inactive';+ this.listeners.dataavailable?.({ data: new Blob([raw], { type: 'audio/wav' }) });+ this.listeners.stop?.();+ }+ };+ }, AUDIO_B64);- const now = new Date().toISOString();- const user = await callOpenhumanRpc('openhuman.threads_message_append', {- thread_id: threadId,- message: {- id: 'msg_e2e_voice_user',- content: TRANSCRIPT,- type: 'text',- extraMetadata: {- voiceNote: { noteId: 'vn_e2e_user', mime: 'audio/webm', durationMs: 4000 },- },- sender: 'user',- createdAt: now,- },- });- expect(user.ok).toBe(true);- const agent = await callOpenhumanRpc('openhuman.threads_message_append', {- thread_id: threadId,- message: {- id: 'agent:e2e-req',- content: REPLY,- type: 'text',- extraMetadata: {- scope: 'web_chat_reply',- requestId: 'e2e-req',- voiceNote: { noteId: 'reply-e2e-req', mime: 'audio/mpeg' },- },- sender: 'agent',- createdAt: new Date(Date.now() + 1000).toISOString(),- },- });- expect(agent.ok).toBe(true);- });+ await clickTestId('voice-note-record');+ await waitForTestId('voice-note-recording', 5_000);+ await clickTestId('voice-note-stop');+ await waitForTestId('voice-note-preview', 5_000);+ await clickTestId('voice-note-send');+ await browser.waitUntil(async () => await textExists(TRANSCRIPT), { timeout: 20_000 });+ await waitForAssistantReplyContaining(REPLY, 60_000);+ await browser.waitUntil(async () => (await browser.$$('[data-testid="voice-note-player"]')).length === 2, { timeout: 30_000 });- it('shows both players after a reload, with the transcript under the user note', async function () {- this.timeout(90_000);await browser.refresh();await waitForApp();await navigateViaHash('/chat');await browser.waitUntil(async () => await chatMounted(), { timeout: 20_000 });- await browser.execute(tid => {- window.__OPENHUMAN_STORE__?.dispatch({ type: 'thread/setSelectedThread', payload: tid });- }, threadId);-- await waitForTestId('voice-note-player', 20_000);- const players = await browser.$$('[data-testid="voice-note-player"]');- expect(players.length).toBe(2);-- // The assistant reply keeps its text; the user note shows it as a transcript.+ await browser.execute(tid => window.__OPENHUMAN_STORE__?.dispatch({ type: 'thread/setSelectedThread', payload: tid }), threadId);+ await browser.waitUntil(async () => (await browser.$$('[data-testid="voice-note-player"]')).length === 2, { timeout: 30_000 });expect(await textExists(REPLY)).toBe(true);await clickTestId('voice-note-transcript-toggle');await browser.waitUntil(async () => await textExists(TRANSCRIPT), { timeout: 5_000 });- });- it('plays back from the stored audio and the core still serves it', async function () {- this.timeout(30_000);+ const playButtons = await browser.$$('[data-testid="voice-note-toggle"]');+ expect(playButtons.length).toBe(2);+ await clickTestId('voice-note-toggle');+ await browser.waitUntil(async () => await browser.execute(() => document.querySelector('[data-testid="voice-note-toggle"]')?.getAttribute('aria-label')?.toLowerCase().includes('pause')), { timeout: 5_000 });await clickTestId('voice-note-toggle');- const read = await callOpenhumanRpc('openhuman.channel_web_voice_note_read', {- note_id: 'reply-e2e-req',- });- expect(read.ok).toBe(true);- expect(read.result?.result?.audio_base64 ?? read.result?.audio_base64).toBe(AUDIO_B64);});});