MCPcopy
hub / github.com/mudler/LocalAI / mockAudioTransform

Function mockAudioTransform

core/http/react-ui/e2e/audio-transform.spec.js:15–42  ·  view source on GitHub ↗
(page, filename = 'transformed.wav')

Source from the content-addressed store, hash-verified

13// the page submitted to /audio/transformations. The handler returns a tiny
14// fake WAV blob so the page can render its result waveforms.
15function mockAudioTransform(page, filename = 'transformed.wav') {
16 let resolveSubmit
17 const submitted = new Promise((resolve) => { resolveSubmit = resolve })
18
19 page.route('**/audio/transformations', (route) => {
20 if (route.request().method() !== 'POST') return route.continue()
21 const req = route.request()
22 const body = req.postData() || ''
23 resolveSubmit({
24 contentType: req.headers()['content-type'] || '',
25 bodySize: body.length,
26 // Naive multipart field name extraction so a test can assert the
27 // form-data shape without parsing the multipart body.
28 fields: Array.from(body.matchAll(/name="([^"]+)"/g)).map((m) => m[1]),
29 })
30 const wavHeader = new Uint8Array(44) // 44-byte RIFF/WAVE skeleton
31 route.fulfill({
32 status: 200,
33 headers: {
34 'Content-Type': 'audio/wav',
35 'Content-Disposition': `attachment; filename="${filename}"`,
36 },
37 body: Buffer.from(wavHeader),
38 })
39 })
40
41 return submitted
42}
43
44// Build a tiny in-memory WAV file (44-byte header, 4 silent samples) so
45// Playwright's setInputFiles + the page's audio decoder both have valid

Callers 1

Calls 3

requestMethod · 0.80
fromMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected