feat: bootstrap BoxBrain foundation
This commit is contained in:
60
tests/memory.test.ts
Normal file
60
tests/memory.test.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { afterEach, describe, expect, it } from 'vitest';
|
||||
import { IdentityDB } from 'identitydb';
|
||||
import { persistFactDrafts } from '../src/memory';
|
||||
|
||||
const openDbs: IdentityDB[] = [];
|
||||
|
||||
async function createDb() {
|
||||
const db = await IdentityDB.connect({ client: 'sqlite', filename: ':memory:' });
|
||||
await db.initialize();
|
||||
openDbs.push(db);
|
||||
return db;
|
||||
}
|
||||
|
||||
afterEach(async () => {
|
||||
while (openDbs.length > 0) {
|
||||
await openDbs.pop()!.close();
|
||||
}
|
||||
});
|
||||
|
||||
describe('persistFactDrafts', () => {
|
||||
it('stores drafted facts in the requested persona space', async () => {
|
||||
const db = await createDb();
|
||||
|
||||
const [fact] = await persistFactDrafts(db, {
|
||||
spaceName: 'persona:minji',
|
||||
domain: 'persona.biography',
|
||||
source: 'boxbrain:test',
|
||||
facts: [
|
||||
{
|
||||
statement: 'Minji grew up near the sea.',
|
||||
topics: [{ name: 'Minji' }, { name: 'sea' }],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const space = await db.getSpaceByName('persona:minji');
|
||||
expect(space).not.toBeNull();
|
||||
expect(fact?.spaceId).toBe(space?.id);
|
||||
expect(fact?.metadata).toMatchObject({
|
||||
boxbrain: {
|
||||
domain: 'persona.biography',
|
||||
source: 'boxbrain:test',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('accepts an empty draft list without writes', async () => {
|
||||
const db = await createDb();
|
||||
|
||||
const facts = await persistFactDrafts(db, {
|
||||
spaceName: 'persona:empty',
|
||||
domain: 'persona.biography',
|
||||
source: 'boxbrain:test',
|
||||
facts: [],
|
||||
});
|
||||
|
||||
expect(facts).toEqual([]);
|
||||
expect(await db.getSpaceByName('persona:empty')).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user