feat: integrate learning module
Some checks failed
Electron E2E / Electron E2E (macos-latest) (push) Has been cancelled
Electron E2E / Electron E2E (ubuntu-latest) (push) Has been cancelled
Electron E2E / Electron E2E (windows-latest) (push) Has been cancelled

This commit is contained in:
inman
2026-08-16 20:52:16 +08:00
parent 26b52d76e3
commit 01bee3188b
107 changed files with 6318 additions and 12063 deletions

View File

@@ -0,0 +1,32 @@
import { describe, expect, it, vi } from 'vitest';
import { createLearningSpeechClient } from '@electron/services/learning-speech-client';
describe('Learning speech client', () => {
it('keeps authentication in Main and forwards bounded multipart audio', async () => {
const fetchImpl = vi.fn<typeof fetch>().mockResolvedValue(new Response(
JSON.stringify({ text: '什么是变量', model: 'stt' }),
{ status: 200, headers: { 'Content-Type': 'application/json' } },
));
const client = createLearningSpeechClient({
fetchImpl,
getAccessToken: vi.fn().mockResolvedValue('main-owned-token'),
apiBaseUrl: 'https://square.example',
});
await expect(client.transcribe({
audio: new Uint8Array([1, 2, 3]),
fileName: 'voice.webm',
mimeType: 'audio/webm',
language: 'zh-CN',
})).resolves.toEqual({ text: '什么是变量' });
const [url, init] = fetchImpl.mock.calls[0];
expect(url).toBe('https://square.example/api/speech/transcriptions');
expect(init?.headers).toEqual({ Authorization: 'Bearer main-owned-token' });
const form = init?.body as FormData;
expect(form.get('language')).toBe('zh-CN');
const file = form.get('audio') as File;
expect(file.name).toBe('voice.webm');
expect(new Uint8Array(await file.arrayBuffer())).toEqual(new Uint8Array([1, 2, 3]));
});
});