feat: add topic hierarchy APIs

This commit is contained in:
2026-05-11 11:46:10 +09:00
parent d95ac8c1a0
commit ba03ecb85b
9 changed files with 223 additions and 2 deletions

View File

@@ -19,6 +19,16 @@ async function seedMemoryGraph(db: IdentityDB): Promise<void> {
{ name: 'programming language', category: 'concept', granularity: 'abstract', role: 'classification' },
],
});
await db.linkTopics({
parentName: 'software technology',
childName: 'programming language',
});
await db.linkTopics({
parentName: 'programming language',
childName: 'TypeScript',
});
}
describe('IdentityDB queries', () => {
@@ -60,6 +70,7 @@ describe('IdentityDB queries', () => {
'2025',
'I',
'programming language',
'software technology',
'TypeScript',
]);
expect('facts' in topics[0]!).toBe(false);
@@ -81,4 +92,25 @@ describe('IdentityDB queries', () => {
expect(facts).toHaveLength(1);
expect(facts[0]?.statement).toBe('I have worked with TypeScript since 2025.');
});
it('lists direct child topics for a parent topic', async () => {
const children = await db.getTopicChildren('programming language');
expect(children.map((topic) => topic.name)).toEqual(['TypeScript']);
});
it('lists direct parent topics for a child topic', async () => {
const parents = await db.getTopicParents('TypeScript');
expect(parents.map((topic) => topic.name)).toEqual(['programming language']);
});
it('returns lineage from nearest parent outward', async () => {
const lineage = await db.getTopicLineage('TypeScript');
expect(lineage.map((topic) => topic.name)).toEqual([
'programming language',
'software technology',
]);
});
});