44 lines
1.7 KiB
TypeScript
44 lines
1.7 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { InMemoryMemoryStore, Persona, type FactDraft } 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: {
|
|
initialization: {
|
|
async extractInitialFacts(input): Promise<FactDraft[]> {
|
|
return [
|
|
{
|
|
statement: `${input.displayName} likes quiet cafes.`,
|
|
topics: ['persona', input.displayName],
|
|
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('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);
|
|
});
|
|
});
|