HEL-879 assembly: merge the HEL-897-verified voice frontend (c61d9c9, hel-878-voice-wiring) - original author's six-file visual base byte-preserved with the late-cleanup/interleaved-start fix (761a2331) already independently re-verified 88/88 by the manager; no visual rework, no backend changes on this side
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
// HEL-878 browser check only: a scripted stand-in for the livekit-client UMD global, served by tests/hel878_mock.mjs in
|
||||
// place of the vendored build. Same names the page uses (Room, RoomEvent, Track.Source, ParticipantKind,
|
||||
// createLocalAudioTrack); no WebRTC, no signalling. The microphone is a real MediaStreamTrack from the browser's fake
|
||||
// device (--use-fake-device-for-media-stream), so stopping it can be observed. window.__lk drives her side.
|
||||
(() => {
|
||||
const RoomEvent = { TrackSubscribed: 'trackSubscribed', TrackUnsubscribed: 'trackUnsubscribed', ParticipantConnected: 'participantConnected', ParticipantAttributesChanged: 'participantAttributesChanged', DataReceived: 'dataReceived', Disconnected: 'disconnected', AudioPlaybackStatusChanged: 'audioPlaybackChanged' };
|
||||
const lk = window.__lk = { rooms: [], connects: [], published: [], mics: [], connectDelay: 200 };
|
||||
class Room {
|
||||
constructor() { this.handlers = {}; this.remoteParticipants = new Map(); this.canPlaybackAudio = true; this.state = 'new'; const self = this; this.localParticipant = { tracks: [], async publishTrack(t) { if (self.state !== 'connected') throw new Error('not connected'); self.localParticipant.tracks.push(t); lk.published.push(t); } }; lk.rooms.push(this); }
|
||||
on(e, cb) { (this.handlers[e] ||= []).push(cb); return this; }
|
||||
emit(e, ...a) { (this.handlers[e] || []).forEach(cb => cb(...a)); }
|
||||
async connect(url, token) { lk.connects.push({ url, token }); this.state = 'connecting'; await new Promise(r => setTimeout(r, lk.connectDelay)); if (this.state !== 'connecting') throw new Error('aborted'); this.state = 'connected'; }
|
||||
async disconnect(stop = true) { if (this.state === 'gone') return; this.state = 'gone'; if (stop) this.localParticipant.tracks.forEach(t => t.stop()); this.emit(RoomEvent.Disconnected); }
|
||||
async startAudio() { this.canPlaybackAudio = true; }
|
||||
}
|
||||
const live = () => lk.rooms.filter(r => r.state === 'connected').at(-1);
|
||||
// Her worker joins: an agent participant with a looping tone as her voice track.
|
||||
lk.join = () => {
|
||||
const room = live(); if (!room) return false;
|
||||
const p = { identity: 'agent-AJ_fake', kind: 4, attributes: { 'lk.agent.state': 'listening' } };
|
||||
room.remoteParticipants.set(p.identity, p); room.emit(RoomEvent.ParticipantConnected, p);
|
||||
const ctx = new AudioContext(), osc = ctx.createOscillator(), dest = ctx.createMediaStreamDestination(); osc.connect(dest); osc.start();
|
||||
const mst = dest.stream.getAudioTracks()[0];
|
||||
const track = { kind: 'audio', mediaStreamTrack: mst, els: [], attach() { const el = document.createElement('audio'); el.srcObject = new MediaStream([mst]); el.autoplay = true; this.els.push(el); return el; }, detach() { const e = this.els; this.els = []; return e; }, stop() { mst.stop(); } };
|
||||
room.emit(RoomEvent.TrackSubscribed, track, {}, p);
|
||||
return true;
|
||||
};
|
||||
lk.state = s => { const room = lk.rooms.at(-1), p = [...room.remoteParticipants.values()][0]; if (!p) return false; p.attributes['lk.agent.state'] = s; room.emit(RoomEvent.ParticipantAttributesChanged, { 'lk.agent.state': s }, p); return true; };
|
||||
lk.say = obj => { const room = lk.rooms.at(-1); room.emit(RoomEvent.DataReceived, new TextEncoder().encode(JSON.stringify(obj)), undefined, 0, 'cg.subtitle'); return true; };
|
||||
lk.drop = () => { const room = live(); room.state = 'gone'; room.emit(RoomEvent.Disconnected); return true; };
|
||||
lk.block = () => { const room = live(); room.canPlaybackAudio = false; room.emit(RoomEvent.AudioPlaybackStatusChanged); return true; };
|
||||
async function createLocalAudioTrack(constraints) {
|
||||
const stream = await navigator.mediaDevices.getUserMedia({ audio: constraints || true }), mst = stream.getAudioTracks()[0];
|
||||
lk.mics.push(mst);
|
||||
return { kind: 'audio', mediaStreamTrack: mst, attach() { return document.createElement('audio'); }, detach() { return []; }, stop() { mst.stop(); } };
|
||||
}
|
||||
window.LivekitClient = { Room, RoomEvent, Track: { Source: { Microphone: 'microphone' } }, ParticipantKind: { AGENT: 4 }, createLocalAudioTrack };
|
||||
})();
|
||||
@@ -0,0 +1,86 @@
|
||||
// HEL-878 isolated contract mock for real voice on the approved conversation. Serves web/dist, the persisted-message
|
||||
// contract (as tests/hel875_mock.mjs) and the HEL-877 voice router (src/cybergril/voice/router.py): GET
|
||||
// /api/voice/status, POST /api/voice/session -> 201 grant, DELETE /api/voice/session/{id}. The LiveKit client path is
|
||||
// answered with tests/fake-livekit.js (a scripted stand-in, no WebRTC); the real vendored build stays reachable at
|
||||
// /__real-sdk.js for the API-surface check only. Synthetic data only: no model, no LiveKit, no TTS, no network.
|
||||
// Usage: node tests/hel878_mock.mjs <port>. Control GETs: /__voice?configured=&tts=, /__refuse/<code|0>,
|
||||
// /__voice-turn?stage=user|reply|cancel&text=, /__cut, /__sessions, /__log, /__rows.
|
||||
import { createServer } from 'node:http';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { extname, join, normalize } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const dist = fileURLToPath(new URL('../dist/', import.meta.url)), fake = fileURLToPath(new URL('./fake-livekit.js', import.meta.url));
|
||||
const port = Number(process.argv[2] || 8878);
|
||||
const T0 = Date.UTC(2026, 9, 26, 12, 0);
|
||||
const identity = { id: '1', name: '栖', birth: '2000-03-14', hour: '子', relation: '朋友', nickname: '', boundary: '', color: { pillars: { year: '庚辰', month: '己卯', day: '丙午', hour: '戊子' }, traits: '合成测试档案' } };
|
||||
// /__hold-delete?id=<session> keeps that DELETE unanswered (a slow server); /__hold-delete with no id answers them all.
|
||||
const epoch = 3, log = [], rows = [], sessions = new Map(), held = new Map();
|
||||
let voice = { configured: true, tts: true }, refuse = 0, made = 0, voiceTurn = 0, textStream = null;
|
||||
const add = row => { const id = rows.length + 1; rows.push({ id, ts: T0 + id * 60e3, status: 'sent', lifeIds: [], ...row }); return id; };
|
||||
add({ role: 'user', text: '下雨天的时候,你会想听什么?', turn_id: '00000000-0000-4000-8000-000000000001' });
|
||||
add({ role: 'companion', text: '会想把窗开一条缝,听雨落在铁皮檐上。你呢,今天累不累?', turn_id: '00000000-0000-4000-8000-000000000001' });
|
||||
const dto = r => ({ id: r.id, ts: r.ts, role: r.role, text: r.text, turn_id: r.turn_id, status: r.status, lifeIds: r.lifeIds, ...(r.proactive ? { proactive: true } : {}) });
|
||||
const send = (res, status, body, type = 'application/json; charset=utf-8') => { res.writeHead(status, { 'Content-Type': type, 'Cache-Control': 'no-store' }); res.end(typeof body === 'string' || Buffer.isBuffer(body) ? body : JSON.stringify(body)); };
|
||||
const sleep = ms => new Promise(r => setTimeout(r, ms));
|
||||
const REFUSALS = { 503: '她的声音服务这会儿不在,稍后再试试。', 409: '还没有创建真实伴侣,语音也不会开始。' };
|
||||
|
||||
createServer(async (req, res) => {
|
||||
const url = new URL(req.url, 'http://x'), p = url.pathname;
|
||||
if (!p.startsWith('/__') && !p.startsWith('/assets/') && !p.startsWith('/vendor/')) log.push(`${req.method} ${p}${url.search}`);
|
||||
if (p === '/__log') return send(res, 200, log.splice(0));
|
||||
if (p === '/__rows') return send(res, 200, rows.map(dto));
|
||||
if (p === '/__sessions') return send(res, 200, { open: [...sessions.keys()], made });
|
||||
if (p === '/__voice') { voice = { configured: url.searchParams.get('configured') !== '0', tts: url.searchParams.get('tts') !== '0' }; return send(res, 200, voice); }
|
||||
if (p.startsWith('/__refuse/')) { refuse = Number(p.slice(10)); return send(res, 200, { refuse }); }
|
||||
// What the worker's /api/chat call leaves in the record, one stage at a time (the browser never posts it).
|
||||
if (p === '/__voice-turn') {
|
||||
const stage = url.searchParams.get('stage'), text = url.searchParams.get('text') || '';
|
||||
if (stage === 'user') { voiceTurn++; add({ role: 'user', text, turn_id: `voice-${voiceTurn}`, status: 'pending' }); }
|
||||
if (stage === 'reply') { add({ role: 'companion', text, turn_id: `voice-${voiceTurn}` }); rows.forEach(r => { if (r.turn_id === `voice-${voiceTurn}`) r.status = 'sent'; }); }
|
||||
if (stage === 'cancel') rows.forEach(r => { if (r.turn_id === `voice-${voiceTurn}`) r.status = 'cancelled'; });
|
||||
return send(res, 200, { turn: voiceTurn });
|
||||
}
|
||||
// A voice turn took the server's turn gate: the text stream in flight ends without a final; its row is cancelled.
|
||||
if (p === '/__cut') { const s = textStream; textStream = null; if (s) { rows.forEach(r => { if (r.turn_id === s.turn_id && r.role === 'user') r.status = 'cancelled'; }); s.cut = true; s.res.end(); } return send(res, 200, { cut: !!s }); }
|
||||
if (p === '/__real-sdk.js') return send(res, 200, await readFile(join(dist, 'vendor/livekit-client-2.22.4.umd.min.js')), 'text/javascript');
|
||||
if (p.startsWith('/vendor/livekit-client')) return send(res, 200, await readFile(fake), 'text/javascript');
|
||||
if (p === '/api/health') return send(res, 200, { ok: true, version: 'R5-candidate', epoch, llm: { ok: true, model: 'mock' }, backend: { life: true, persona: true, receipt: true, web_connected: true }, life_runtime: { state: 'running', timezone: 'Asia/Shanghai', budget_warning: false, budget_stopped: false, last: null }, capabilities: { text: true, proactive: true, voice: false, memory: true } });
|
||||
if (p === '/api/companion') return send(res, 200, identity);
|
||||
if (p === '/api/messages') {
|
||||
const limit = Math.min(200, Number(url.searchParams.get('limit') || 200)), before = Number(url.searchParams.get('before') || Number.MAX_SAFE_INTEGER);
|
||||
const desc = rows.filter(r => r.id < before).sort((a, b) => b.id - a.id).slice(0, limit + 1), more = desc.length > limit, page = desc.slice(0, limit);
|
||||
return send(res, 200, { messages: [...page].reverse().map(dto), next_before: more ? page[page.length - 1].id : null, epoch });
|
||||
}
|
||||
if (p === '/api/persona') return send(res, 200, { state: 'ready', interpretation: null, seeds: [], growth: [] });
|
||||
if (p === '/api/life') return send(res, 200, { events: [], next_before: null, epoch });
|
||||
if (p === '/api/memories') return send(res, 200, { memories: [], next_before: null, epoch });
|
||||
if (p === '/api/voice/status') return send(res, 200, voice.configured ? { configured: true, tts_ok: voice.tts, agent_name: 'cybergril-voice-agent', voice: false, livekit_url: 'wss://192.168.200.12:7880' } : { configured: false, tts_ok: false, agent_name: null, voice: false });
|
||||
if (p === '/api/voice/session' && req.method === 'POST') {
|
||||
if (!voice.configured) return send(res, 503, { detail: '语音还没有在这台服务上配置,不能假装能通话。' });
|
||||
if (refuse) return send(res, refuse, { detail: REFUSALS[refuse] || '通话服务暂时连不上,稍后再试试。' });
|
||||
await sleep(120);
|
||||
const id = `sess-${++made}`; sessions.set(id, { room: `cg-voice-${made}` });
|
||||
return send(res, 201, { url: 'wss://lk.invalid', token: `token-${id}`, room: `cg-voice-${made}`, session_id: id, agent_name: 'cybergril-voice-agent', epoch, expires_at: Date.now() + 2 * 3600e3 });
|
||||
}
|
||||
if (p === '/__hold-delete') { const id = url.searchParams.get('id'); if (id) { let open; held.set(id, { promise: new Promise(r => { open = r; }), open }); } else { held.forEach(h => h.open()); held.clear(); } return send(res, 200, { held: [...held.keys()] }); }
|
||||
if (p.startsWith('/api/voice/session/') && req.method === 'DELETE') { const id = decodeURIComponent(p.slice(19)); if (held.has(id)) await held.get(id).promise; return sessions.delete(id) ? send(res, 200, { ended: true }) : send(res, 404, { detail: '这次通话已经不在了。' }); }
|
||||
if (p === '/api/chat' && req.method === 'POST') {
|
||||
let body = ''; for await (const chunk of req) body += chunk;
|
||||
const { text: said, turn_id } = JSON.parse(body), reply = '我在。今天的雨停了没有?要是还在下,就慢点回家。';
|
||||
add({ role: 'user', text: said, turn_id, status: 'pending' });
|
||||
res.writeHead(200, { 'Content-Type': 'text/event-stream' });
|
||||
const stream = { res, turn_id, cut: false }; textStream = stream;
|
||||
for (const part of reply.match(/.{1,4}/gu)) { if (stream.cut) return; res.write(`data: ${JSON.stringify({ t: 'chat.delta', epoch, turn_id, delta: part })}\n\n`); await sleep(400); }
|
||||
if (stream.cut) return;
|
||||
textStream = null;
|
||||
add({ role: 'companion', text: reply, turn_id }); rows.forEach(r => { if (r.turn_id === turn_id) r.status = 'sent'; });
|
||||
res.end(`data: ${JSON.stringify({ t: 'chat.final', epoch, turn_id, utterance: { text: reply, speech_tags: [] }, receipt: null })}\n\n`);
|
||||
return;
|
||||
}
|
||||
if (p.startsWith('/api/')) return send(res, 404, { detail: 'Not Found' });
|
||||
const file = normalize(join(dist, p === '/' ? 'index.html' : p));
|
||||
if (!file.startsWith(normalize(dist))) return send(res, 403, 'no', 'text/plain');
|
||||
try { send(res, 200, await readFile(file), { '.js': 'text/javascript', '.css': 'text/css', '.html': 'text/html; charset=utf-8', '.svg': 'image/svg+xml', '.png': 'image/png', '.jpg': 'image/jpeg', '.webp': 'image/webp' }[extname(file)] || 'application/octet-stream'); }
|
||||
catch { send(res, 200, await readFile(join(dist, 'index.html')), 'text/html; charset=utf-8'); }
|
||||
}).listen(port, '127.0.0.1', () => console.log(`hel878 mock on ${port}`));
|
||||
@@ -0,0 +1,258 @@
|
||||
// HEL-878 browser check: drives headless Edge over CDP against tests/hel878_mock.mjs (real voice on the approved
|
||||
// conversation, with tests/fake-livekit.js in place of the LiveKit client and Chromium's fake audio device in place of
|
||||
// a microphone). Usage: node tests/hel878_shots.mjs <edge.exe> <outDir> [port]. One PASS/FAIL line per check.
|
||||
import { spawn } from 'node:child_process';
|
||||
import { mkdirSync, writeFileSync, rmSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { tmpdir } from 'node:os';
|
||||
|
||||
const [edge, out, portArg] = process.argv.slice(2);
|
||||
const port = Number(portArg || 8878), base = `http://127.0.0.1:${port}`, cdpPort = 9478;
|
||||
mkdirSync(out, { recursive: true });
|
||||
const profile = join(tmpdir(), `hel878-edge-${Date.now()}`);
|
||||
const browser = spawn(edge, ['--headless=new', `--remote-debugging-port=${cdpPort}`, `--user-data-dir=${profile}`, '--no-first-run', '--hide-scrollbars', '--force-color-profile=srgb', '--use-fake-device-for-media-stream', '--use-fake-ui-for-media-stream', '--autoplay-policy=no-user-gesture-required', 'about:blank'], { stdio: 'ignore' });
|
||||
const sleep = ms => new Promise(r => setTimeout(r, ms));
|
||||
let targets;
|
||||
for (let i = 0; i < 60 && !targets; i++) { try { targets = await (await fetch(`http://127.0.0.1:${cdpPort}/json`)).json(); } catch { await sleep(250); } }
|
||||
const ws = new WebSocket(targets.find(t => t.type === 'page').webSocketDebuggerUrl);
|
||||
await new Promise(r => ws.addEventListener('open', r, { once: true }));
|
||||
let seq = 0; const waiting = new Map();
|
||||
ws.addEventListener('message', ({ data }) => { const m = JSON.parse(data); if (m.id && waiting.has(m.id)) { const { ok, ko } = waiting.get(m.id); waiting.delete(m.id); m.error ? ko(new Error(m.error.message)) : ok(m.result); } });
|
||||
const cdp = (method, params = {}) => new Promise((ok, ko) => { const id = ++seq; waiting.set(id, { ok, ko }); ws.send(JSON.stringify({ id, method, params })); });
|
||||
const js = async expr => { const r = await cdp('Runtime.evaluate', { expression: expr, returnByValue: true, awaitPromise: true }); if (r.exceptionDetails) throw new Error(r.exceptionDetails.exception?.description || 'js error'); return r.result.value; };
|
||||
const results = [];
|
||||
const check = (name, ok, detail = '') => { results.push(ok); console.log(`${ok ? 'PASS' : 'FAIL'} ${name}${detail ? ` — ${detail}` : ''}`); };
|
||||
const ctl = async path => (await fetch(`${base}${path}`)).json();
|
||||
const shot = async name => { const { data } = await cdp('Page.captureScreenshot', { format: 'png' }); writeFileSync(join(out, `${name}.png`), Buffer.from(data, 'base64')); };
|
||||
const click = async (selector, text = '') => js(`(() => { const el = [...document.querySelectorAll(${JSON.stringify(selector)})].find(e => e.offsetParent !== null && e.textContent.includes(${JSON.stringify(text)})); if (!el) return false; el.click(); return true; })()`);
|
||||
const text = sel => js(`[...document.querySelectorAll(${JSON.stringify(sel)})].map(e => e.innerText).join('\\n')`);
|
||||
const exists = sel => js(`!!document.querySelector(${JSON.stringify(sel)})`);
|
||||
const said = () => js(`document.querySelector('.conversation .sr')?.textContent || ''`);
|
||||
const status = () => js(`document.querySelector('.talk-status')?.innerText || ''`);
|
||||
const row = () => js(`document.querySelector('.voice-row.real')?.innerText || ''`);
|
||||
const phase = () => js(`document.querySelector('.voice-row.real')?.dataset.phase || 'off'`);
|
||||
const lk = expr => js(`window.__lk ? (${expr}) : null`);
|
||||
const type = t => js(`(() => { const el = document.querySelector('textarea'); const set = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value').set; set.call(el, ${JSON.stringify(t)}); el.dispatchEvent(new Event('input', { bubbles: true })); return true; })()`);
|
||||
const until = async (fn, ms = 4000) => { const end = Date.now() + ms; while (Date.now() < end) { if (await fn()) return true; await sleep(100); } return false; };
|
||||
const views = { desktop: { width: 1440, height: 900, deviceScaleFactor: 1, mobile: false }, phone: { width: 390, height: 844, deviceScaleFactor: 2, mobile: true } };
|
||||
async function view(v) { await cdp('Emulation.setDeviceMetricsOverride', views[v]); await cdp('Emulation.setTouchEmulationEnabled', { enabled: views[v].mobile, maxTouchPoints: 5 }); }
|
||||
async function boot(theme) {
|
||||
await cdp('Page.navigate', { url: `${base}/` }); await sleep(500);
|
||||
await js(`localStorage.setItem('cg.theme', ${JSON.stringify(theme)}); sessionStorage.clear(); true`);
|
||||
await cdp('Page.navigate', { url: `${base}/` }); await sleep(1600);
|
||||
}
|
||||
async function frames(name, ms) { const list = []; const end = Date.now() + ms; while (Date.now() < end) { const { data } = await cdp('Page.captureScreenshot', { format: 'jpeg', quality: 70 }); list.push(data); } list.forEach((d, i) => writeFileSync(join(out, `${name}-${String(i).padStart(2, '0')}.jpg`), Buffer.from(d, 'base64'))); return list.length; }
|
||||
// Every microphone request is counted (the fake device still answers it); a test can make the next one refuse.
|
||||
await cdp('Page.enable'); await cdp('Runtime.enable'); await cdp('Network.enable');
|
||||
await cdp('Page.addScriptToEvaluateOnNewDocument', { source: `window.__asked = 0; window.__refuseMic = ''; try { const md = navigator.mediaDevices, real = md.getUserMedia.bind(md); md.getUserMedia = c => { window.__asked++; if (window.__refuseMic) return Promise.reject(new DOMException('refused', window.__refuseMic)); return real(c); }; } catch {}` });
|
||||
const micsLive = () => lk(`__lk.mics.filter(t => t.readyState === 'live').length`);
|
||||
const herAudio = () => js(`document.querySelectorAll('[data-voice="her"] audio').length`);
|
||||
const calls = async () => (await ctl('/__log'));
|
||||
async function startVoice() {
|
||||
await click('.voice-button'); await until(() => exists('.modal.open'));
|
||||
await click('.modal.open .btn-primary', '开始语音');
|
||||
await until(async () => (await phase()) === 'joining');
|
||||
await until(async () => (await lk('__lk.rooms.at(-1)?.state')) === 'connected');
|
||||
await lk('__lk.join()'); await sleep(200);
|
||||
}
|
||||
const cleanEnd = async label => {
|
||||
await sleep(400);
|
||||
const s = await ctl('/__sessions'), mics = await micsLive(), audio = await herAudio(), holder = await exists('[data-voice="her"]');
|
||||
check(`${label}: microphone stopped, her audio and room gone, server room deleted`, mics === 0 && audio === 0 && !holder && s.open.length === 0 && (await phase()) === 'off', `mics=${mics} audio=${audio} holder=${holder} open=${s.open.length}`);
|
||||
};
|
||||
|
||||
// ── 1. Arriving at the conversation: one honest status read; no room, no microphone, no client download. ──
|
||||
await view('desktop'); await boot('moon'); await calls();
|
||||
await click('.nav-item', '交谈'); await sleep(1400);
|
||||
let log = await calls();
|
||||
check('status read on arrival only: no session, no microphone, no LiveKit client', log.filter(l => l.includes('/api/voice')).join() === 'GET /api/voice/status' && await js('window.__asked') === 0 && await js('!window.LivekitClient'), log.filter(l => l.includes('voice')).join(' | '));
|
||||
check('voice button offers to start, honestly labelled', await js(`document.querySelector('.voice-button').getAttribute('aria-label')`) === '开始语音');
|
||||
await shot('01-moon-desktop-talk-voice-off');
|
||||
|
||||
// ── 2. Not configured / TTS down: the button says so and nothing starts. ──
|
||||
await ctl('/__voice?configured=0'); await boot('moon'); await click('.nav-item', '交谈'); await sleep(1400); await calls();
|
||||
await click('.voice-button'); await sleep(500);
|
||||
check('not configured: refusal in her own words, no dialog, no session, no microphone', (await status()).includes('语音还没有在这台服务上配置') && !(await exists('.modal.open')) && !(await calls()).some(l => l.startsWith('POST')) && await js('window.__asked') === 0 && await exists('.voice-button.denied'), await status());
|
||||
await shot('02-moon-desktop-voice-not-configured');
|
||||
await ctl('/__voice?configured=1&tts=0'); await click('.voice-button'); await sleep(500);
|
||||
check('TTS down: says her voice service is away', (await status()).includes('她的声音服务这会儿不在'), await status());
|
||||
await ctl('/__voice?configured=1&tts=1');
|
||||
|
||||
// ── 3. The ask: what happens, where the sound goes, that it is not yet real-device accepted. Cancel asks nothing. ──
|
||||
await click('.voice-button'); await until(() => exists('.modal.open'));
|
||||
const ask = await text('.modal.open');
|
||||
check('the dialog explains microphone, destination, same memory, how to stop, and the unverified path', ask.includes('麦克风') && ask.includes('这台服务器') && ask.includes('同一份记忆') && ask.includes('立即关闭') && ask.includes('还没有经过真机验收'), ask.replace(/\n/g, ' '));
|
||||
await shot('03-moon-desktop-voice-ask');
|
||||
await click('.modal.open .btn-ghost', '取消'); await sleep(300);
|
||||
check('cancel: no microphone request, no session', await js('window.__asked') === 0 && (await ctl('/__sessions')).made === 0);
|
||||
|
||||
// ── 4. Start: opening → waiting for her → listening. ──
|
||||
await click('.voice-button'); await until(() => exists('.modal.open')); await calls();
|
||||
await click('.modal.open .btn-primary', '开始语音');
|
||||
await until(async () => (await phase()) === 'joining');
|
||||
await shot('04-moon-desktop-voice-joining');
|
||||
check('waiting for her is shown as waiting, not as connected', (await row()).includes('在等栖接起') && (await text('.topbar .state')).includes('未经真机验收'), await row());
|
||||
await until(async () => (await lk('__lk.rooms.at(-1)?.state')) === 'connected');
|
||||
log = await calls();
|
||||
check('one session opened with a server token; one microphone; mic published to that room', log.filter(l => l === 'POST /api/voice/session').length === 1 && (await lk('__lk.connects.at(-1).token')).startsWith('token-sess-') && await js('window.__asked') === 1 && await lk('__lk.published.length') === 1);
|
||||
await lk('__lk.join()'); await sleep(300);
|
||||
check('her worker joined: listening, wave in your colour, her audio attached', (await phase()) === 'listening' && (await row()).includes('在听你说') && await herAudio() === 1, await row());
|
||||
await frames('m1-voice-in', 700);
|
||||
await shot('05-moon-desktop-voice-listening');
|
||||
|
||||
// ── 5. A voice turn: your draft, the record row, her thinking and speaking, then her words on the stage. ──
|
||||
await lk(`__lk.say({ kind: 'interim', role: 'user', text: '今天下班的路上' })`); await sleep(200);
|
||||
check('interim words show as a draft line beside the state', (await row()).includes('今天下班的路上'));
|
||||
await shot('06-moon-desktop-voice-heard');
|
||||
await ctl('/__voice-turn?stage=user&text=' + encodeURIComponent('今天下班的路上看到一只猫'));
|
||||
await lk(`__lk.say({ kind: 'user_final', role: 'user', text: '今天下班的路上看到一只猫' })`); await lk(`__lk.state('thinking')`);
|
||||
await until(async () => (await said()).includes('看到一只猫'));
|
||||
check('your spoken words enter the stage from the server record (not from the subtitle)', (await said()).includes('看到一只猫') && (await phase()) === 'thinking', await said());
|
||||
await shot('07-moon-desktop-voice-thinking');
|
||||
await lk(`__lk.state('speaking')`); await sleep(250);
|
||||
check('speaking: her name, and that you can cut in by speaking', (await row()).includes('栖在说') && (await row()).includes('开口就能打断'));
|
||||
await frames('m2-voice-speaking', 900);
|
||||
await shot('08-moon-desktop-voice-speaking');
|
||||
await ctl('/__voice-turn?stage=reply&text=' + encodeURIComponent('是橘色的那只吗?它最近总在桥下晒太阳。'));
|
||||
await lk(`__lk.say({ kind: 'assistant_final', role: 'assistant', text: '是橘色的那只吗?它最近总在桥下晒太阳。' })`); await lk(`__lk.state('listening')`);
|
||||
await until(async () => (await said()).includes('晒太阳'), 6000);
|
||||
check('her spoken answer reaches the stage once it is in the record', (await said()).includes('晒太阳'), await said());
|
||||
await shot('09-moon-desktop-voice-reply-on-stage');
|
||||
await click('.log-btn'); await sleep(700);
|
||||
const rec = await text('.log-panel .scroll');
|
||||
check('the record holds the voice turn once, same conversation as text', rec.split('看到一只猫').length === 2 && rec.split('晒太阳').length === 2 && rec.includes('下雨天'));
|
||||
await shot('10-moon-desktop-voice-record');
|
||||
await click('.log-panel .btn-round'); await sleep(400);
|
||||
|
||||
// ── 6. φ: her failure line is heard and shown, never recorded. ──
|
||||
await lk(`__lk.say({ kind: 'error', role: 'assistant', text: '我刚刚没接上话,你再说一遍好吗?' })`); await sleep(400);
|
||||
check('φ line shown as heard, marked not recorded; not in the record', (await row()).includes('没接上话') && (await row()).includes('未记入聊天') && !(await ctl('/__rows')).some(r => r.text.includes('没接上话')));
|
||||
await shot('11-moon-desktop-voice-phi');
|
||||
|
||||
// ── 7. Typing over her spoken answer: what is left of it goes silent until she listens again. ──
|
||||
await lk(`__lk.state('speaking')`); await sleep(150);
|
||||
await type('等等,我先打字说'); await js(`document.querySelector('.send').click(), true`); await sleep(300);
|
||||
check('text over voice: her remaining audio is muted', await js(`[...document.querySelectorAll('[data-voice="her"] audio')].every(a => a.muted)`));
|
||||
await lk(`__lk.state('listening')`); await sleep(150);
|
||||
check('…and unmuted once she is listening again', await js(`[...document.querySelectorAll('[data-voice="her"] audio')].every(a => !a.muted)`));
|
||||
await until(async () => !(await exists('.reader-bar .stop')), 8000);
|
||||
|
||||
// ── 8. Speaking over a text reply: the text turn is cut (not "failed"), your words stay as said. ──
|
||||
await type('再给我讲讲那只猫'); await js(`document.querySelector('.send').click(), true`); await sleep(1300);
|
||||
check('text reply streaming', await exists('.reader-bar .stop'));
|
||||
await ctl('/__cut'); await ctl('/__voice-turn?stage=user&text=' + encodeURIComponent('算了先不说了'));
|
||||
await lk(`__lk.say({ kind: 'user_final', role: 'user', text: '算了先不说了' })`); await sleep(1500);
|
||||
const cutStatus = await status();
|
||||
check('voice over text: no failure notice, no retry, draft not refilled', !cutStatus.includes('连接中断') && !(await exists('.talk-status .retry')) && await js(`document.querySelector('textarea').value`) === '', cutStatus);
|
||||
await click('.log-btn'); await sleep(700);
|
||||
const cutRec = await text('.log-panel .scroll');
|
||||
check('…the cut text turn is marked cancelled in the record; the voice words are there once', cutRec.includes('已取消') && cutRec.split('算了先不说了').length === 2, cutRec.slice(-200).replace(/\n/g, ' '));
|
||||
await click('.log-panel .btn-round'); await sleep(300);
|
||||
|
||||
// ── 9. Autoplay held back: a tap lets her voice out. ──
|
||||
await lk('__lk.block()'); await sleep(200);
|
||||
check('blocked audio offers a tap', (await row()).includes('点一下听栖的声音'));
|
||||
await shot('12-moon-desktop-voice-audio-blocked');
|
||||
await click('.voice-row.real button', '点一下'); await sleep(200);
|
||||
check('…and the offer goes away after the tap', !(await row()).includes('点一下'));
|
||||
|
||||
// ── 10. 结束语音: everything stops at once; late events from the old room change nothing. ──
|
||||
await calls();
|
||||
await click('.voice-row.real .voice-end');
|
||||
await cleanEnd('结束语音');
|
||||
check('ended: says the microphone is closed; DELETE sent', (await status()).includes('麦克风已关闭') && (await calls()).some(l => l.startsWith('DELETE /api/voice/session/')), await status());
|
||||
await shot('13-moon-desktop-voice-ended');
|
||||
await lk(`__lk.state('speaking')`); await lk(`__lk.say({ kind: 'user_final', role: 'user', text: '幽灵' })`); await sleep(500);
|
||||
check('late events after the end do not revive anything', (await phase()) === 'off' && !(await exists('.voice-row.real')) && !(await calls()).some(l => l.startsWith('POST')));
|
||||
|
||||
// ── 11. Microphone permission refused: nothing opened. ──
|
||||
await js(`window.__refuseMic = 'NotAllowedError', true`); await calls();
|
||||
await click('.voice-button'); await until(() => exists('.modal.open')); await click('.modal.open .btn-primary', '开始语音'); await sleep(800);
|
||||
check('permission refused: told plainly, no session opened, text still there', (await status()).includes('没有拿到麦克风权限') && !(await calls()).some(l => l.startsWith('POST')) && await exists('textarea'), await status());
|
||||
await shot('14-moon-desktop-voice-denied');
|
||||
await js(`window.__refuseMic = '', true`);
|
||||
|
||||
// ── 12. Permission revoked mid-call / room dropped / server refusal. ──
|
||||
await startVoice();
|
||||
await lk(`(__lk.mics.at(-1).dispatchEvent(new Event('ended')), true)`);
|
||||
await sleep(300);
|
||||
check('microphone revoked mid-call: call ends, said so', (await status()).includes('麦克风被关掉了'), await status());
|
||||
await cleanEnd('revoked');
|
||||
await startVoice(); await lk('__lk.drop()');
|
||||
await sleep(300);
|
||||
check('room dropped: call ends, said so', (await status()).includes('通话断开了'), await status());
|
||||
await cleanEnd('dropped');
|
||||
// HEL-897: the dropped call's DELETE answers only after a new call is up; the late answer may not touch the new call.
|
||||
await startVoice();
|
||||
const firstSession = (await ctl('/__sessions')).open.at(-1);
|
||||
await ctl(`/__hold-delete?id=${firstSession}`); await lk('__lk.drop()'); await sleep(300);
|
||||
check('slow DELETE: dropped call says so and its microphone stops before the server answers', (await status()).includes('通话断开了') && await micsLive() === 0 && (await ctl('/__sessions')).open.includes(firstSession), await status());
|
||||
await startVoice();
|
||||
const secondSession = (await ctl('/__sessions')).open.find(s => s !== firstSession);
|
||||
check('…a new call is up meanwhile: listening', (await phase()) === 'listening' && await micsLive() === 1);
|
||||
await ctl('/__hold-delete'); await sleep(800);
|
||||
const lateOpen = (await ctl('/__sessions')).open;
|
||||
check('…the old DELETE answers late: the new call stays listening, no old notice, one live microphone, her audio, only the new room open', (await phase()) === 'listening' && !(await status()).includes('通话断开了') && await micsLive() === 1 && await herAudio() === 1 && lateOpen.length === 1 && lateOpen[0] === secondSession, `phase=${await phase()} status=${await status()} open=${lateOpen.join()}`);
|
||||
await shot('12b-moon-desktop-voice-new-call-after-late-delete');
|
||||
await click('.voice-row.real .voice-end'); await cleanEnd('new call after the late old DELETE');
|
||||
await ctl('/__refuse/503'); await click('.voice-button'); await until(() => exists('.modal.open')); await click('.modal.open .btn-primary', '开始语音'); await sleep(900);
|
||||
check('server refusal shows its detail; microphone released', (await status()).includes('她的声音服务这会儿不在') && await micsLive() === 0, await status());
|
||||
await ctl('/__refuse/0');
|
||||
|
||||
// ── 13. Repeated on/off: one call at most, nothing left behind. ──
|
||||
await click('.voice-button'); await until(() => exists('.modal.open')); await click('.modal.open .btn-primary', '开始语音'); await sleep(60);
|
||||
await click('.voice-row.real .voice-end'); await sleep(40);
|
||||
await click('.voice-button'); await until(() => exists('.modal.open')); await click('.modal.open .btn-primary', '开始语音');
|
||||
await until(async () => (await lk('__lk.rooms.at(-1)?.state')) === 'connected'); await sleep(600);
|
||||
const sess = await ctl('/__sessions');
|
||||
check('rapid off/on: exactly one open session and one live microphone', sess.open.length === 1 && await micsLive() === 1, JSON.stringify(sess));
|
||||
await click('.voice-row.real .voice-end'); await cleanEnd('rapid toggle');
|
||||
|
||||
// ── 14. Leaving: nav, Esc, 结束交谈, page unload, network loss — each ends the call. ──
|
||||
await startVoice(); await click('.nav-item', '此刻'); await cleanEnd('nav away');
|
||||
await click('.nav-item', '交谈'); await sleep(1300); await startVoice();
|
||||
await js(`document.body.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true })), true`); await cleanEnd('Esc');
|
||||
await click('.nav-item', '交谈'); await sleep(1300); await startVoice();
|
||||
await click('.end-talk'); await cleanEnd('结束交谈');
|
||||
await click('.nav-item', '交谈'); await sleep(1300); await startVoice();
|
||||
await cdp('Network.emulateNetworkConditions', { offline: true, latency: 0, downloadThroughput: -1, uploadThroughput: -1 }); await sleep(500);
|
||||
check('network lost: call ends with its own words', (await status()).includes('网络断开了'), await status());
|
||||
const offMics = await micsLive(), offAudio = await herAudio(), offOpen = (await ctl('/__sessions')).open.length;
|
||||
check('network lost: microphone and her audio stop at once; the server room is owed, not pretended deleted', offMics === 0 && offAudio === 0 && offOpen === 1 && (await js(`localStorage.getItem('cg.voice.owed')`) || '').includes('sess-'), `mics=${offMics} audio=${offAudio} open=${offOpen}`);
|
||||
await cdp('Network.emulateNetworkConditions', { offline: false, latency: 0, downloadThroughput: -1, uploadThroughput: -1 });
|
||||
await cleanEnd('offline, after the network is back');
|
||||
check('…the owed DELETE is sent once back online and forgotten', !(await js(`localStorage.getItem('cg.voice.owed')`)));
|
||||
await startVoice(); await calls();
|
||||
await cdp('Page.navigate', { url: 'about:blank' }); await sleep(800);
|
||||
log = await calls();
|
||||
check('page unload: the server room is deleted (keepalive)', log.some(l => l.startsWith('DELETE /api/voice/session/')) && (await ctl('/__sessions')).open.length === 0, log.join(' | '));
|
||||
|
||||
// ── 15. Phone and the fog theme: the same line, the same states. ──
|
||||
for (const [theme, v] of [['fog', 'desktop'], ['moon', 'phone'], ['fog', 'phone']]) {
|
||||
await view(v); await boot(theme); await click('.nav-item', '交谈'); await sleep(1400);
|
||||
await startVoice();
|
||||
await lk(`__lk.say({ kind: 'interim', role: 'user', text: '今天下班的路上看到一只很胖的橘猫' })`); await sleep(250);
|
||||
await shot(`15-${theme}-${v}-voice-listening`);
|
||||
await lk(`__lk.state('speaking')`); await sleep(300);
|
||||
await shot(`16-${theme}-${v}-voice-speaking`);
|
||||
if (v === 'phone') check(`${theme}/${v}: voice line fits the screen`, await js(`(() => { const r = document.querySelector('.voice-row.real').getBoundingClientRect(); return r.left >= 0 && r.right <= innerWidth; })()`));
|
||||
await click('.voice-row.real .voice-end'); await sleep(400);
|
||||
}
|
||||
await shot('17-fog-phone-voice-ended');
|
||||
|
||||
// ── 16. The real vendored client: same API names the page uses (no connection is made). ──
|
||||
await view('desktop');
|
||||
await cdp('Page.navigate', { url: `${base}/__nothing` }); await sleep(800);
|
||||
const sdk = await js(`new Promise(ok => { delete window.LivekitClient; const s = document.createElement('script'); s.src = '/__real-sdk.js'; s.onload = () => { const L = window.LivekitClient, E = L.RoomEvent; const room = new L.Room({ adaptiveStream: true, dynacast: true }); ok({ events: ['TrackSubscribed','TrackUnsubscribed','ParticipantConnected','ParticipantAttributesChanged','DataReceived','Disconnected','AudioPlaybackStatusChanged'].every(k => typeof E[k] === 'string'), values: [E.ParticipantAttributesChanged, E.DataReceived, E.AudioPlaybackStatusChanged], mic: L.Track.Source.Microphone, agent: L.ParticipantKind && L.ParticipantKind.AGENT, create: typeof L.createLocalAudioTrack, methods: ['connect','disconnect','startAudio','on'].every(m => typeof room[m] === 'function'), playback: typeof room.canPlaybackAudio, remote: room.remoteParticipants instanceof Map, publish: typeof room.localParticipant.publishTrack, version: L.version }); }; s.onerror = () => ok(null); document.head.append(s); })`);
|
||||
check('real livekit-client 2.22.4: every name the adapter uses exists', !!sdk && sdk.events && sdk.mic === 'microphone' && typeof sdk.agent === 'number' && sdk.create === 'function' && sdk.methods && sdk.playback === 'boolean' && sdk.remote && sdk.publish === 'function', JSON.stringify(sdk));
|
||||
|
||||
// ── 17. The demo entry stays separate: no voice route, no client. ──
|
||||
await calls();
|
||||
await cdp('Page.navigate', { url: `${base}/?demo=1` }); await sleep(2500);
|
||||
check('demo entry makes no voice requests', !(await calls()).some(l => l.includes('/api/voice')));
|
||||
|
||||
ws.close(); browser.kill();
|
||||
try { rmSync(profile, { recursive: true, force: true }); } catch { /* Edge may still hold the profile. */ }
|
||||
const failed = results.filter(r => !r).length;
|
||||
console.log(`${results.length - failed}/${results.length} passed`);
|
||||
process.exit(failed ? 1 : 0);
|
||||
@@ -0,0 +1,44 @@
|
||||
import { expect, test } from 'vitest';
|
||||
import { VoiceController, type RoomEvents, type VoiceView } from '../src/voice/session';
|
||||
|
||||
test('old room disconnect cleanup cannot overwrite a newly opened call', async () => {
|
||||
const pendingDeletes: (() => void)[] = [];
|
||||
const releaseOld = () => pendingDeletes.splice(0).forEach(resolve => resolve());
|
||||
let grant = 0;
|
||||
const events: RoomEvents[] = [];
|
||||
let view: VoiceView | undefined;
|
||||
const controller = new VoiceController({
|
||||
secure: () => true,
|
||||
onView: v => { view = v; },
|
||||
onRecord: () => {}, onSpoke: () => {},
|
||||
agentWaitMs: 60000,
|
||||
fetch: (async (url, init) => {
|
||||
if (String(url).endsWith('/status')) return Response.json({ configured: true, tts_ok: true });
|
||||
if (init?.method === 'POST') return Response.json({ session_id: `s${++grant}`, token: 'token', url: 'wss://fake.invalid' });
|
||||
if (String(url).endsWith('/s1')) await new Promise<void>(resolve => { pendingDeletes.push(resolve); });
|
||||
return Response.json({ ended: true });
|
||||
}) as typeof fetch,
|
||||
transport: async () => ({
|
||||
capture: async () => ({ stop() {}, onEnded() {} }),
|
||||
join: async (_url, _token, callbacks) => {
|
||||
events.push(callbacks);
|
||||
return { publish: async () => {}, close: async () => {}, hush() {}, resumeAudio: async () => {} };
|
||||
},
|
||||
}),
|
||||
});
|
||||
try {
|
||||
await controller.start();
|
||||
events[0].agentJoined();
|
||||
events[0].dropped(); // DELETE s1 is deliberately held in flight.
|
||||
await controller.start();
|
||||
events[1].agentJoined();
|
||||
expect(view?.phase).toBe('listening');
|
||||
releaseOld();
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
expect(controller.active).toBe(true);
|
||||
expect(view?.phase).toBe('listening');
|
||||
} finally {
|
||||
releaseOld();
|
||||
await controller.end();
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,400 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { mergeTurns, recentRows, VoiceController, voiceStatus, WORDS, type MicTrack, type RoomEvents, type VoiceRoom, type VoiceView } from '../src/voice/session';
|
||||
import type { ServerMessage } from '../src/adapters/real';
|
||||
import type { Message } from '../src/domain/model';
|
||||
|
||||
// Fake transport and media objects: no LiveKit, no microphone, no network. The fake server follows the HEL-877 voice
|
||||
// router (src/cybergril/voice/router.py): GET /api/voice/status, POST /api/voice/session -> 201 grant, DELETE
|
||||
// /api/voice/session/{id} -> 200 or 404.
|
||||
const gate = () => { let open!: () => void; const promise = new Promise<void>(r => { open = r; }); return { promise, open }; };
|
||||
const flush = async (n = 8) => { for (let i = 0; i < n; i++) await Promise.resolve(); await new Promise(r => setTimeout(r, 0)); };
|
||||
class Mic implements MicTrack { stopped = 0; ended?: () => void; stop() { this.stopped++; } onEnded(cb: () => void) { this.ended = cb; } }
|
||||
class Room implements VoiceRoom {
|
||||
closed = 0; published: MicTrack[] = []; hushed: boolean[] = []; on!: RoomEvents;
|
||||
async publish(mic: MicTrack) { this.published.push(mic); }
|
||||
hush(on: boolean) { this.hushed.push(on); }
|
||||
async resumeAudio() {}
|
||||
async close() { this.closed++; }
|
||||
}
|
||||
class Transport {
|
||||
mics: Mic[] = []; rooms: Room[] = []; signals: AbortSignal[] = [];
|
||||
micGate?: ReturnType<typeof gate>; joinGate?: ReturnType<typeof gate>; micError?: Error; joinError?: Error;
|
||||
async capture() { const g = this.micGate; if (g) await g.promise; if (this.micError) throw this.micError; const m = new Mic(); this.mics.push(m); return m; }
|
||||
async join(_url: string, _token: string, on: RoomEvents, signal: AbortSignal) { const r = new Room(); r.on = on; this.rooms.push(r); this.signals.push(signal); const g = this.joinGate; if (g) await g.promise; if (this.joinError) throw this.joinError; return r; }
|
||||
}
|
||||
class Server {
|
||||
status: Record<string, unknown> | number = { configured: true, tts_ok: true, agent_name: 'cybergril-voice-agent', voice: false };
|
||||
open = new Set<string>(); made = 0; calls: { method: string; url: string; keepalive?: boolean }[] = [];
|
||||
postGate?: ReturnType<typeof gate>; refuse?: { status: number; detail: string };
|
||||
// DELETEs of these sessions wait for the gate (a slow server answering for an older call).
|
||||
deleteGate?: { ids: Set<string>; gate: ReturnType<typeof gate> };
|
||||
fetch = vi.fn(async (url: string, init: RequestInit = {}) => {
|
||||
const method = init.method || 'GET';
|
||||
this.calls.push({ method, url, keepalive: init.keepalive });
|
||||
if (url === '/api/voice/status') return typeof this.status === 'number' ? new Response('{"detail":"Not Found"}', { status: this.status }) : new Response(JSON.stringify(this.status));
|
||||
if (url === '/api/voice/session' && method === 'POST') {
|
||||
const g = this.postGate; if (g) await g.promise;
|
||||
if (this.refuse) return new Response(JSON.stringify({ detail: this.refuse.detail }), { status: this.refuse.status });
|
||||
const id = `s${++this.made}`; this.open.add(id);
|
||||
return new Response(JSON.stringify({ url: 'wss://lk.test', token: `tok-${id}`, room: `cg-voice-${id}`, session_id: id, agent_name: 'cybergril-voice-agent', epoch: 3, expires_at: 0 }), { status: 201 });
|
||||
}
|
||||
const m = /^\/api\/voice\/session\/(.+)$/u.exec(url);
|
||||
if (m && method === 'DELETE' && this.deleteGate?.ids.has(decodeURIComponent(m[1]))) await this.deleteGate.gate.promise;
|
||||
if (m && method === 'DELETE') return this.open.delete(decodeURIComponent(m[1])) ? new Response('{"ended":true}') : new Response('{"detail":"这次通话已经不在了。"}', { status: 404 });
|
||||
return new Response('{"detail":"Not Found"}', { status: 404 });
|
||||
});
|
||||
}
|
||||
function rig() {
|
||||
const server = new Server(), transport = new Transport(), views: VoiceView[] = [], record = vi.fn(), spoke = vi.fn();
|
||||
const c = new VoiceController({ transport: async () => transport, onView: v => views.push(v), onRecord: record, onSpoke: spoke, fetch: server.fetch as unknown as typeof fetch, secure: () => true, agentWaitMs: 1000 });
|
||||
const view = () => views.at(-1)!;
|
||||
return { server, transport, views, view, record, spoke, c };
|
||||
}
|
||||
async function connected() {
|
||||
const r = rig(); await r.c.start(); r.transport.rooms[0].on.agentJoined(); return r;
|
||||
}
|
||||
afterEach(() => { vi.useRealTimers(); vi.unstubAllGlobals(); });
|
||||
|
||||
describe('honest switch', () => {
|
||||
it('reads status only: no room, no microphone', async () => {
|
||||
const s = new Server();
|
||||
expect(await voiceStatus(new AbortController().signal, s.fetch as unknown as typeof fetch)).toEqual({ available: true, reason: '' });
|
||||
s.status = { configured: false, tts_ok: false, voice: false };
|
||||
expect((await voiceStatus(new AbortController().signal, s.fetch as unknown as typeof fetch)).reason).toBe(WORDS.notConfigured);
|
||||
s.status = { configured: true, tts_ok: false, voice: false };
|
||||
expect((await voiceStatus(new AbortController().signal, s.fetch as unknown as typeof fetch)).reason).toBe(WORDS.ttsDown);
|
||||
s.status = 404;
|
||||
expect((await voiceStatus(new AbortController().signal, s.fetch as unknown as typeof fetch)).reason).toBe(WORDS.noRoute);
|
||||
const down = vi.fn(async () => { throw new TypeError('Failed to fetch'); });
|
||||
expect((await voiceStatus(new AbortController().signal, down as unknown as typeof fetch)).reason).toBe(WORDS.unknown);
|
||||
expect(s.calls.every(c => c.method === 'GET' && c.url === '/api/voice/status')).toBe(true);
|
||||
});
|
||||
it('configured && tts_ok never means "verified": voice:false is not read as connected', async () => {
|
||||
const r = rig(); r.server.status = { configured: true, tts_ok: true, voice: false };
|
||||
await r.c.start();
|
||||
// Starting is allowed (the user asked), but the page only says what the room is doing, never "已接通".
|
||||
expect(r.views.map(v => v.phase)).toEqual(['opening', 'joining']);
|
||||
});
|
||||
it('refuses honestly before touching the microphone when the server cannot speak', async () => {
|
||||
const r = rig(); r.server.status = { configured: true, tts_ok: false };
|
||||
await r.c.start();
|
||||
expect(r.view()).toMatchObject({ phase: 'off', notice: WORDS.ttsDown });
|
||||
expect(r.transport.mics).toHaveLength(0);
|
||||
expect(r.server.calls.some(c => c.method === 'POST')).toBe(false);
|
||||
});
|
||||
it('an insecure page is told why, without asking for the microphone', async () => {
|
||||
const r = rig(); const c = new VoiceController({ transport: async () => r.transport, onView: v => r.views.push(v), onRecord: r.record, onSpoke: r.spoke, fetch: r.server.fetch as unknown as typeof fetch, secure: () => false });
|
||||
await c.start();
|
||||
expect(r.view().notice).toBe(WORDS.insecure);
|
||||
expect(r.server.calls).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('lifecycle', () => {
|
||||
it('opens, joins, publishes the microphone, follows her state; ending stops everything', async () => {
|
||||
const r = await connected(), room = r.transport.rooms[0], mic = r.transport.mics[0];
|
||||
expect(room.published).toEqual([mic]);
|
||||
expect(r.view().phase).toBe('listening');
|
||||
room.on.agentState('thinking'); expect(r.view().phase).toBe('thinking');
|
||||
room.on.agentState('speaking'); expect(r.view().phase).toBe('speaking');
|
||||
room.on.agentState('listening'); expect(r.view().phase).toBe('listening');
|
||||
expect(r.server.open.size).toBe(1);
|
||||
await r.c.end();
|
||||
expect(mic.stopped).toBeGreaterThan(0);
|
||||
expect(room.closed).toBe(1);
|
||||
expect(r.server.open.size).toBe(0);
|
||||
expect(r.view()).toMatchObject({ phase: 'off', notice: '' });
|
||||
expect(r.c.active).toBe(false);
|
||||
});
|
||||
it('permission denied: nothing opened on the server, nothing left running', async () => {
|
||||
const r = rig(); r.transport.micError = Object.assign(new Error('denied'), { name: 'NotAllowedError' });
|
||||
await r.c.start();
|
||||
expect(r.view()).toMatchObject({ phase: 'off', notice: WORDS.denied });
|
||||
expect(r.server.calls.filter(c => c.method !== 'GET')).toHaveLength(0);
|
||||
r.transport.micError = Object.assign(new Error('none'), { name: 'NotFoundError' });
|
||||
await r.c.start(); expect(r.view().notice).toBe(WORDS.noMic);
|
||||
});
|
||||
it('server refusal shows its own words and releases the microphone', async () => {
|
||||
const r = rig(); r.server.refuse = { status: 409, detail: '还没有创建真实伴侣,语音也不会开始。' };
|
||||
await r.c.start();
|
||||
expect(r.view().notice).toBe('还没有创建真实伴侣,语音也不会开始。');
|
||||
expect(r.transport.mics[0].stopped).toBeGreaterThan(0);
|
||||
expect(r.transport.rooms).toHaveLength(0);
|
||||
});
|
||||
it('a failed join releases the microphone and gives the room back', async () => {
|
||||
const r = rig(); r.transport.joinError = new Error('ws failed');
|
||||
await r.c.start();
|
||||
expect(r.view().notice).toBe(WORDS.unreachable);
|
||||
expect(r.transport.mics[0].stopped).toBeGreaterThan(0);
|
||||
expect(r.server.open.size).toBe(0);
|
||||
});
|
||||
it('ending while the microphone prompt is open: the late microphone is stopped, no room is asked for', async () => {
|
||||
const r = rig(); r.transport.micGate = gate();
|
||||
const starting = r.c.start(); await flush();
|
||||
await r.c.end();
|
||||
r.transport.micGate.open(); await starting; await flush();
|
||||
expect(r.transport.mics[0].stopped).toBeGreaterThan(0);
|
||||
expect(r.server.calls.some(c => c.method === 'POST')).toBe(false);
|
||||
expect(r.view().phase).toBe('off');
|
||||
});
|
||||
it('ending while the room is being opened: the late grant is given back, never joined', async () => {
|
||||
const r = rig(); r.server.postGate = gate();
|
||||
const starting = r.c.start(); await flush();
|
||||
await r.c.end();
|
||||
expect(r.transport.mics[0].stopped).toBeGreaterThan(0);
|
||||
r.server.postGate.open(); await starting; await flush();
|
||||
expect(r.server.made).toBe(1);
|
||||
expect(r.server.open.size).toBe(0);
|
||||
expect(r.transport.rooms).toHaveLength(0);
|
||||
expect(r.view().phase).toBe('off');
|
||||
});
|
||||
it('ending while joining: the join is aborted, a late room is closed, the server room deleted', async () => {
|
||||
const r = rig(); r.transport.joinGate = gate();
|
||||
const starting = r.c.start(); await flush();
|
||||
expect(r.view().phase).toBe('joining');
|
||||
await r.c.end();
|
||||
expect(r.transport.signals[0].aborted).toBe(true);
|
||||
r.transport.joinGate.open(); await starting; await flush();
|
||||
expect(r.transport.rooms[0].closed).toBe(1);
|
||||
expect(r.server.open.size).toBe(0);
|
||||
expect(r.transport.mics[0].stopped).toBeGreaterThan(0);
|
||||
expect(r.view().phase).toBe('off');
|
||||
});
|
||||
it('rapid on/off/on: only the last call stays, every earlier microphone and room is released', async () => {
|
||||
const r = rig();
|
||||
const a = r.c.start(); void r.c.end(); const b = r.c.start(); const c = r.c.start();
|
||||
await Promise.all([a, b, c]); await flush();
|
||||
expect(r.server.open.size).toBe(1);
|
||||
const live = r.transport.mics.filter(m => !m.stopped);
|
||||
expect(live).toHaveLength(1);
|
||||
expect(r.transport.rooms.filter(x => !x.closed)).toHaveLength(1);
|
||||
await r.c.end(); await flush();
|
||||
expect(r.server.open.size).toBe(0);
|
||||
expect(r.transport.mics.every(m => m.stopped)).toBe(true);
|
||||
});
|
||||
it('late events from an ended call never bring it back', async () => {
|
||||
const r = await connected(), old = r.transport.rooms[0];
|
||||
await r.c.end(); r.record.mockClear();
|
||||
const seen = r.views.length;
|
||||
old.on.agentState('speaking'); old.on.subtitle({ kind: 'user_final', role: 'user', text: '旧的话' }); old.on.agentJoined(); old.on.dropped(); old.on.audioBlocked(true);
|
||||
r.transport.mics[0].ended?.();
|
||||
await flush();
|
||||
expect(r.views.length).toBe(seen);
|
||||
expect(r.record).not.toHaveBeenCalled(); expect(r.spoke).not.toHaveBeenCalled();
|
||||
expect(r.c.active).toBe(false);
|
||||
});
|
||||
it('the room dropping on its own (network, server ended it) cleans up and says so', async () => {
|
||||
const r = await connected();
|
||||
r.transport.rooms[0].on.dropped(); await flush();
|
||||
expect(r.view()).toMatchObject({ phase: 'off', notice: WORDS.dropped });
|
||||
expect(r.transport.mics[0].stopped).toBeGreaterThan(0);
|
||||
expect(r.server.open.size).toBe(0);
|
||||
});
|
||||
it('microphone permission revoked mid-call ends the call', async () => {
|
||||
const r = await connected();
|
||||
r.transport.mics[0].ended?.(); await flush();
|
||||
expect(r.view()).toMatchObject({ phase: 'off', notice: WORDS.micGone });
|
||||
expect(r.server.open.size).toBe(0);
|
||||
expect(r.transport.rooms[0].closed).toBe(1);
|
||||
});
|
||||
it('her worker never joining is a failure, not an endless wait', async () => {
|
||||
vi.useFakeTimers();
|
||||
const r = rig(); await r.c.start();
|
||||
expect(r.view().phase).toBe('joining');
|
||||
await vi.advanceTimersByTimeAsync(1100);
|
||||
expect(r.view()).toMatchObject({ phase: 'off', notice: WORDS.noAgent });
|
||||
expect(r.server.open.size).toBe(0);
|
||||
});
|
||||
it('offline ends with its own words; unload releases at once and the DELETE survives the page', async () => {
|
||||
const r = await connected();
|
||||
await r.c.end(WORDS.offline);
|
||||
expect(r.view().notice).toBe(WORDS.offline);
|
||||
const u = await connected();
|
||||
u.c.unload();
|
||||
expect(u.transport.mics[0].stopped).toBeGreaterThan(0);
|
||||
await flush();
|
||||
expect(u.server.calls.find(c => c.method === 'DELETE')?.keepalive).toBe(true);
|
||||
expect(u.server.open.size).toBe(0);
|
||||
});
|
||||
it('a DELETE that cannot get through (offline) is owed, survives a new page, and is sent once back online', async () => {
|
||||
const data = new Map<string, string>();
|
||||
vi.stubGlobal('localStorage', { getItem: (k: string) => data.get(k) ?? null, setItem: (k: string, v: string) => void data.set(k, v), removeItem: (k: string) => void data.delete(k) });
|
||||
const r = await connected(), real = r.server.fetch.getMockImplementation()!;
|
||||
r.server.fetch.mockImplementation(async (url: string, init: RequestInit = {}) => { if (init.method === 'DELETE') { r.server.calls.push({ method: 'DELETE', url }); throw new TypeError('Failed to fetch'); } return real(url, init); });
|
||||
await r.c.end(WORDS.offline);
|
||||
expect(r.transport.mics[0].stopped).toBeGreaterThan(0); // local capture stops regardless
|
||||
expect(r.server.open.size).toBe(1); // the server room is not pretended gone
|
||||
expect(JSON.parse(data.get('cg.voice.owed')!)).toEqual(['s1']);
|
||||
r.server.fetch.mockImplementation(real);
|
||||
// A new page (new controller) settles it: once, then forgets.
|
||||
const again = new VoiceController({ transport: async () => r.transport, onView: () => {}, onRecord: () => {}, onSpoke: () => {}, fetch: r.server.fetch as unknown as typeof fetch, secure: () => true });
|
||||
await again.settle();
|
||||
expect(r.server.open.size).toBe(0);
|
||||
expect(data.has('cg.voice.owed')).toBe(false);
|
||||
const before = r.server.calls.length; await again.settle();
|
||||
expect(r.server.calls.length).toBe(before);
|
||||
});
|
||||
it('an owed room already gone on the server (404) counts as settled', async () => {
|
||||
const data = new Map<string, string>([['cg.voice.owed', '["gone-1"]']]);
|
||||
vi.stubGlobal('localStorage', { getItem: (k: string) => data.get(k) ?? null, setItem: (k: string, v: string) => void data.set(k, v), removeItem: (k: string) => void data.delete(k) });
|
||||
const r = rig(); await r.c.settle();
|
||||
expect(r.server.calls.at(-1)).toMatchObject({ method: 'DELETE', url: '/api/voice/session/gone-1' });
|
||||
expect(data.has('cg.voice.owed')).toBe(false);
|
||||
});
|
||||
it('never confirms a receipt or posts chat itself: the worker owns both', async () => {
|
||||
const r = await connected(), room = r.transport.rooms[0];
|
||||
room.on.subtitle({ kind: 'user_final', role: 'user', text: '今天好冷' });
|
||||
room.on.subtitle({ kind: 'assistant_final', role: 'assistant', text: '那多穿一件。' });
|
||||
await r.c.end();
|
||||
expect(r.server.calls.some(c => c.url.startsWith('/api/chat'))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
// An older call's cleanup may answer long after a new call is up (a slow DELETE, the settle retry for it, a late
|
||||
// microphone): it may only release the older call's own things, never touch the new call's view, microphone or room.
|
||||
describe('a late end of an older call', () => {
|
||||
const hold = (r: ReturnType<typeof rig>, ...ids: string[]) => { const g = gate(); r.server.deleteGate = { ids: new Set(ids), gate: g }; return g; };
|
||||
const reopened = async (r: ReturnType<typeof rig>, i: number) => { await r.c.start(); r.transport.rooms[i].on.agentJoined(); expect(r.view().phase).toBe('listening'); };
|
||||
const stillNew = (r: ReturnType<typeof rig>, i: number) => {
|
||||
expect(r.c.active).toBe(true);
|
||||
expect(r.view()).toMatchObject({ phase: 'listening', notice: '' });
|
||||
expect(r.transport.mics[i].stopped).toBe(0);
|
||||
expect(r.transport.rooms[i].closed).toBe(0);
|
||||
expect(r.transport.mics.slice(0, i).every(m => m.stopped > 0)).toBe(true);
|
||||
expect(r.transport.rooms.slice(0, i).every(x => x.closed > 0)).toBe(true);
|
||||
};
|
||||
const failures: [string, (r: ReturnType<typeof rig>) => void][] = [
|
||||
['the room dropped', r => r.transport.rooms[0].on.dropped()],
|
||||
['the microphone was taken away', r => r.transport.mics[0].ended?.()],
|
||||
];
|
||||
for (const [what, cause] of failures) {
|
||||
it(`${what}, its DELETE (and the settle retry) answering after a new call is up, leaves the new call alone`, async () => {
|
||||
const r = await connected(), slow = hold(r, 's1');
|
||||
cause(r); await flush();
|
||||
expect(r.view()).toMatchObject({ phase: 'off' });
|
||||
expect(r.transport.mics[0].stopped).toBeGreaterThan(0); // released at once, not after the server answers
|
||||
expect(r.c.active).toBe(false);
|
||||
await reopened(r, 1);
|
||||
expect(r.server.calls.filter(c => c.method === 'DELETE' && c.url.endsWith('/s1')).length).toBe(2); // first try + settle
|
||||
const seen = r.views.length;
|
||||
slow.open(); await flush();
|
||||
expect(r.views.length).toBe(seen);
|
||||
stillNew(r, 1);
|
||||
expect(r.server.open).toEqual(new Set(['s2']));
|
||||
await r.c.end(); await flush();
|
||||
expect(r.server.open.size).toBe(0);
|
||||
expect(r.transport.mics.every(m => m.stopped)).toBe(true);
|
||||
});
|
||||
}
|
||||
it('her worker never joined, the DELETE is slow, and a new call is started before it answers', async () => {
|
||||
vi.useFakeTimers();
|
||||
const r = rig(); await r.c.start(); const slow = hold(r, 's1');
|
||||
await vi.advanceTimersByTimeAsync(1100);
|
||||
expect(r.view()).toMatchObject({ phase: 'off', notice: WORDS.noAgent });
|
||||
await reopened(r, 1);
|
||||
slow.open(); await vi.advanceTimersByTimeAsync(0);
|
||||
stillNew(r, 1);
|
||||
await r.c.end();
|
||||
});
|
||||
it('a normal end whose DELETE is slow, then a new call, then the old answer arrives', async () => {
|
||||
const r = await connected(), slow = hold(r, 's1');
|
||||
const ending = r.c.end();
|
||||
expect(r.view()).toMatchObject({ phase: 'off', notice: '' });
|
||||
await reopened(r, 1);
|
||||
slow.open(); await ending; await flush();
|
||||
stillNew(r, 1);
|
||||
expect(r.server.open).toEqual(new Set(['s2']));
|
||||
await r.c.end();
|
||||
});
|
||||
it('starting again while the previous start still waits for the old room to be given back: only the newest call survives', async () => {
|
||||
const r = await connected(), slow = hold(r, 's1');
|
||||
const b = r.c.start(); await flush(); // B ends A; A's DELETE is held
|
||||
const c = r.c.start(); await flush(); // C does not wait behind B
|
||||
r.transport.rooms.at(-1)!.on.agentJoined();
|
||||
slow.open(); await Promise.all([b, c]); await flush(); // B wakes up late: it must not take over
|
||||
const last = r.transport.rooms.length - 1;
|
||||
expect(r.transport.rooms.filter(x => !x.closed)).toEqual([r.transport.rooms[last]]);
|
||||
expect(r.transport.mics.filter(m => !m.stopped)).toEqual([r.transport.mics[last]]);
|
||||
expect(r.server.open.size).toBe(1);
|
||||
stillNew(r, last);
|
||||
await r.c.end(); await flush();
|
||||
expect(r.server.open.size).toBe(0);
|
||||
expect(r.transport.mics.every(m => m.stopped)).toBe(true);
|
||||
expect(r.transport.rooms.every(x => x.closed)).toBe(true);
|
||||
});
|
||||
it('a microphone granted late to an older start is stopped without touching the new call', async () => {
|
||||
const r = rig(); r.transport.micGate = gate(); const late = r.transport.micGate;
|
||||
const a = r.c.start(); await flush();
|
||||
r.transport.micGate = undefined;
|
||||
await reopened(r, 0);
|
||||
late.open(); await a; await flush();
|
||||
expect(r.transport.mics).toHaveLength(2);
|
||||
expect(r.transport.mics[1].stopped).toBeGreaterThan(0); // A's late microphone
|
||||
expect(r.transport.mics[0].stopped).toBe(0); // the live call's own
|
||||
expect(r.c.active).toBe(true);
|
||||
expect(r.view()).toMatchObject({ phase: 'listening', notice: '' });
|
||||
expect(r.server.made).toBe(1);
|
||||
await r.c.end();
|
||||
});
|
||||
});
|
||||
|
||||
describe('subtitles and the two channels', () => {
|
||||
it('interim is a draft; user_final cancels a text reply and asks for the record; φ is heard but not recorded', async () => {
|
||||
const r = await connected(), room = r.transport.rooms[0];
|
||||
room.on.subtitle({ kind: 'interim', role: 'user', text: '今天' });
|
||||
expect(r.view().heard).toBe('今天'); expect(r.record).not.toHaveBeenCalled();
|
||||
room.on.subtitle({ kind: 'user_final', role: 'user', text: '今天好冷' });
|
||||
expect(r.spoke).toHaveBeenCalledTimes(1); expect(r.record).toHaveBeenCalledTimes(1);
|
||||
room.on.subtitle({ kind: 'error', role: 'assistant', text: '我刚才走神了,你再说一遍?' });
|
||||
expect(r.view().spoken).toBe('我刚才走神了,你再说一遍?');
|
||||
room.on.subtitle({ kind: 'assistant_final', role: 'assistant', text: '那多穿一件。' });
|
||||
expect(r.view()).toMatchObject({ heard: '', spoken: '' });
|
||||
room.on.subtitle({ kind: 'bogus', text: 1 }); room.on.subtitle(null);
|
||||
expect(r.record).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
it('without the agent state attribute, subtitles still move the state honestly', async () => {
|
||||
const r = await connected(), room = r.transport.rooms[0];
|
||||
room.on.subtitle({ kind: 'user_final', role: 'user', text: '在吗' }); expect(r.view().phase).toBe('thinking');
|
||||
room.on.subtitle({ kind: 'assistant_final', role: 'assistant', text: '在。' }); expect(r.view().phase).toBe('listening');
|
||||
});
|
||||
it('typing over her spoken answer silences what is left of it until she is listening again', async () => {
|
||||
const r = await connected(), room = r.transport.rooms[0];
|
||||
r.c.hush(); expect(room.hushed).toEqual([]); // listening: nothing to silence
|
||||
room.on.agentState('speaking'); r.c.hush();
|
||||
expect(room.hushed).toEqual([true]);
|
||||
room.on.agentState('speaking'); expect(room.hushed).toEqual([true]);
|
||||
room.on.agentState('listening'); expect(room.hushed).toEqual([true, false]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('record re-read', () => {
|
||||
const msg = (id: number, role: Message['role'], turnId: string, extra: Partial<Message> = {}): Message => ({ id: String(id), role, text: `${role}${id}`, lifeIds: [], turnId, status: 'sent', ...extra });
|
||||
it('adds voice turns once, in id order; leaves reach-outs to the inbox and text turns to the stream', () => {
|
||||
const known = [msg(1, 'user', 't1'), msg(2, 'companion', 't1'), { ...msg(0, 'user', 'local-turn'), id: 'abc-local', status: 'pending' as const }];
|
||||
const rows = [msg(5, 'companion', 'v1'), msg(4, 'user', 'v1'), msg(6, 'companion', 'r6', { proactive: true }), msg(7, 'user', 'local-turn'), msg(2, 'companion', 't1')];
|
||||
const next = mergeTurns(known, rows)!;
|
||||
expect(next.map(m => m.id)).toEqual(['1', '2', 'abc-local', '4', '5']);
|
||||
expect(mergeTurns(next, rows)).toBeNull();
|
||||
});
|
||||
it('a pending voice row settles in place (sent or cancelled), never duplicated', () => {
|
||||
const known = [msg(4, 'user', 'v1', { status: 'pending' })];
|
||||
const next = mergeTurns(known, [msg(4, 'user', 'v1', { status: 'cancelled' })])!;
|
||||
expect(next).toHaveLength(1); expect(next[0].status).toBe('cancelled');
|
||||
});
|
||||
it('reads newest pages down to what the page holds, bounded', async () => {
|
||||
const rows: ServerMessage[] = Array.from({ length: 130 }, (_, i) => ({ id: i + 1, role: i % 2 ? 'companion' : 'user', text: `第${i + 1}句`, turn_id: `t${i}`, status: 'sent' }));
|
||||
const calls: string[] = [];
|
||||
vi.stubGlobal('fetch', vi.fn(async (url: string) => {
|
||||
calls.push(url);
|
||||
const u = new URL(url, 'http://x'), limit = Number(u.searchParams.get('limit')), before = Number(u.searchParams.get('before') || Infinity);
|
||||
const desc = rows.filter(r => r.id < before).sort((a, b) => b.id - a.id).slice(0, limit + 1), more = desc.length > limit, page = desc.slice(0, limit);
|
||||
return new Response(JSON.stringify({ messages: [...page].reverse(), next_before: more ? page.at(-1)!.id : null }));
|
||||
}));
|
||||
expect((await recentRows(120, new AbortController().signal)).map(m => m.id)).toEqual(['121', '122', '123', '124', '125', '126', '127', '128', '129', '130']);
|
||||
expect(calls).toHaveLength(1);
|
||||
expect(await recentRows(60, new AbortController().signal)).toHaveLength(70);
|
||||
calls.length = 0;
|
||||
expect(await recentRows(0, new AbortController().signal, 2)).toHaveLength(100);
|
||||
expect(calls).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user