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.

4.8 KB
Raw Blame
import { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, expect, it } from 'vitest'
import { openStore } from '../src/main/store'
import { parseEvents, setCalendarOwnEmail } from '../src/main/calendar'
import { initMeetings, linkEvent, prepareMeeting, refreshEventSnapshots, startMeeting, stopMeeting, unlinkEvent } from '../src/main/meeting'
import { mergeBackup } from '../src/main/backup'
import { groupPeople, matchingOwnEmail, normalizedEmail } from '../src/shared/people'

const people = [{ name: 'Attendee One', email: '[email protected]' }, { name: 'Attendee Two', email: '[email protected]' }]
const note = { title: 'Planning', startedAt: 1, endedAt: 2, eventId: null, app: null, attendees: people, state: 'done' as const }
const event = { id: 'invite', title: 'Planning', start: 1, end: 2, attendees: people, url: null, ownEmail: '[email protected]' }
afterEach(() => setCalendarOwnEmail(() => {}))

it('uses only a valid, known own address with an exact matching attendee domain', () => {
  expect(matchingOwnEmail(people, ['[email protected]', '[email protected]'])).toBe('[email protected]')
  expect(matchingOwnEmail(people, ['[email protected]', '[email protected]'])).toBeNull()
  expect(matchingOwnEmail(people, [])).toBeNull()
  expect(matchingOwnEmail([], ['[email protected]'])).toBeNull()
  expect(matchingOwnEmail(people, ['[email protected]', '[email protected]'])).toBe('[email protected]')
  for (const value of [null, {}, '', 'not-email', 'two@@studio.example', 'two@studio', 'two [email protected]']) expect(normalizedEmail(value)).toBeNull()
})

it('keeps the helper own address on its event without adding it to attendees', () => {
  const known: string[] = []
  setCalendarOwnEmail(email => { known.push(email) })
  const row = { id: 'event', start: '2026-11-01T10:00:00Z', end: '2026-11-01T11:00:00Z', me: ' [email protected] ', attendees: people }
  expect(parseEvents([row])[0]).toMatchObject({ ownEmail: '[email protected]', attendees: people })
  expect(known).toEqual(['[email protected]'])
  expect(parseEvents([{ ...row, me: 'bad' }])[0].ownEmail).toBeUndefined()
  parseEvents([{ me: '[email protected]' }]); expect(known).toEqual(['[email protected]'])
})

it('saves the event address for prepared, started and later-linked notes, and refreshes old snapshots', () => {
  const store = openStore(':memory:'); initMeetings(store)
  try {
    const prepared = prepareMeeting(event)
    expect(prepared.ownEmail).toBe(event.ownEmail)
    const started = startMeeting({ title: 'Planning', app: null, event: { ...event, id: 'other' } })
    expect(started.ownEmail).toBe(event.ownEmail); stopMeeting(started.id)
    const m = store.createMeeting(note)
    expect(linkEvent(m.id, { ...event, ownEmail: '[email protected]' })?.ownEmail).toBe('[email protected]')
    expect(unlinkEvent(m.id)?.ownEmail).toBe('[email protected]')
    store.updateMeeting(m.id, { attendees: [{ name: 'Visitor', email: '[email protected]' }] })
    expect(store.meeting(m.id)?.ownEmail).toBeUndefined()
    const old = store.createMeeting({ ...note, eventId: event.id })
    expect(old.ownEmail).toBeUndefined()
    refreshEventSnapshots([event])
    expect(store.meeting(old.id)?.ownEmail).toBe(event.ownEmail)
    expect(store.meeting(old.id)?.attendees).toEqual(people)
    refreshEventSnapshots([]); expect(store.meeting(old.id)?.ownEmail).toBe(event.ownEmail)
    const rows = [{ p: { name: 'Sample Self', email: store.meeting(old.id)!.ownEmail! }, mine: true }, ...people.map(p => ({ p }))]
    expect(groupPeople(rows).find(g => g.domain === 'studio.example')?.people).toEqual([rows[0], rows[1]])
  } finally { store.close() }
})

it('retains event and fallback addresses after reopening without calendar access, and merges them in backups', () => {
  const dir = mkdtempSync(join(tmpdir(), 'yogurt-own-')), file = join(dir, 'notes.db')
  let store = openStore(file)
  const into = openStore(':memory:')
  try {
    const linked = store.createMeeting({ ...note, eventId: event.id, ownEmail: event.ownEmail })
    const unlinked = store.createMeeting(note)
    store.rememberOwnEmail('[email protected]')
    store.close(); store = openStore(file)
    expect(store.meeting(linked.id)?.ownEmail).toBe(event.ownEmail)
    expect(store.meeting(unlinked.id)?.ownEmail).toBe('[email protected]')
    into.rememberOwnEmail('[email protected]')
    mergeBackup(into.db, store.db)
    expect(into.meeting(linked.id)?.ownEmail).toBe(event.ownEmail)
    expect(into.meeting(unlinked.id)?.ownEmail).toBe('[email protected]')
    expect(into.ownEmails()).toEqual(['[email protected]', '[email protected]', '[email protected]'])
  } finally { store.close(); into.close(); rmSync(dir, { recursive: true, force: true }) }
})