- Add internal reuse_last_evidence tool for continuing existing topic without repeated retrieval - Expand OpenAI output capacity to 120s / 5,760,000 bytes and add delivery fairness - Coalesce adjacent user ASR transcript deltas to prevent client control queue overflow - Add server-side OPENAI_REALTIME_SPEED configuration and update style to v4 - Add extensive unit and integration regressions for evidence reuse, capacity, and fairness
72 lines
3.3 KiB
JavaScript
72 lines
3.3 KiB
JavaScript
// Run the actual frontend worklet against a fixed numeric arrival trace.
|
|
// Usage: node tests/support/live_playback_trace.mjs /absolute/frontend/path
|
|
import assert from 'node:assert/strict';
|
|
import { readFileSync } from 'node:fs';
|
|
import { resolve } from 'node:path';
|
|
import vm from 'node:vm';
|
|
|
|
const frontend = process.argv[2];
|
|
assert(frontend, 'Provide the frontend repository path');
|
|
const source = readFileSync(resolve(frontend, 'public/assets/worklets/pcm-playback.worklet.js'), 'utf8');
|
|
const results = [];
|
|
for (const rate of [24000, 44100, 48000]) {
|
|
for (const prebufferMs of [80, 120, 160, 240]) {
|
|
for (const scenario of ['jitter', 'provider_pause']) {
|
|
let Processor;
|
|
const context = vm.createContext({
|
|
sampleRate: rate,
|
|
AudioWorkletProcessor: class {
|
|
constructor() {
|
|
this.messages = [];
|
|
this.port = { postMessage: m => this.messages.push(m) };
|
|
}
|
|
},
|
|
registerProcessor: (_, cls) => { Processor = cls; },
|
|
});
|
|
vm.runInContext(source, context);
|
|
const proc = new Processor();
|
|
proc.prebuffer = Math.floor(rate * prebufferMs / 1000);
|
|
// 250 20-ms frames. Three arrive together every 60 ms with bounded jitter.
|
|
const arrivals = [];
|
|
for (let i = 0; i < 250; i++) {
|
|
const batch = Math.floor(i / 3);
|
|
const at = batch * 60 + (batch % 5 === 0 ? 30 : 0) +
|
|
(scenario === 'provider_pause' && i >= 100 ? 2000 : 0);
|
|
arrivals.push({ at, samples: 480 });
|
|
}
|
|
arrivals.sort((a, b) => a.at - b.at);
|
|
let index = 0, firstConsumedMs = null, underruns = 0, openIdleMs = 0;
|
|
let wasDry = false, sealed = false, peakQueuedSource = 0;
|
|
const quantumMs = 128000 / rate;
|
|
for (let now = 0; now < 12000; now += quantumMs) {
|
|
while (index < arrivals.length && arrivals[index].at <= now) {
|
|
const pcm = new Int16Array(arrivals[index].samples).fill(1000);
|
|
proc.port.onmessage({ data: { type: 'push', pcm: pcm.buffer, sampleRate: 24000, audioRef: 'fixed-trace' } });
|
|
index++;
|
|
}
|
|
if (index === arrivals.length && !sealed) {
|
|
proc.port.onmessage({ data: { type: 'flush', audioRef: 'fixed-trace' } });
|
|
sealed = true;
|
|
}
|
|
peakQueuedSource = Math.max(peakQueuedSource, proc.queuedSource);
|
|
const before = proc.refPlayedOut.get('fixed-trace') ?? 0;
|
|
proc.process([[]], [[new Float32Array(128)]]);
|
|
const consumed = (proc.refPlayedOut.get('fixed-trace') ?? 0) > before;
|
|
if (consumed && firstConsumedMs === null) firstConsumedMs = now;
|
|
const dry = !consumed && firstConsumedMs !== null && !sealed;
|
|
if (dry) openIdleMs += quantumMs;
|
|
if (dry && !wasDry) underruns++;
|
|
wasDry = dry;
|
|
if (sealed && proc.count === 0) break;
|
|
}
|
|
const consumedSamples = proc.refPlayedOut.get('fixed-trace');
|
|
assert.equal(consumedSamples, rate * 5, 'Every admitted sample must drain');
|
|
assert(!proc.messages.some(m => m.type === 'overflow'), 'Two-second source queue must remain bounded');
|
|
assert(peakQueuedSource <= 48000);
|
|
results.push({ scenario, rate, prebufferMs, firstConsumedMs: Math.round(firstConsumedMs),
|
|
underruns, openIdleMs: Math.round(openIdleMs), peakQueuedSource: Math.ceil(peakQueuedSource), consumedSamples });
|
|
}
|
|
}
|
|
}
|
|
console.log(JSON.stringify(results, null, 2));
|