feat: add topic alias resolution APIs
This commit is contained in:
@@ -51,4 +51,41 @@ describe('IdentityDB topic and fact writes', () => {
|
||||
expect(typeScriptFacts).toHaveLength(1);
|
||||
expect(typeScriptFacts[0]?.statement).toBe('I have worked with TypeScript since 2025.');
|
||||
});
|
||||
|
||||
it('resolves alias names to a canonical topic', async () => {
|
||||
await db.upsertTopic({
|
||||
name: 'TypeScript',
|
||||
category: 'entity',
|
||||
granularity: 'concrete',
|
||||
});
|
||||
|
||||
await db.addTopicAlias('TypeScript', 'TS');
|
||||
|
||||
const resolved = await db.resolveTopic('ts');
|
||||
const aliases = await db.getTopicAliases('TypeScript');
|
||||
|
||||
expect(resolved?.name).toBe('TypeScript');
|
||||
expect(aliases).toEqual(['TS']);
|
||||
});
|
||||
|
||||
it('reuses the canonical topic when a fact is added through an alias', async () => {
|
||||
await db.upsertTopic({
|
||||
name: 'TypeScript',
|
||||
category: 'entity',
|
||||
granularity: 'concrete',
|
||||
});
|
||||
|
||||
await db.addTopicAlias('TypeScript', 'TS');
|
||||
|
||||
await db.addFact({
|
||||
statement: 'TS compiles to JavaScript.',
|
||||
topics: [{ name: 'TS', category: 'entity', granularity: 'concrete' }],
|
||||
});
|
||||
|
||||
const topics = await db.listTopics({ includeFacts: false });
|
||||
const facts = await db.getTopicFacts('TypeScript');
|
||||
|
||||
expect(topics.map((topic) => topic.name)).toEqual(['TypeScript']);
|
||||
expect(facts.map((fact) => fact.statement)).toEqual(['TS compiles to JavaScript.']);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user