feat: add topic alias resolution APIs

This commit is contained in:
2026-05-11 11:53:56 +09:00
parent ba03ecb85b
commit 428f5021e8
9 changed files with 252 additions and 31 deletions

View File

@@ -16,7 +16,7 @@ afterEach(async () => {
});
describe('initializeSchema', () => {
it('creates the topics, facts, fact_topics, and topic_relations tables', async () => {
it('creates the topics, facts, fact_topics, topic_relations, and topic_aliases tables', async () => {
const connection = await createDatabase({ client: 'sqlite', filename: ':memory:' });
openConnections.push(connection.destroy);
@@ -35,6 +35,7 @@ describe('initializeSchema', () => {
expect(tableNames).toContain('facts');
expect(tableNames).toContain('fact_topics');
expect(tableNames).toContain('topic_relations');
expect(tableNames).toContain('topic_aliases');
});
it('creates the expected columns for each table', async () => {
@@ -47,6 +48,7 @@ describe('initializeSchema', () => {
const factsColumns = await sql<{ name: string }>`PRAGMA table_info(facts)`.execute(connection.db);
const factTopicsColumns = await sql<{ name: string }>`PRAGMA table_info(fact_topics)`.execute(connection.db);
const topicRelationsColumns = await sql<{ name: string }>`PRAGMA table_info(topic_relations)`.execute(connection.db);
const topicAliasesColumns = await sql<{ name: string }>`PRAGMA table_info(topic_aliases)`.execute(connection.db);
expect(topicsColumns.rows.map((row) => row.name)).toEqual([
'id',
@@ -85,6 +87,16 @@ describe('initializeSchema', () => {
'relation',
'created_at',
]);
expect(topicAliasesColumns.rows.map((row) => row.name)).toEqual([
'id',
'topic_id',
'alias',
'normalized_alias',
'is_primary',
'created_at',
'updated_at',
]);
});
it('is idempotent when called more than once', async () => {