Files
client/scripts/audit-voice-timed.mjs
T
omar e6464bc4ed feat: checkpoint account-free client workflows and source-matched UI
Preserve accumulated client implementation since v0.1.4, including local identities, multi-server state, chat, administration, audio and streaming controls. Refine official-source layout, original artwork, responsive composer overflow, settings navigation and chat scroll anchoring.

Current verification: Node suite passes; isolated packaged chat and responsive control smokes pass without device capture. Native core is reused, not rebuilt in this pass. Strict whole-screen visual parity remains incomplete; no 1:1 or cross-platform acceptance claim. Local checkpoint only; no release or push.
2026-11-01 19:43:18 +03:00

79 lines
6.0 KiB
JavaScript

// Disconnected, silent, real Chromium fake-file capture. Never opens a physical microphone.
import { launchApp, root } from './lib/electron-app.mjs';
import { mkdirSync, mkdtempSync, readFileSync, writeFileSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
import assert from 'node:assert/strict';
const args = process.argv.slice(2);
const opt = (key, fallback) => args.includes(`--${key}`) ? args[args.indexOf(`--${key}`) + 1] : fallback;
const seconds = Number(opt('seconds', '190'));
const out = path.resolve(opt('out', 'smoke-out/voice-timed'));
mkdirSync(out, { recursive: true });
const profile = mkdtempSync(path.join(tmpdir(), 'teamspeach-voice-timed-'));
// Preserve the licensed four-second speech fixture, followed by two seconds of silence, repeated by Chromium.
const fixture = readFileSync(path.join(root, 'core/tests/fixtures/speech-librivox-48k.wav'));
let data;
for (let pos = 12; pos + 8 <= fixture.length;) {
const size = fixture.readUInt32LE(pos + 4);
if (fixture.toString('ascii', pos, pos + 4) === 'data') data = fixture.subarray(pos + 8, pos + 8 + size);
pos += 8 + size + (size % 2);
}
assert.ok(data);
const pcm = Buffer.concat([data, Buffer.alloc(48000 * 2 * 2)]);
const wav = Buffer.alloc(44);
wav.write('RIFF'); wav.writeUInt32LE(36 + pcm.length, 4); wav.write('WAVEfmt ', 8); wav.writeUInt32LE(16, 16);
wav.writeUInt16LE(1, 20); wav.writeUInt16LE(1, 22); wav.writeUInt32LE(48000, 24); wav.writeUInt32LE(96000, 28);
wav.writeUInt16LE(2, 32); wav.writeUInt16LE(16, 34); wav.write('data', 36); wav.writeUInt32LE(pcm.length, 40);
const fake = path.join(profile, 'speech-silence.wav'); writeFileSync(fake, Buffer.concat([wav, pcm]));
let app;
const result = { startedAt: new Date().toISOString(), seconds, sourceSamples: data.length / 2, cycleSamples: pcm.length / 2,
scope: 'offscreen disconnected Chromium fake WAV; no physical microphone/server/playback/profile modification', errors: [] };
try {
app = await launchApp({ exe: opt('exe'), profile, args: ['--use-fake-device-for-media-stream', '--use-fake-ui-for-media-stream', `--use-file-for-fake-audio-capture=${fake}`] });
const page = await app.firstWindow();
page.on('pageerror', error => result.errors.push(error.message));
result.runtime = await app.evaluate(() => ({ electron: process.versions.electron, chrome: process.versions.chrome }));
const capture = await page.evaluate(async ({ seconds, stall }) => {
const { AudioEngine } = await import('./js/audio/engine.js');
const { S } = await import('./js/state.js');
const chunks = [], times = [], checkpoints = [], errors = [], arrivals = [], stalls = [];
const engine = new AudioEngine({ onFrame(pcm) { chunks.push(new Uint8Array(pcm)); times.push(performance.now()); }, onError(e) { errors.push(e); } });
engine.setOutputLevelDb(-200);
await engine.init();
await engine.ctx.setSinkId({ type: 'none' });
await engine.startCapture({ echoCancellation: true, noiseSuppression: true, autoGainControl: true });
await engine.capture.ctx.setSinkId({ type: 'none' });
const start = performance.now();
// Observe the real MessagePort independently of production forwarding; the deliberate stall
// models renderer work, not a microphone or network fault. Every raw frame is still measured.
engine.capture.node.port.addEventListener('message', ({ data }) => {
if (data.type === 'frame') arrivals.push({ wallMs: performance.now() - start, contextTime: engine.capture.ctx.currentTime, capturedAt: data.capturedAt ?? null });
});
if (stall) setTimeout(() => {
const began = performance.now();
while (performance.now() - began < 600) { /* bounded adversarial renderer task */ }
stalls.push({ beganMs: began - start, endedMs: performance.now() - start });
}, 5000);
const safeSettings = () => { const { sampleRate, channelCount, echoCancellation, noiseSuppression, autoGainControl, latency } = engine.capture.track.getSettings(); return { sampleRate, channelCount, echoCancellation, noiseSuppression, autoGainControl, latency }; };
for (const at of [0, 30, 90, 180, seconds].filter((v, i, a) => v <= seconds && a.indexOf(v) === i).sort((a,b)=>a-b)) {
await new Promise(resolve => setTimeout(resolve, Math.max(0, start + at * 1000 - performance.now())));
checkpoints.push({ elapsedMs: performance.now() - start, frames: chunks.length, captureTime: engine.capture.ctx.currentTime, playbackTime: engine.ctx.currentTime, settings: safeSettings() });
}
const settings = safeSettings();
engine.stopCapture(); await engine.captureClosing; await engine.releasePlayback();
const joined = new Uint8Array(chunks.length * 1920); chunks.forEach((chunk, i) => joined.set(chunk, i * 1920));
let binary = ''; for (let i = 0; i < joined.length; i += 16384) binary += String.fromCharCode(...joined.subarray(i, i + 16384));
return { pcm: btoa(binary), times, arrivals, stalls, checkpoints, settings, errors, stats: engine.stats, connection: S.conn.state };
}, { seconds, stall: args.includes('--stall') });
writeFileSync(path.join(out, 'capture.pcm'), Buffer.from(capture.pcm, 'base64'));
delete capture.pcm; Object.assign(result, capture);
assert.equal(result.connection, 'disconnected'); assert.deepEqual(result.errors, []);
assert.ok(result.times.length > seconds * 45);
if (args.includes('--verify')) {
assert.equal(result.arrivals.length - result.times.length, result.stats.staleCaptureFrames);
if (args.includes('--stall')) assert.ok(result.stats.staleCaptureFrames >= 15 && result.stats.staleCaptureFrames <= 25);
else assert.equal(result.stats.staleCaptureFrames, 0);
}
} catch (error) { result.failure = error.stack; process.exitCode = 1; }
finally { if (app) await app.close(); rmSync(profile, { recursive: true, force: true }); result.finishedAt = new Date().toISOString(); writeFileSync(path.join(out, 'capture.json'), JSON.stringify(result, null, 2)); console.log(JSON.stringify({ ...result, times: `${result.times?.length} frame timestamps`, arrivals: `${result.arrivals?.length} raw frames` }, null, 2)); }