import { describe, it, expect, beforeAll } from 'vitest'; import { resetDb } from '../helpers/db.js'; import { migrateUp } from '../../lib/db/migrate.js'; import * as agents from '../../lib/db/repos/agents.js'; import * as conversations from '../../lib/db/repos/conversations.js'; const owner = { kind: 'user', id: null }; beforeAll(async () => { await resetDb(); await migrateUp(); }); describe('findOrCreateGlobal', () => { it('creates one space-less open conversation and reuses it', async () => { const y = await agents.getBySlug('yerin'); // seeded by 011_yerin.sql const c1 = await conversations.findOrCreateGlobal(y.id, owner); expect(c1.space_id).toBeNull(); expect(c1.agent_id).toBe(y.id); const c2 = await conversations.findOrCreateGlobal(y.id, owner); expect(c2.id).toBe(c1.id); }); });