feat: bootstrap BoxBrain foundation

This commit is contained in:
2026-05-11 15:56:56 +09:00
parent 964c9b3159
commit 7b474ddac3
15 changed files with 960 additions and 0 deletions

60
tests/memory.test.ts Normal file
View 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();
});
});