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.
75 lines
3.8 KiB
JavaScript
75 lines
3.8 KiB
JavaScript
'use strict';
|
|
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { EventEmitter } = require('node:events');
|
|
const { ConnectionManager } = require('../app/main/connections');
|
|
|
|
function fixture() {
|
|
const cores = [];
|
|
class Core extends EventEmitter {
|
|
constructor(options) { super(); this.options = options; this.running = false; this.audio = []; this.requests = []; this.stops = 0; }
|
|
start() { this.running = true; this.emit('status', { status: 'ready' }); }
|
|
request(cmd, args) { this.requests.push({ cmd, args }); return Promise.resolve({ ok: true, result: { cmd, args } }); }
|
|
sendAudio(cmd, args) { this.audio.push({ cmd, args }); return true; }
|
|
stop() { this.stops++; return new Promise((resolve) => { this.finishStop = () => { this.running = false; resolve(); }; }); }
|
|
}
|
|
const manager = new ConnectionManager({ resolveBinary: () => ({ path: 'disposable-core' }), dataDir: 'profile', logsDir: 'logs', createCore: (options) => { const core = new Core(options); cores.push(core); return core; } });
|
|
return { manager, cores };
|
|
}
|
|
|
|
test('independent routes, selected microphone only, and identity/session state', async () => {
|
|
const { manager: m, cores } = fixture();
|
|
const a = m.create().connection.id; const b = m.create().connection.id;
|
|
assert.notEqual(a, b);
|
|
assert.notEqual(cores[0].options.connectionDir, cores[1].options.connectionDir);
|
|
assert.equal(cores[0].options.dataDir, cores[1].options.dataDir);
|
|
cores[0].emit('event', { event: 'state', state: 'connected', identity_id: 'identity-a' });
|
|
cores[1].emit('event', { event: 'state', state: 'connected', identity_id: 'identity-b' });
|
|
await m.request(a, 'send_text', { message: 'first' });
|
|
await m.request(b, 'send_text', { message: 'second' });
|
|
assert.equal(cores[0].requests[0].args.message, 'first');
|
|
assert.equal(cores[1].requests[0].args.message, 'second');
|
|
assert.equal(m.get(a).identityId, 'identity-a');
|
|
m.setInput(a); assert.equal(m.sendAudioFrame('one'), true);
|
|
m.setInput(b); m.sendAudioFrame('two', 9);
|
|
assert.deepEqual(cores[0].audio.map((x) => x.cmd), ['audio_frame', 'audio_end']);
|
|
assert.equal(cores[1].audio[0].args.pcm, 'two');
|
|
assert.equal(cores[1].audio[0].args.whisper, 9);
|
|
const beforeReconnect = m.get(b).session;
|
|
cores[1].emit('event', { event: 'state', state: 'connecting' });
|
|
assert.ok(m.get(b).session > beforeReconnect);
|
|
assert.equal(m.sendAudioFrame('during-reconnect'), false);
|
|
cores[1].emit('event', { event: 'state', state: 'connected' });
|
|
const epoch = m.get(b).session;
|
|
cores[1].emit('status', { status: 'failed' });
|
|
assert.ok(m.get(b).session > epoch);
|
|
assert.equal(m.inputId, null); assert.equal(m.sendAudioFrame('late'), false);
|
|
});
|
|
|
|
test('closing IDs never reappear and stopping runtime slots cannot be reused', async () => {
|
|
const { manager: m, cores } = fixture();
|
|
const a = m.create().connection.id;
|
|
const old = m.get(a); const delivered = [];
|
|
m.on('event', (...args) => delivered.push(args));
|
|
let spawned;
|
|
m.once('changed', () => { spawned = m.create().connection; });
|
|
const closing = m.close(a);
|
|
assert.notEqual(spawned.id, a); assert.notEqual(spawned.slot, old.slot);
|
|
cores[0].emit('event', { event: 'snapshot' });
|
|
assert.equal(delivered.length, 0);
|
|
assert.equal((await m.request(a, 'profile_get')).error.code, 'connection_closed');
|
|
cores[0].finishStop(); await closing;
|
|
const third = m.create().connection;
|
|
assert.equal(third.slot, old.slot); assert.notEqual(third.id, a);
|
|
});
|
|
|
|
test('concurrent restart waits for one shutdown and starts one replacement', async () => {
|
|
const { manager: m, cores } = fixture();
|
|
const id = m.create().connection.id;
|
|
const first = m.restart(id); const second = m.restart(id);
|
|
assert.equal(cores[0].stops, 1);
|
|
cores[0].finishStop();
|
|
assert.equal((await first).ok, true); assert.equal((await second).ok, true);
|
|
assert.equal(cores.length, 2);
|
|
});
|