import { describe, expect, it } from 'vitest'; import { InMemoryMemoryStore, Persona } from '../src'; describe('Persona initialization', () => { it('creates a new isolated persona space from displayName and seed message', async () => { const memory = new InMemoryMemoryStore(); const debug: string[] = []; const persona = new Persona('Mina', 'Mina is a careful student who likes quiet cafes.', { memory, now: '2026-05-01T10:00:00.000Z', debug: (event) => { debug.push(event.name); }, models: { factExtractor: { async extract(input) { return [{ statement: 'Mina likes quiet cafes.', topics: [{ name: 'persona' }, { name: 'Mina' }], source: 'test', }]; }, }, }, }); const space = await persona.ready(); expect(space.displayName).toBe('Mina'); expect(space.id).toMatch(/^persona-mina-/); expect(await memory.findFacts(space.id, ['persona'])).toHaveLength(1); expect(debug).toContain('persona.initialized'); }); it('exposes baseSystemPrompt on the persona instance when provided', async () => { const memory = new InMemoryMemoryStore(); const persona = new Persona('Hana', 'Hana is a cheerful barista.', { memory, now: '2026-05-01T10:00:00.000Z', baseSystemPrompt: 'You are a helpful assistant. Always be kind.', }); await persona.ready(); expect(persona.baseSystemPrompt).toBe('You are a helpful assistant. Always be kind.'); }); it('loads an existing persona space by space id without creating another space', async () => { const memory = new InMemoryMemoryStore(); const created = new Persona('Joon', 'Joon is a freelance designer.', { memory, now: '2026-05-01T10:00:00.000Z' }); const space = await created.ready(); const loaded = new Persona(space.id, { memory, now: '2026-05-01T11:00:00.000Z' }); await expect(loaded.ready()).resolves.toMatchObject({ id: space.id, displayName: 'Joon' }); expect(memory.spaces.size).toBe(1); }); });