/** * Fakes for the assist tests: a transport that records queries and * answers with a fixed result, and a buffer whose sync is always idle. */ import type { AssistBuffer, AssistTransport } from "../../../src/components/editor/assist/types"; import type { EngineError, JsonValue } from "../../../src/ipc"; /** A recording transport. */ export interface FakeTransport extends AssistTransport { /** The queries sent, in order. */ calls: { command: string; params: JsonValue }[]; } /** * A transport that answers every query with `value`, or fails with * `error`. */ export function fakeTransport(value: unknown, error?: EngineError): FakeTransport { const calls: { command: string; params: JsonValue }[] = []; return { calls, query: (command, params) => { calls.push({ command, params }); return Promise.resolve(error ? { ok: false, error } : { ok: true, value }); }, }; } /** A buffer that counts idle waits; `onIdle` runs inside each one. */ export function fakeBuffer(id: number, onIdle?: () => void): AssistBuffer & { idleCalls: number } { const buffer = { id, idleCalls: 0, idle: (): Promise => { buffer.idleCalls += 1; onIdle?.(); return Promise.resolve(); }, }; return buffer; }