Skip to content

Private AI meeting notes that stay on your computer. No meeting bot. Free and open source for Mac, Windows and Linux. An alternative to Granola, Otter and Fireflies.

25.1 KB
Raw Blame
import { existsSync, mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { describe, expect, it, vi } from 'vitest'
import { speedKey, validateCatalog, type Catalog, type Hardware } from '@yogurt/picker'
import bundled from '../../catalog/catalog.json'
import licenses from '../../catalog/licenses.json'
import { SetupController, type ParakeetDeps, type SetupDeps, type SpeedDeps, type SpeedResult } from '../src/main/setup'
import { fakeDownloadDeps } from '../src/main/fake'
import { ChecksumError, type DownloadDeps } from '../src/main/downloader'

const catalog = bundled as unknown as Catalog
const mac: Hardware = { os: 'darwin', arch: 'arm64', cpuModel: 'Apple M1 Max', totalRamGB: 32, freeDiskGB: 500, gpu: { kind: 'unified', name: 'Apple M1 Max', vramGB: 24 } }
const cpuPc: Hardware = { os: 'win32', arch: 'x64', cpuModel: 'Intel Core i5-1135G7', totalRamGB: 16, freeDiskGB: 500, gpu: { kind: 'none', name: '', vramGB: 0 }, cores: 8 }
const gpuPc: Hardware = { os: 'linux', arch: 'x64', cpuModel: 'AMD Ryzen 5 5600X', totalRamGB: 16, freeDiskGB: 500, gpu: { kind: 'discrete', name: 'NVIDIA GeForce RTX 3060', vramGB: 12 }, cores: 12 }

const file = (url: string) => decodeURIComponent(new URL(url).pathname.split('/').pop()!)
const asr = (id: string) => catalog.asr.find((a) => a.id === id)!
const PARAKEET = file(catalog.parakeet!.url), BASE = file(asr('whisper-base-q5_1').url), SMALL = file(asr('whisper-small-q5_1').url), TURBO = file(asr('whisper-large-v3-turbo-q5_0').url)

/** downloads that record what was asked for; `hold` keeps chosen files back until released, `fail` makes them arrive damaged */
function recorder(o: { hold?: (name: string) => boolean; fail?: (name: string) => boolean } = {}) {
  const asked: string[] = []
  const released: (() => void)[] = []
  const inner = fakeDownloadDeps({ stepMs: 0 })
  const download: DownloadDeps['download'] = async (url, dir, name, onProgress, signal) => {
    asked.push(file(url))
    if (o.hold?.(file(url))) await new Promise<void>((r) => released.push(r))
    if (o.fail?.(file(url))) throw new ChecksumError('damaged')
    return inner.download(url, dir, name, onProgress, signal)
  }
  return { asked, release: () => released.splice(0).forEach((r) => r()), deps: { ...inner, download } as DownloadDeps }
}

const parakeet = (over: Partial<ParakeetDeps> = {}): ParakeetDeps => ({ off: () => null, wantsWhisper: () => false, quietPollMs: 1, ...over })

/** a profile that already transcribes with these whisper models, as every install before Parakeet does */
function profileWith(...names: string[]) {
  const root = mkdtempSync(join(tmpdir(), 'yogurt-setup-pk-'))
  mkdirSync(join(root, 'asr'), { recursive: true })
  for (const n of names) { writeFileSync(join(root, 'asr', n), 'fake'); writeFileSync(join(root, 'asr', n + '.ok'), 'FAKE') }
  return root
}

function setup(over: Partial<SetupDeps> = {}, rec = recorder()) {
  const root = over.modelsDir ?? mkdtempSync(join(tmpdir(), 'yogurt-setup-pk-'))
  const c = new SetupController({ getHardware: async () => mac, getCatalog: async () => catalog, modelsDir: root, download: rec.deps, sha256Override: 'FAKE', retryDelaysMs: [0, 0], parakeet: parakeet(), ...over })
  return { c, root, rec }
}

/** fake timings per whisper model file, kept in memory */
function speed(rtf: Record<string, number | null>, saved?: SpeedResult) {
  const timed: string[] = []
  let stored = saved
  const deps: SpeedDeps = {
    measure: async (path) => { const id = catalog.asr.find((a) => path.includes(file(a.url)))!.id; timed.push(id); return { rtf: rtf[id] ?? null } },
    load: () => stored, save: (r) => { stored = r },
  }
  return { deps, timed, stored: () => stored }
}

describe('the catalog', () => {
  it('has Parakeet TDT 0.6B v3 q8_0, pinned to a revision with its checksum and size, and names the whisper that hears languages', () => {
    const p = catalog.parakeet!
    expect(p.url).toBe('https://huggingface.co/ggml-org/parakeet-GGUF/resolve/35156454d1a39de06863303dd209fd2bed6ee079/ggml-parakeet-tdt-0.6b-v3-q8_0.bin')
    expect(p.sha256).toBe('4d64e9e96c2792186d072fde0034df0ad670cf680a2f53069052ead827fd600e')
    expect(p.bytes).toBe(668757119)
    expect(p.languageId).toBe('whisper-base-q5_1')
    expect(asr(p.languageId).bytes).toBeLessThan(70e6)
    expect(validateCatalog(bundled, licenses).ok).toBe(true)
  })
  it('a Parakeet entry that names no whisper in the catalog, or a licence not on the list, is refused', () => {
    const bad = validateCatalog({ ...bundled, parakeet: { ...bundled.parakeet, languageId: 'whisper-nowhere' } }, licenses)
    expect(bad.ok).toBe(false)
    expect(validateCatalog(bundled, licenses.filter((l) => l !== 'CC-BY-4.0')).ok).toBe(false)
  })
})

describe('a new install', () => {
  it('a Mac downloads Parakeet and whisper base, nothing bigger, and is ready', async () => {
    const { c, rec } = setup()
    await c.start(); await c.idle()
    expect(c.state.phase).toBe('ready')
    expect(rec.asked.slice(0, 2)).toEqual([PARAKEET, BASE])
    expect(rec.asked).not.toContain(TURBO)
    expect(rec.asked).not.toContain(SMALL)
    const i = c.installed()!
    expect(i.parakeet).toContain(PARAKEET)
    expect(i.lid).toContain(BASE)
    // never without a whisper: the small one reads what Parakeet can't until a bigger one is wanted
    expect(i.asr).toBe(i.lid)
  })
  it('the next start finds both in place and downloads no speech model', async () => {
    const first = setup()
    await first.c.start(); await first.c.idle()
    const again = setup({ modelsDir: first.root })
    await again.c.start(); await again.c.idle()
    expect(again.rec.asked.filter((n) => n.endsWith('.bin'))).toEqual([])
    expect(again.c.installed()).toMatchObject({ parakeet: expect.stringContaining(PARAKEET), lid: expect.stringContaining(BASE) })
  })
  it('the bigger whisper comes in the background once a language Parakeet does not cover is wanted', async () => {
    const { c, rec } = setup()
    await c.start(); await c.idle()
    expect(rec.asked).not.toContain(TURBO)
    c.wantWhisper()
    c.wantWhisper()
    await c.idle()
    expect(rec.asked.filter((n) => n === TURBO)).toHaveLength(1)
    expect(c.installed()).toMatchObject({ asr: expect.stringContaining(TURBO), lid: expect.stringContaining(BASE), parakeet: expect.stringContaining(PARAKEET) })
  })
  it('wanted from the start (the computer speaks a language Parakeet does not cover): ready does not wait for it', async () => {
    const rec = recorder({ hold: (n) => n === TURBO })
    const { c } = setup({ parakeet: parakeet({ wantsWhisper: () => true }) }, rec)
    await c.start()
    expect(c.state.phase).toBe('ready')
    expect(c.installed()!.asr).toContain(BASE)
    await vi.waitFor(() => expect(rec.asked).toContain(TURBO))
    rec.release()
    await c.idle()
    expect(c.installed()!.asr).toContain(TURBO)
  })
  it('Parakeet arriving damaged twice leaves nobody without transcription: whisper as before', async () => {
    const rec = recorder({ fail: (n) => n === PARAKEET })
    const { c } = setup({}, rec)
    await c.start(); await c.idle()
    expect(c.state.phase).toBe('ready')
    expect(c.installed()!.asr).toContain(TURBO)
    expect(c.installed()!.parakeet).toBeUndefined()
  })
})

describe('the kill switch', () => {
  it('with Parakeet off nothing of it is downloaded: turbo as before', async () => {
    const { c, rec } = setup({ parakeet: parakeet({ off: () => 'YOGURT_ASR=whisper' }) })
    const log = vi.spyOn(console, 'info').mockImplementation(() => {})
    try {
      await c.start(); await c.idle()
      expect(rec.asked[0]).toBe(TURBO)
      expect(rec.asked).not.toContain(PARAKEET)
      expect(c.installed()!.parakeet).toBeUndefined()
      expect(log.mock.calls.map((a) => a.join(' ')).join('\n')).toMatch(/ASR Parakeet is not used.*YOGURT_ASR=whisper/)
    } finally { log.mockRestore() }
  })
  it('switched off on an install that has Parakeet: its files stay, and whisper reads everything', async () => {
    const first = setup()
    await first.c.start(); await first.c.idle()
    const off = setup({ modelsDir: first.root, parakeet: parakeet({ off: () => 'YOGURT_ASR=whisper' }) })
    await off.c.start(); await off.c.idle()
    expect(off.c.installed()!.parakeet).toBeUndefined()
    expect(off.c.installed()!.asr).toContain(TURBO)
    expect(existsSync(join(first.root, 'asr', PARAKEET))).toBe(true)
  })
})

describe('an install from before Parakeet', () => {
  it('a Mac is ready at once on the whisper it has, and keeps it until Parakeet is downloaded and checked', async () => {
    const rec = recorder({ hold: (n) => n === PARAKEET })
    const { c } = setup({ modelsDir: profileWith(TURBO) }, rec)
    await c.start()
    expect(c.state.phase).toBe('ready')
    expect(c.installed()).toMatchObject({ asr: expect.stringContaining(TURBO) })
    expect(c.installed()!.parakeet).toBeUndefined()
    await vi.waitFor(() => expect(rec.asked).toContain(PARAKEET))
    // still downloading: whisper only
    expect(c.installed()!.parakeet).toBeUndefined()
    rec.release()
    await c.idle()
    expect(c.installed()).toMatchObject({ asr: expect.stringContaining(TURBO), parakeet: expect.stringContaining(PARAKEET), lid: expect.stringContaining(BASE) })
    expect(rec.asked).toContain(BASE)
  })
  it('a download that fails changes nothing, and the next start tries again', async () => {
    const root = profileWith(TURBO)
    const failing = recorder()
    const real = failing.deps.download
    failing.deps.download = async (url, ...rest) => { if (file(url) === PARAKEET) throw new Error('fetch failed'); return real(url, ...rest) }
    const first = setup({ modelsDir: root }, failing)
    const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
    try {
      await first.c.start(); await first.c.idle()
      expect(first.c.state.phase).toBe('ready')
      expect(first.c.installed()!.asr).toContain(TURBO)
      expect(first.c.installed()!.parakeet).toBeUndefined()
    } finally { warn.mockRestore() }
    const next = setup({ modelsDir: root })
    await next.c.start(); await next.c.idle()
    expect(next.c.installed()!.parakeet).toContain(PARAKEET)
  })
  it('once Parakeet is in, later starts use it from the beginning and keep the bigger whisper for other languages', async () => {
    const root = profileWith(TURBO)
    const first = setup({ modelsDir: root })
    await first.c.start(); await first.c.idle()
    const rec = recorder({ hold: () => true })
    const next = setup({ modelsDir: root }, rec)
    void next.c.start()
    await vi.waitFor(() => expect(next.c.state.phase).toBe('ready'))
    expect(next.c.installed()).toMatchObject({ asr: expect.stringContaining(TURBO), parakeet: expect.stringContaining(PARAKEET), lid: expect.stringContaining(BASE) })
    rec.release()
  })
})

describe('Windows and Linux: Parakeet in the speed check', () => {
  const pkSpeed = (rtf: number | null) => { const timed: string[] = []; return { timed, measure: async (path: string) => { timed.push(path); return rtf } } }

  it('a new install on the processor alone: Parakeet is timed first, and where it keeps up it is the live engine, with whisper base beside it and no other whisper downloaded or timed', async () => {
    const s = speed({ 'whisper-small-q5_1': 0.9, 'whisper-base-q5_1': 0.3 })
    const pk = pkSpeed(0.21)
    const { c, rec } = setup({ getHardware: async () => cpuPc, speed: s.deps, parakeet: parakeet({ measure: pk.measure }) })
    await c.start(); await c.idle()
    expect(c.state.phase).toBe('ready')
    expect(pk.timed).toHaveLength(1)
    expect(s.timed).toEqual([])
    expect(rec.asked.filter((n) => n.startsWith('ggml-'))).toEqual([PARAKEET, BASE])
    expect(c.installed()).toMatchObject({ parakeet: expect.stringContaining(PARAKEET), lid: expect.stringContaining(BASE), asr: expect.stringContaining(BASE) })
    expect(c.installed()!.asrAfterMeeting).toBeUndefined()
    expect(s.stored()).toMatchObject({ key: speedKey(cpuPc), parakeet: 0.21, whisperTimed: false })
  })
  it('the same rule as whisper: over half the clip\'s length does not keep up with two voices, so whisper is picked as before and Parakeet\'s file goes', async () => {
    const s = speed({ 'whisper-small-q5_1': 0.88 })
    const pk = pkSpeed(0.62)
    const { c, root } = setup({ getHardware: async () => cpuPc, speed: s.deps, parakeet: parakeet({ measure: pk.measure }) })
    await c.start(); await c.idle()
    expect(c.installed()!.parakeet).toBeUndefined()
    expect(c.installed()!.asr).toContain(SMALL)
    expect(s.timed).toEqual(['whisper-small-q5_1'])
    expect(existsSync(join(root, 'asr', PARAKEET))).toBe(false)
    expect(s.stored()).toMatchObject({ model: 'whisper-small-q5_1', parakeet: 0.62 })
  })
  it('out of time counts as too slow', async () => {
    const s = speed({ 'whisper-small-q5_1': 2, 'whisper-base-q5_1': 0.4 })
    const { c } = setup({ getHardware: async () => cpuPc, speed: s.deps, parakeet: parakeet({ measure: pkSpeed(null).measure }) })
    await c.start(); await c.idle()
    expect(c.state.phase).toBe('ready')
    expect(c.installed()!.parakeet).toBeUndefined()
    expect(c.installed()!.asr).toContain(BASE)
  })
  it('the stored result is used on the next start: nothing is timed or downloaded again', async () => {
    const s = speed({})
    const pk = pkSpeed(0.21)
    const first = setup({ getHardware: async () => cpuPc, speed: s.deps, parakeet: parakeet({ measure: pk.measure }) })
    await first.c.start(); await first.c.idle()
    const again = setup({ getHardware: async () => cpuPc, speed: s.deps, parakeet: parakeet({ measure: pk.measure }), modelsDir: first.root })
    await again.c.start(); await again.c.idle()
    expect(pk.timed).toHaveLength(1)
    expect(s.timed).toEqual([])
    expect(again.rec.asked.filter((n) => n.startsWith('ggml-'))).toEqual([])
    expect(again.c.installed()).toMatchObject({ parakeet: expect.stringContaining(PARAKEET), asr: expect.stringContaining(BASE) })
  })
  it('a language Parakeet does not cover turns up: the whisper models are timed then, while no meeting runs, and whisper base stays for hearing languages', async () => {
    const s = speed({ 'whisper-small-q5_1': 0.9 })
    let meeting = true
    const { c, root } = setup({ getHardware: async () => cpuPc, speed: s.deps, parakeet: parakeet({ measure: pkSpeed(0.2).measure, quiet: () => !meeting }) })
    await c.start(); await c.idle()
    c.wantWhisper()
    await new Promise((r) => setTimeout(r, 20))
    expect(s.timed).toEqual([])
    meeting = false
    await c.idle()
    expect(s.timed).toEqual(['whisper-small-q5_1'])
    expect(c.installed()).toMatchObject({ asr: expect.stringContaining(SMALL), lid: expect.stringContaining(BASE), parakeet: expect.stringContaining(PARAKEET) })
    expect(existsSync(join(root, 'asr', BASE))).toBe(true)
    expect(s.stored()).toMatchObject({ model: 'whisper-small-q5_1', parakeet: 0.2, whisperTimed: true })
  })
  it('an install from before Parakeet keeps its whisper (here: one that only transcribes after the meeting); Parakeet is fetched, timed while no meeting runs, and takes over live when it keeps up', async () => {
    const saved: SpeedResult = { key: speedKey(cpuPc), model: 'whisper-small-q5_1', rtf: { 'whisper-small-q5_1': 1.6 }, afterMeeting: true, at: 1 }
    const s = speed({}, saved)
    const pk = pkSpeed(0.3)
    let meeting = true
    const rec = recorder({ hold: (n) => n === PARAKEET })
    const { c } = setup({ getHardware: async () => cpuPc, speed: s.deps, modelsDir: profileWith(SMALL), parakeet: parakeet({ measure: pk.measure, quiet: () => !meeting }) }, rec)
    await c.start()
    expect(c.state.phase).toBe('ready')
    expect(c.installed()).toMatchObject({ asr: expect.stringContaining(SMALL), asrAfterMeeting: true })
    expect(c.installed()!.parakeet).toBeUndefined()
    rec.release()
    await new Promise((r) => setTimeout(r, 20))
    // downloaded, but a meeting is on: not timed, not used
    expect(pk.timed).toHaveLength(0)
    expect(c.installed()!.parakeet).toBeUndefined()
    meeting = false
    await c.idle()
    expect(pk.timed).toHaveLength(1)
    expect(c.installed()).toMatchObject({ asr: expect.stringContaining(SMALL), asrAfterMeeting: true, parakeet: expect.stringContaining(PARAKEET), lid: expect.stringContaining(BASE) })
    expect(s.stored()).toMatchObject({ model: 'whisper-small-q5_1', afterMeeting: true, parakeet: 0.3 })
    expect(s.timed).toEqual([])
  })
  it('an install from before Parakeet where it is too slow: its file goes, whisper stays, and it is not fetched again', async () => {
    const saved: SpeedResult = { key: speedKey(gpuPc), model: 'whisper-large-v3-turbo-q5_0', rtf: { 'whisper-large-v3-turbo-q5_0': 0.1 }, at: 1 }
    const s = speed({}, saved)
    const root = profileWith(TURBO)
    const first = setup({ getHardware: async () => gpuPc, speed: s.deps, modelsDir: root, parakeet: parakeet({ measure: pkSpeed(0.8).measure }) })
    await first.c.start(); await first.c.idle()
    expect(first.c.installed()!.parakeet).toBeUndefined()
    expect(first.c.installed()!.asr).toContain(TURBO)
    expect(existsSync(join(root, 'asr', PARAKEET))).toBe(false)
    expect(s.stored()).toMatchObject({ parakeet: 0.8 })
    const next = setup({ getHardware: async () => gpuPc, speed: s.deps, modelsDir: root, parakeet: parakeet({ measure: pkSpeed(0.8).measure }) })
    await next.c.start(); await next.c.idle()
    expect(next.rec.asked).not.toContain(PARAKEET)
  })
  it('with a graphics card too: Parakeet on the processor for its languages, the whisper it had on the card for the rest', async () => {
    const saved: SpeedResult = { key: speedKey(gpuPc), model: 'whisper-large-v3-turbo-q5_0', rtf: { 'whisper-large-v3-turbo-q5_0': 0.1 }, at: 1 }
    const s = speed({}, saved)
    const { c } = setup({ getHardware: async () => gpuPc, speed: s.deps, modelsDir: profileWith(TURBO), parakeet: parakeet({ measure: pkSpeed(0.12).measure }) })
    await c.start(); await c.idle()
    expect(c.installed()).toMatchObject({ asr: expect.stringContaining(TURBO), parakeet: expect.stringContaining(PARAKEET) })
  })
})

describe('Parakeet is tried before it is adopted', () => {
  const quiet = () => { const w = vi.spyOn(console, 'warn').mockImplementation(() => {}); return () => w.mockRestore() }

  it('Windows and Linux, a new install: a speed check that fails outright (the helper will not start) is no setup error; whisper is timed and picked as before', async () => {
    const restore = quiet()
    try {
      const s = speed({ 'whisper-small-q5_1': 0.4 })
      let tries = 0
      const { c, root } = setup({ getHardware: async () => cpuPc, speed: s.deps, parakeet: parakeet({ measure: async () => { tries++; throw new Error('parakeet-server exited (3221225781)') } }) })
      await c.start(); await c.idle()
      expect(c.state.phase).toBe('ready')
      expect(c.installed()!.parakeet).toBeUndefined()
      expect(c.installed()!.asr).toContain(SMALL)
      expect(s.timed).toEqual(['whisper-small-q5_1'])
      // not a time: nothing is stored about Parakeet, so the next start tries it again (the file is still there)
      expect(s.stored()).toMatchObject({ model: 'whisper-small-q5_1' })
      expect(s.stored()).not.toHaveProperty('parakeet')
      expect(existsSync(join(root, 'asr', PARAKEET))).toBe(true)
      // the next start: it works now, and is adopted next to the whisper already picked
      const again = setup({ getHardware: async () => cpuPc, speed: s.deps, modelsDir: root, parakeet: parakeet({ measure: async () => 0.2 }) })
      await again.c.start(); await again.c.idle()
      expect(again.c.installed()).toMatchObject({ asr: expect.stringContaining(SMALL), parakeet: expect.stringContaining(PARAKEET) })
      expect(again.rec.asked).not.toContain(PARAKEET)
      expect(tries).toBe(1)
    } finally { restore() }
  })
  it('an install from before Parakeet: a failing try in the background changes nothing', async () => {
    const restore = quiet()
    try {
      const saved: SpeedResult = { key: speedKey(cpuPc), model: 'whisper-small-q5_1', rtf: { 'whisper-small-q5_1': 0.4 }, at: 1 }
      const s = speed({}, saved)
      const { c } = setup({ getHardware: async () => cpuPc, speed: s.deps, modelsDir: profileWith(SMALL), parakeet: parakeet({ measure: async () => { throw new Error('boom') } }) })
      await c.start(); await c.idle()
      expect(c.state.phase).toBe('ready')
      expect(c.installed()!.parakeet).toBeUndefined()
      expect(s.stored()).not.toHaveProperty('parakeet')
    } finally { restore() }
  })
  it('a Mac tries it once on the bundled clip, the way meetings run it, before a new install adopts it', async () => {
    const tried: string[] = []
    const first = setup({ parakeet: parakeet({ measure: async (m) => { tried.push(m); return 0.01 } }) })
    await first.c.start(); await first.c.idle()
    expect(tried).toHaveLength(1)
    expect(tried[0]).toContain(PARAKEET)
    expect(first.c.installed()!.parakeet).toContain(PARAKEET)
    expect(first.rec.asked).not.toContain(TURBO)
    // it passed: later starts don't try it again
    const next = setup({ modelsDir: first.root, parakeet: parakeet({ measure: async (m) => { tried.push(m); return 0.01 } }) })
    await next.c.start(); await next.c.idle()
    expect(tried).toHaveLength(1)
    expect(next.c.installed()!.parakeet).toContain(PARAKEET)
  })
  it('a Mac where it hears nothing in the clip, or will not run: not adopted, whisper as before, and tried again at the next start', async () => {
    const restore = quiet()
    try {
      for (const broken of [async () => null, async () => { throw new Error('Metal: no device') }]) {
        const first = setup({ parakeet: parakeet({ measure: broken }) })
        await first.c.start(); await first.c.idle()
        expect(first.c.state.phase).toBe('ready')
        expect(first.c.installed()!.parakeet).toBeUndefined()
        expect(first.c.installed()!.asr).toContain(TURBO)
        let tries = 0
        const next = setup({ modelsDir: first.root, parakeet: parakeet({ measure: async () => { tries++; return 0.01 } }) })
        await next.c.start(); await next.c.idle()
        expect(tries).toBe(1)
        expect(next.c.installed()).toMatchObject({ asr: expect.stringContaining(TURBO), parakeet: expect.stringContaining(PARAKEET) })
      }
    } finally { restore() }
  })
  it('a Mac from before Parakeet: downloaded in the background, tried, and only then used', async () => {
    const restore = quiet()
    try {
      const bad = setup({ modelsDir: profileWith(TURBO), parakeet: parakeet({ measure: async () => null }) })
      await bad.c.start(); await bad.c.idle()
      expect(bad.c.installed()!.parakeet).toBeUndefined()
      const good = setup({ modelsDir: profileWith(TURBO), parakeet: parakeet({ measure: async () => 0.01 }) })
      await good.c.start(); await good.c.idle()
      expect(good.c.installed()!.parakeet).toContain(PARAKEET)
    } finally { restore() }
  })
  it('a meeting that starts while Parakeet is timed in the background: that time is thrown away, and it is timed again once the meeting is over', async () => {
    const saved: SpeedResult = { key: speedKey(cpuPc), model: 'whisper-small-q5_1', rtf: { 'whisper-small-q5_1': 0.4 }, at: 1 }
    const s = speed({}, saved)
    let meeting = false, tries = 0
    const measure = async () => { tries++; if (tries === 1) { meeting = true; setTimeout(() => { meeting = false }, 30); return 0.9 } return 0.2 }
    const { c } = setup({ getHardware: async () => cpuPc, speed: s.deps, modelsDir: profileWith(SMALL), parakeet: parakeet({ measure, quiet: () => !meeting }) })
    await c.start(); await c.idle()
    expect(tries).toBe(2)
    expect(s.stored()).toMatchObject({ parakeet: 0.2 })
    expect(c.installed()!.parakeet).toContain(PARAKEET)
  })
  it('the same for the whisper models timed later: a time taken while a meeting started is not kept', async () => {
    let meeting = false, tries = 0
    const stored: { r?: SpeedResult } = {}
    const deps: SpeedDeps = {
      measure: async () => { tries++; if (tries === 1) { meeting = true; setTimeout(() => { meeting = false }, 30); return { rtf: 1.9 } } return { rtf: 0.3 } },
      load: () => stored.r, save: (r) => { stored.r = r },
    }
    const { c } = setup({ getHardware: async () => cpuPc, speed: deps, parakeet: parakeet({ measure: async () => 0.2, quiet: () => !meeting }) })
    await c.start(); await c.idle()
    c.wantWhisper()
    await c.idle()
    expect(tries).toBe(2)
    expect(stored.r).toMatchObject({ model: 'whisper-small-q5_1', rtf: { 'whisper-small-q5_1': 0.3 }, whisperTimed: true })
    expect(c.installed()!.asr).toContain(SMALL)
  })
  it('Windows and Linux: the bigger whisper starts downloading the moment it is wanted, even mid-meeting; only its timing waits', async () => {
    const s = speed({ 'whisper-small-q5_1': 0.3 })
    let meeting = true
    const { c, rec } = setup({ getHardware: async () => cpuPc, speed: s.deps, parakeet: parakeet({ measure: async () => 0.2, quiet: () => !meeting }) })
    await c.start(); await c.idle()
    c.wantWhisper()
    await vi.waitFor(() => expect(rec.asked).toContain(SMALL))
    expect(s.timed).toEqual([])
    meeting = false
    await c.idle()
    expect(s.timed).toEqual(['whisper-small-q5_1'])
  })
  it('tells when the bigger whisper is in, so meetings the small one read can be read again', async () => {
    const { c } = setup()
    const landed: number[] = []
    c.onWhisper(() => landed.push(1))
    await c.start(); await c.idle()
    expect(landed).toEqual([])
    c.wantWhisper()
    await c.idle()
    expect(landed).toEqual([1])
  })
})