628 lines
45 KiB
TypeScript
628 lines
45 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
import { mergeTurns, recentRows, VoiceController, voiceLine, voiceStatus, WORDS, type HerLine, type MicTrack, type RoomEvents, type VoiceRoom, type VoiceView } from '../src/voice/session';
|
|
import { groupTurns, pagesOf, type ShownMessage } from '../src/chat/reading';
|
|
import type { ServerMessage } from '../src/adapters/real';
|
|
import type { Message } from '../src/domain/model';
|
|
import { readFileSync } from 'node:fs';
|
|
|
|
// The backend's recorded cg.subtitle frames (contract v2, docs/rework/hel879/subtitle-samples, generated offline).
|
|
type Frame = Record<string, unknown> & { seq: number };
|
|
const sample = (name: string): Frame[] => readFileSync(new URL(`../../docs/rework/hel879/subtitle-samples/${name}.jsonl`, import.meta.url), 'utf8').split('\n').filter(l => l.trim()).map(l => JSON.parse(l));
|
|
|
|
// 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({ v: 2, seq: 1, kind: 'user_final', role: 'user', text: '旧的话' }); old.on.subtitle({ v: 2, seq: 2, kind: 'turn_start', role: 'assistant', text: '', speech_id: 'old' }); 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];
|
|
for (const line of sample('normal-turn')) room.on.subtitle(line);
|
|
for (const line of sample('proactive')) room.on.subtitle({ ...line, seq: line.seq + 100 });
|
|
await r.c.end();
|
|
expect(r.server.calls.some(c => c.url.startsWith('/api/chat'))).toBe(false);
|
|
// No receipt, no read mark, no message write: the page only talks to the voice routes.
|
|
expect(r.server.calls.every(c => c.url.startsWith('/api/voice/'))).toBe(true);
|
|
});
|
|
});
|
|
|
|
// 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();
|
|
});
|
|
});
|
|
|
|
// A v2 frame as the worker's SubtitleBus emits it (src/cybergril/voice/seam.py).
|
|
const frame = (seq: number, kind: string, extra: Record<string, unknown> = {}) => ({ v: 2, seq, kind, role: kind === 'interim' || kind === 'user_final' ? 'user' : 'assistant', text: '', ...extra });
|
|
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(frame(1, 'interim', { text: '今天' }));
|
|
expect(r.view().heard).toBe('今天'); expect(r.record).not.toHaveBeenCalled();
|
|
room.on.subtitle(frame(2, 'user_final', { text: '今天好冷' }));
|
|
expect(r.spoke).toHaveBeenCalledTimes(1); expect(r.record).toHaveBeenCalledTimes(1);
|
|
room.on.subtitle(frame(3, 'turn_start', { speech_id: 'a' }));
|
|
room.on.subtitle(frame(4, 'assistant_interim', { speech_id: 'a', text: '我刚' }));
|
|
room.on.subtitle(frame(5, 'error', { speech_id: 'a', text: '我刚才走神了,你再说一遍?' }));
|
|
expect(r.view()).toMatchObject({ spoken: '我刚才走神了,你再说一遍?', her: null });
|
|
room.on.subtitle(frame(6, 'turn_cancel', { speech_id: 'a', reason: 'error_phi' }));
|
|
expect(r.view()).toMatchObject({ spoken: '我刚才走神了,你再说一遍?', her: null });
|
|
room.on.subtitle(frame(7, 'assistant_interim', { speech_id: 'a', text: '我刚才走神了' })); // after its cancel
|
|
expect(r.view().her).toBeNull();
|
|
room.on.subtitle({ kind: 'bogus', text: 1 }); room.on.subtitle(null);
|
|
expect(r.record).toHaveBeenCalledTimes(3);
|
|
expect(r.server.calls.some(c => c.url.startsWith('/api/chat') || c.url.startsWith('/api/messages'))).toBe(false);
|
|
});
|
|
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(frame(1, 'user_final', { text: '在吗' })); expect(r.view().phase).toBe('thinking');
|
|
room.on.subtitle(frame(2, 'turn_start', { speech_id: 'a' })); expect(r.view().phase).toBe('thinking');
|
|
room.on.subtitle(frame(3, 'assistant_final', { speech_id: 'a', turn_id: 't', 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]);
|
|
});
|
|
});
|
|
|
|
// HEL-898: her words while she speaks (contract v2). The page shows them; it never stores, confirms or marks them.
|
|
describe('her voice line (cg.subtitle v2)', () => {
|
|
const play = (room: Room, frames: Frame[], after?: (f: Frame) => void) => { for (const f of frames) { room.on.subtitle(f); after?.(f); } };
|
|
it('rejects anything that is not exactly a v2 frame', async () => {
|
|
const r = await connected(), room = r.transport.rooms[0], seen = r.views.length;
|
|
const bad = [
|
|
{ kind: 'user_final', role: 'user', text: 'v1 没有信封' },
|
|
{ ...frame(1, 'user_final', { text: '版本不对' }), v: 3 },
|
|
{ ...frame(1, 'user_final', { text: '序号不对' }), seq: 0 },
|
|
{ ...frame(1, 'user_final', { text: '序号不对' }), seq: 1.5 },
|
|
{ ...frame(1, 'user_final', { text: '序号不对' }), seq: '1' },
|
|
frame(1, 'turn_start'), // no speech_id
|
|
{ ...frame(1, 'turn_start', { speech_id: 'a' }), role: 'user' }, // her kind, your role
|
|
{ ...frame(1, 'interim', { text: '草稿' }), role: 'assistant' }, // your kind, her role
|
|
frame(1, 'assistant_final', { speech_id: 'a', text: '无归属' }), // final without turn_id
|
|
frame(1, 'proactive_start', { speech_id: 'p', text: '无行号' }), // reach-out without message_id
|
|
frame(1, 'proactive_start', { speech_id: 'p', text: '行号不对', message_id: '17' }),
|
|
frame(1, 'assistant_text', { speech_id: 'a', text: '未知种类' }),
|
|
[frame(1, 'user_final', { text: '数组' })],
|
|
];
|
|
for (const b of bad) room.on.subtitle(b);
|
|
expect(r.views.length).toBe(seen); expect(r.record).not.toHaveBeenCalled(); expect(r.spoke).not.toHaveBeenCalled();
|
|
// A rejected frame does not move the sequence: the first good one still lands.
|
|
room.on.subtitle(frame(1, 'interim', { text: '好的' })); expect(r.view().heard).toBe('好的');
|
|
});
|
|
it('normal turn: your draft and final, her growing reply replaced in place, then her stored final', async () => {
|
|
const r = await connected(), room = r.transport.rooms[0], frames = sample('normal-turn');
|
|
const steps: (VoiceView['her'] | string)[] = [];
|
|
play(room, frames, () => steps.push(r.view().her ? { ...r.view().her! } : r.view().heard));
|
|
expect(steps).toEqual([
|
|
'你在听的', '你在听吗?',
|
|
{ speech: 'speech_normal', text: '', state: 'open' },
|
|
{ speech: 'speech_normal', text: '在听呢,', state: 'open' },
|
|
{ speech: 'speech_normal', text: '在听呢,在听呢,你刚才说到一半的那件事我还在想。', state: 'open' },
|
|
{ speech: 'speech_normal', text: '在听呢,你刚才说到一半的那件事我还在想。', state: 'final', turnId: '0e2f-demo-turn' },
|
|
{ speech: 'speech_normal', text: '在听呢,你刚才说到一半的那件事我还在想。', state: 'done', turnId: '0e2f-demo-turn' },
|
|
]);
|
|
expect(r.view().heard).toBe(''); // her stored answer retires the draft it answered
|
|
// Her words never land in your draft slot, and yours never in hers.
|
|
expect(r.views.every(v => !v.her || !v.heard.includes('在听呢'))).toBe(true);
|
|
expect(r.spoke).toHaveBeenCalledTimes(1);
|
|
expect(r.record).toHaveBeenCalledTimes(3); // your final, her final, her turn's end: re-read, never written
|
|
// The whole recording replayed (same seq) changes nothing.
|
|
const seen = r.views.length; play(room, frames);
|
|
expect(r.views.length).toBe(seen);
|
|
// Your next turn: her finished line does not stay in front of it.
|
|
room.on.subtitle(frame(8, 'interim', { text: '那' })); expect(r.view().her?.state).toBe('done');
|
|
room.on.subtitle(frame(9, 'user_final', { text: '那你想到了吗' })); expect(r.view().her).toBeNull();
|
|
});
|
|
it('interrupted: no final, her line goes at once, its late frames never reach the new turn', async () => {
|
|
const r = await connected(), room = r.transport.rooms[0], frames = sample('interrupt');
|
|
play(room, frames.slice(0, 2));
|
|
expect(r.view().her).toMatchObject({ speech: 'speech_cut', text: '我正想跟你说,今天下午', state: 'open' });
|
|
play(room, frames.slice(2, 3));
|
|
expect(r.view().her).toBeNull();
|
|
// Late increments of the cut turn, even with a higher seq, and a replay of its start.
|
|
room.on.subtitle(frame(4, 'assistant_interim', { speech_id: 'speech_cut', text: '我正想跟你说,今天下午去了' }));
|
|
room.on.subtitle(frame(5, 'assistant_final', { speech_id: 'speech_cut', turn_id: 'old', text: '我正想跟你说,今天下午去了河边。' }));
|
|
room.on.subtitle(frame(6, 'turn_start', { speech_id: 'speech_cut' }));
|
|
expect(r.view().her).toBeNull();
|
|
play(room, frames.slice(3).map(f => ({ ...f, seq: f.seq + 10 })));
|
|
expect(r.view()).toMatchObject({ heard: '', her: { speech: 'speech_next', text: '好,你先说。', state: 'done', turnId: '0e2f-demo-next' } });
|
|
});
|
|
it('frames that overtook each other: a lower seq is stale; an older speech never touches or closes the new one', async () => {
|
|
const r = await connected(), room = r.transport.rooms[0];
|
|
room.on.subtitle(frame(1, 'turn_start', { speech_id: 'a' }));
|
|
room.on.subtitle(frame(3, 'assistant_interim', { speech_id: 'a', text: '一二三' }));
|
|
room.on.subtitle(frame(2, 'assistant_interim', { speech_id: 'a', text: '一二' })); // overtaken: dropped
|
|
expect(r.view().her?.text).toBe('一二三');
|
|
// Two handles: b starts while a is still open (queued then generated). a is closed here by b.
|
|
room.on.subtitle(frame(4, 'turn_start', { speech_id: 'b' }));
|
|
room.on.subtitle(frame(5, 'assistant_interim', { speech_id: 'a', text: '一二三四' }));
|
|
room.on.subtitle(frame(6, 'turn_end', { speech_id: 'a', turn_id: 'ta' }));
|
|
room.on.subtitle(frame(7, 'turn_cancel', { speech_id: 'a', reason: 'interrupted' }));
|
|
room.on.subtitle(frame(8, 'proactive_cancel', { speech_id: 'b', message_id: 3, reason: 'interrupted' })); // wrong family
|
|
expect(r.view().her).toEqual({ speech: 'b', text: '', state: 'open' });
|
|
room.on.subtitle(frame(9, 'assistant_interim', { speech_id: 'b', text: '好' }));
|
|
room.on.subtitle(frame(10, 'turn_end', { speech_id: 'b', turn_id: 'tb' })); // closed without final
|
|
expect(r.view().her).toBeNull();
|
|
room.on.subtitle(frame(11, 'assistant_final', { speech_id: 'b', turn_id: 'tb', text: '好。' }));
|
|
expect(r.view().her).toBeNull();
|
|
});
|
|
it('reach-out read aloud: shown whole with its stored message id, interruptible, nothing marked or stored', async () => {
|
|
const r = await connected(), room = r.transport.rooms[0], frames = sample('proactive');
|
|
play(room, frames.slice(0, 1));
|
|
expect(r.view()).toMatchObject({ phase: 'speaking', her: { speech: 'speech_pro1', text: '我看到一句很适合现在的话,先念给你听。', state: 'open', messageId: 17, proactive: true } });
|
|
room.on.subtitle(frame(2, 'proactive_end', { speech_id: 'speech_pro1', message_id: 99 })); // another row's end
|
|
expect(r.view().her?.state).toBe('open');
|
|
play(room, frames.slice(1, 2).map(f => ({ ...f, seq: 3 })));
|
|
expect(r.view().her).toMatchObject({ messageId: 17, state: 'done' });
|
|
play(room, frames.slice(2).map(f => ({ ...f, seq: f.seq + 10 })));
|
|
expect(r.view().her).toBeNull();
|
|
// Reaching out is not a turn of yours: no "you spoke", no record write, no request at all.
|
|
expect(r.spoke).not.toHaveBeenCalled(); expect(r.record).not.toHaveBeenCalled();
|
|
expect(r.server.calls.filter(c => !c.url.startsWith('/api/voice/'))).toEqual([]);
|
|
});
|
|
it('a reach-out cut by your voice: the cancel clears it, your words follow', async () => {
|
|
const r = await connected(), room = r.transport.rooms[0];
|
|
room.on.subtitle(frame(1, 'proactive_start', { speech_id: 'p', message_id: 18, text: '还有一件事想告诉你——' }));
|
|
room.on.subtitle(frame(2, 'interim', { text: '等等' }));
|
|
expect(r.view()).toMatchObject({ heard: '等等', her: { speech: 'p', state: 'open' } });
|
|
room.on.subtitle(frame(3, 'proactive_cancel', { speech_id: 'p', message_id: 18, reason: 'interrupted' }));
|
|
expect(r.view()).toMatchObject({ heard: '等等', her: null });
|
|
});
|
|
it('text taking over, hanging up and starting again each clear her line at once', async () => {
|
|
const r = await connected(), room = r.transport.rooms[0];
|
|
room.on.agentState('speaking');
|
|
room.on.subtitle(frame(1, 'turn_start', { speech_id: 'a' }));
|
|
room.on.subtitle(frame(2, 'assistant_interim', { speech_id: 'a', text: '那我们' }));
|
|
r.c.hush();
|
|
expect(r.view().her).toBeNull(); expect(room.hushed).toEqual([true]);
|
|
room.on.subtitle(frame(3, 'assistant_interim', { speech_id: 'a', text: '那我们明天' }));
|
|
expect(r.view().her).toBeNull();
|
|
// A finished line is cleared by text too: your typed line comes next on the stage.
|
|
room.on.subtitle(frame(4, 'turn_start', { speech_id: 'b' }));
|
|
room.on.subtitle(frame(5, 'assistant_interim', { speech_id: 'b', text: '好。' }));
|
|
room.on.subtitle(frame(6, 'assistant_final', { speech_id: 'b', turn_id: 'tb', text: '好。' }));
|
|
room.on.subtitle(frame(7, 'turn_end', { speech_id: 'b', turn_id: 'tb' }));
|
|
expect(r.view().her?.state).toBe('done');
|
|
r.c.hush(); expect(r.view().her).toBeNull();
|
|
// Hanging up mid-sentence.
|
|
room.on.subtitle(frame(8, 'turn_start', { speech_id: 'c' }));
|
|
room.on.subtitle(frame(9, 'assistant_interim', { speech_id: 'c', text: '嗯' }));
|
|
await r.c.end(); expect(r.view().her).toBeNull();
|
|
room.on.subtitle(frame(10, 'assistant_interim', { speech_id: 'c', text: '嗯,晚安' }));
|
|
expect(r.view().her).toBeNull();
|
|
// A new call is a new worker job: its sequence starts again; the old room's frames stay dead.
|
|
await r.c.start(); const next = r.transport.rooms[1]; next.on.agentJoined();
|
|
next.on.subtitle(frame(1, 'turn_start', { speech_id: 'n' }));
|
|
next.on.subtitle(frame(2, 'assistant_interim', { speech_id: 'n', text: '又见面了' }));
|
|
room.on.subtitle(frame(11, 'turn_start', { speech_id: 'z' }));
|
|
room.on.subtitle(frame(12, 'assistant_interim', { speech_id: 'n', text: '旧房间' }));
|
|
expect(r.view().her).toEqual({ speech: 'n', text: '又见面了', state: 'open' });
|
|
await r.c.end();
|
|
});
|
|
it('the room dropping mid-sentence clears her line with the call', async () => {
|
|
const r = await connected(), room = r.transport.rooms[0];
|
|
room.on.subtitle(frame(1, 'turn_start', { speech_id: 'a' }));
|
|
room.on.subtitle(frame(2, 'assistant_interim', { speech_id: 'a', text: '我' }));
|
|
room.on.dropped(); await flush();
|
|
expect(r.view()).toMatchObject({ phase: 'off', her: null, notice: WORDS.dropped });
|
|
});
|
|
});
|
|
|
|
describe('her voice line on the stage', () => {
|
|
const M = (id: number, role: Message['role'], text: string, turnId?: string, extra: Partial<Message> = {}): Message => ({ id: String(id), role, text, lifeIds: [], turnId, status: 'sent', ...extra });
|
|
const metrics = { width: 900, font: 23, compact: false };
|
|
const stage = (list: ShownMessage[]) => pagesOf(groupTurns(list).at(-1), metrics).map(p => `${p.key}=${p.text}`);
|
|
const you = M(4, 'user', '你在听吗?', 'T');
|
|
it('grows in her slot after your voice turn; the stored row takes over under the same line keys', () => {
|
|
const open: HerLine = { speech: 's', text: '在听呢,你刚才说到一半的那件事我一直还在心里想着。后来', state: 'open' };
|
|
const growing = voiceLine(open, [you], 1)!;
|
|
expect(growing).toMatchObject({ role: 'companion', live: 'speaking' });
|
|
// While she speaks, the sentence still forming waits; what she has finished is there.
|
|
expect(stage([you, growing])).toEqual(['T:0:0=你在听吗?', 'T:1:0=在听呢,你刚才说到一半的那件事我一直还在心里想着。']);
|
|
open.text += '呢?';
|
|
expect(stage([you, voiceLine(open, [you], 1)!])).toEqual(['T:0:0=你在听吗?', 'T:1:0=在听呢,你刚才说到一半的那件事我一直还在心里想着。', 'T:1:1=后来呢?']);
|
|
const done: HerLine = { ...open, state: 'done', turnId: 'T' };
|
|
const shown = stage([you, voiceLine(done, [you], 1)!]);
|
|
expect(shown).toEqual(['T:0:0=你在听吗?', 'T:1:0=在听呢,你刚才说到一半的那件事我一直还在心里想着。', 'T:1:1=后来呢?']);
|
|
const stored = [you, M(5, 'companion', done.text, 'T')];
|
|
expect(voiceLine(done, stored, 1)).toBeNull();
|
|
expect(stage(stored)).toEqual(shown);
|
|
});
|
|
it('a short spoken reply is on the stage while she says it, not only once it is stored (HEL-898 f92a86f)', () => {
|
|
const at = (text: string) => stage([you, voiceLine({ speech: 's', text, state: 'open' }, [you], 1)!]);
|
|
// worker-normal.jsonl, interim by interim: nothing of hers until a sentence is finished, then the whole of it.
|
|
expect(at('在听呢,')).toEqual(['T:0:0=你在听吗?']);
|
|
expect(at('在听呢,你刚才说到一半的那件事')).toEqual(['T:0:0=你在听吗?']);
|
|
expect(at('在听呢,你刚才说到一半的那件事我还在想。')).toEqual(['T:0:0=你在听吗?', 'T:1:0=在听呢,你刚才说到一半的那件事我还在想。']);
|
|
// Her final and her stored row keep exactly that line under that key: nothing moves when it is stored.
|
|
expect(stage([you, voiceLine({ speech: 's', text: '在听呢,你刚才说到一半的那件事我还在想。', state: 'final', turnId: 'T' }, [you], 1)!])).toEqual(at('在听呢,你刚才说到一半的那件事我还在想。'));
|
|
expect(stage([you, M(5, 'companion', '在听呢,你刚才说到一半的那件事我还在想。', 'T')])).toEqual(at('在听呢,你刚才说到一半的那件事我还在想。'));
|
|
// A very short sentence shows at once; the next one joins the same line (it only ever grows, never shrinks).
|
|
expect(at('嗯。')).toEqual(['T:0:0=你在听吗?', 'T:1:0=嗯。']);
|
|
expect(at('嗯。我在')).toEqual(['T:0:0=你在听吗?', 'T:1:0=嗯。']);
|
|
expect(at('嗯。我在。')).toEqual(['T:0:0=你在听吗?', 'T:1:0=嗯。我在。']);
|
|
expect(at('“好啊。”')).toEqual(['T:0:0=你在听吗?', 'T:1:0=“好啊。”']);
|
|
});
|
|
it('a long spoken reply still reads one or two sentences at a time; a text stream keeps holding its newest line', () => {
|
|
const long = '我下午去了河边,看到一群白鹭从水面上飞过去了,它们飞得很低,几乎贴着水,翅膀尖在水面上划出一道一道细细的白线,后来又绕回来落在对岸的芦苇里';
|
|
const lines = stage([you, voiceLine({ speech: 's', text: long, state: 'open' }, [you], 1)!]).slice(1);
|
|
// Every finished line of a long sentence is shown; the part still being said waits; no line is the whole text.
|
|
expect(lines.length).toBeGreaterThan(0);
|
|
expect(lines.every(l => l.length - 'T:1:0='.length <= 60)).toBe(true);
|
|
expect(lines.join('')).not.toContain('芦苇里');
|
|
const full = stage([you, voiceLine({ speech: 's', text: long + '。', state: 'final', turnId: 'T' }, [you], 1)!]).slice(1);
|
|
expect(full.slice(0, lines.length)).toEqual(lines);
|
|
// The text chat's own rule is untouched: a streamed reply holds back its newest chunk even when it is a sentence.
|
|
const typed = pagesOf(groupTurns([you, { ...M(9, 'companion', '在听呢,你刚才说到一半的那件事我还在想。', 'T'), live: 'generating' }]).at(-1), metrics);
|
|
expect(typed.map(p => p.text)).toEqual(['你在听吗?']);
|
|
});
|
|
it('a finished line never stands in front of a newer turn; an open one waits for its own end', () => {
|
|
const done: HerLine = { speech: 's', text: '好。', state: 'done', turnId: 'T' };
|
|
expect(voiceLine(done, [you, M(6, 'user', '还有', 'U')], 1)).toBeNull();
|
|
expect(voiceLine({ ...done, state: 'open' }, [you, M(6, 'user', '还有', 'U')], 1)).not.toBeNull();
|
|
expect(voiceLine({ ...done, text: '' }, [you], 1)).toBeNull();
|
|
});
|
|
it('a reach-out read aloud keeps its stored row identity and gives way when that row is the newest line', () => {
|
|
const line: HerLine = { speech: 'p', text: '我看到一句很适合现在的话,先念给你听。', state: 'open', messageId: 17, proactive: true };
|
|
const row = M(17, 'companion', line.text, 'R', { proactive: true });
|
|
const before = [you, M(5, 'companion', '在。', 'T')];
|
|
const waiting = voiceLine(line, before, 2, [row])!;
|
|
expect(waiting).toMatchObject({ id: '17', turnId: 'R', proactive: true }); expect(waiting.live).toBeUndefined();
|
|
expect(stage([...before, waiting])).toEqual(stage([...before, row]));
|
|
expect(voiceLine({ ...line, state: 'done' }, [...before, row], 2)).toBeNull();
|
|
// Not on the page at all: shown under its own key; nothing is created for the record.
|
|
expect(voiceLine(line, before, 2)).toMatchObject({ id: 'voice-p', proactive: true });
|
|
});
|
|
});
|
|
|
|
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);
|
|
});
|
|
});
|