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.

6.2 KB
Raw Blame
import { _electron as electron, expect, test, type ElectronApplication } from '@playwright/test'
import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'

// Parakeet reads the languages it covers and whisper the rest (stand-ins, YOGURT_FAKE): what a new install downloads,
// who reads a meeting, the kill switch, and an install from before Parakeet moving over.
// @everywhere: the Windows and Linux runners are those computers; a Mac is itself and pretends to be the other two.
const main = join(import.meta.dirname, '../out/main/index.js')
const PARAKEET = 'ggml-parakeet-tdt-0.6b-v3-q8_0.bin', BASE = 'ggml-base-q5_1.bin', TURBO = 'ggml-large-v3-turbo-q5_0.bin'

const platforms = process.platform === 'darwin' ? ['darwin', 'win32', 'linux'] : [process.platform]
async function launch(env: Record<string, string> = {}, profile = mkdtempSync(join(tmpdir(), 'yogurt-e2e-'))) {
  const app = await electron.launch({ args: [main], env: { ...process.env, YOGURT_FAKE: '1', YOGURT_USER_DATA: profile, ...env } })
  const page = await app.firstWindow()
  await expect(page.getByTestId('home')).toBeVisible({ timeout: 15_000 })
  return { app, page, profile }
}
const fake = <T>(app: ElectronApplication, fn: string, arg?: unknown): Promise<T> =>
  app.evaluate((_e, [fn, arg]) => (globalThis as unknown as Record<string, Record<string, (a?: unknown) => unknown>>).__fake__[fn as string](arg), [fn, arg] as const) as Promise<T>
type Read = { whisper: string[]; engines: string[]; languages: string[] }
const model = (profile: string, name: string) => join(profile, 'models', 'asr', name)
/** the lines saved for the note on screen */
const lines = (page: import('@playwright/test').Page) => page.evaluate(async () => {
  const id = (await window.yogurt.nav.current()).slice('/note/'.length)
  return (await window.yogurt.transcript.get(id)).map((l: { text: string }) => l.text)
})

const record = async (page: import('@playwright/test').Page) => {
  await page.getByTestId('new-note').click()
  await expect(page.getByTestId('note-state')).toHaveAttribute('data-state', 'recording')
}

for (const platform of platforms) {
test(`@everywhere on ${platform}: a new install gets Parakeet and whisper base, and Parakeet reads an English meeting`, async () => {
  const { app, page, profile } = await launch({ YOGURT_FAKE_PLATFORM: platform })
  try {
    expect(existsSync(model(profile, PARAKEET))).toBe(true)
    expect(existsSync(model(profile, BASE))).toBe(true)
    expect(existsSync(model(profile, TURBO))).toBe(false)
    await record(page)
    await expect.poll(async () => (await lines(page)).length, { timeout: 30_000 }).toBeGreaterThanOrEqual(2)
    const read = await fake<Read>(app, 'prompts')
    expect(new Set(read.engines)).toEqual(new Set(['parakeet']))
    // English only is told as before; Parakeet takes no prompt, so whisper was given none
    expect(new Set(read.languages)).toEqual(new Set(['en']))
    expect(read.whisper).toEqual([])
    await page.getByTestId('note-stop').click()
  } finally { await app.close() }
})

test(`@everywhere on ${platform}: the kill switch (YOGURT_ASR=whisper): whisper reads the meeting, as before Parakeet`, async () => {
  const { app, page, profile } = await launch({ YOGURT_FAKE_PLATFORM: platform, YOGURT_ASR: 'whisper' })
  try {
    expect(existsSync(model(profile, PARAKEET))).toBe(false)
    expect(existsSync(model(profile, TURBO))).toBe(true)
    await record(page)
    await expect.poll(async () => (await lines(page)).length, { timeout: 30_000 }).toBeGreaterThanOrEqual(2)
    const read = await fake<Read>(app, 'prompts')
    expect(new Set(read.engines)).toEqual(new Set(['whisper']))
    expect(read.whisper.length).toBeGreaterThan(0)
    await page.getByTestId('note-stop').click()
  } finally { await app.close() }
})


test(`@everywhere on ${platform}: a parakeet-server that will not start is no setup error: whisper is picked as before, and reads the meeting`, async () => {
  const { app, page, profile } = await launch({ YOGURT_FAKE_PLATFORM: platform, YOGURT_FAKE_PARAKEET: 'broken' })
  try {
    await expect(page.getByTestId('setup-error')).toHaveCount(0)
    expect(existsSync(model(profile, TURBO))).toBe(true)
    await record(page)
    await expect.poll(async () => (await lines(page)).length, { timeout: 30_000 }).toBeGreaterThanOrEqual(2)
    expect(new Set((await fake<Read>(app, 'prompts')).engines)).toEqual(new Set(['whisper']))
    await page.getByTestId('note-stop').click()
  } finally { await app.close() }
})
}

test('the hidden setting ("asr": "whisper" in settings.json) does the same as the kill switch', async () => {
  const profile = mkdtempSync(join(tmpdir(), 'yogurt-e2e-'))
  writeFileSync(join(profile, 'settings.json'), JSON.stringify({ asr: 'whisper' }))
  const { app } = await launch({}, profile)
  try {
    expect(existsSync(model(profile, PARAKEET))).toBe(false)
    expect(existsSync(model(profile, TURBO))).toBe(true)
    expect(JSON.parse(readFileSync(join(profile, 'settings.json'), 'utf8')).asr).toBe('whisper')
  } finally { await app.close() }
})

test('an install from before Parakeet opens on the whisper it has, fetches Parakeet in the background, and uses it from then on', async () => {
  // a profile as an earlier version left it: turbo downloaded and checked
  const profile = mkdtempSync(join(tmpdir(), 'yogurt-e2e-'))
  mkdirSync(join(profile, 'models', 'asr'), { recursive: true })
  writeFileSync(model(profile, TURBO), 'fake'); writeFileSync(model(profile, TURBO) + '.ok', 'FAKE')
  const { app, page } = await launch({}, profile)
  try {
    await expect(page.getByTestId('setup-error')).toHaveCount(0)
    await expect.poll(() => existsSync(model(profile, PARAKEET) + '.ok') && existsSync(model(profile, BASE) + '.ok'), { timeout: 30_000 }).toBe(true)
    // the whisper it had stays, for the languages Parakeet doesn't cover
    expect(existsSync(model(profile, TURBO))).toBe(true)
    await record(page)
    await expect.poll(async () => (await fake<Read>(app, 'prompts')).engines.length, { timeout: 30_000 }).toBeGreaterThan(0)
    expect(new Set((await fake<Read>(app, 'prompts')).engines)).toEqual(new Set(['parakeet']))
    await page.getByTestId('note-stop').click()
  } finally { await app.close() }
})