ktx/packages/cli/src/agent-search-readiness.test.ts

52 lines
2.1 KiB
TypeScript
Raw Permalink Normal View History

2026-05-10 23:12:26 +02:00
import { describe, expect, it } from 'vitest';
import {
isMissingProjectConfigError,
missingConnectionSlSearchReadiness,
missingProjectSlSearchReadiness,
noConnectionsSlSearchReadiness,
noIndexedSourcesSlSearchReadiness,
} from './agent-search-readiness.js';
describe('agent semantic-layer search readiness guidance', () => {
it('formats missing project guidance with exact recovery commands', () => {
2026-05-10 23:51:24 +02:00
expect(missingProjectSlSearchReadiness('/tmp/ktx-search', 'gross revenue')).toEqual({
2026-05-10 23:12:26 +02:00
code: 'agent_sl_search_missing_project',
2026-05-10 23:51:24 +02:00
message: 'Semantic-layer search needs an initialized KTX project at /tmp/ktx-search.',
2026-05-10 23:12:26 +02:00
nextSteps: [
2026-05-10 23:51:24 +02:00
'ktx demo',
'ktx setup --project-dir /tmp/ktx-search',
'ktx ingest <connection>',
'ktx agent sl list --json --query "gross revenue" --project-dir /tmp/ktx-search',
2026-05-10 23:12:26 +02:00
],
});
});
it('formats no-connection and no-index guidance without hiding the project path', () => {
2026-05-10 23:51:24 +02:00
expect(noConnectionsSlSearchReadiness('/tmp/ktx-search', 'revenue')).toMatchObject({
2026-05-10 23:12:26 +02:00
code: 'agent_sl_search_no_connections',
2026-05-10 23:51:24 +02:00
message: 'Semantic-layer search found no configured connections in /tmp/ktx-search.',
2026-05-10 23:12:26 +02:00
});
2026-05-10 23:51:24 +02:00
expect(noIndexedSourcesSlSearchReadiness('/tmp/ktx-search', 'orders')).toMatchObject({
2026-05-10 23:12:26 +02:00
code: 'agent_sl_search_no_indexed_sources',
2026-05-10 23:51:24 +02:00
message: 'Semantic-layer search found no indexed semantic-layer sources in /tmp/ktx-search.',
2026-05-10 23:12:26 +02:00
});
});
it('formats unknown connection guidance', () => {
2026-05-10 23:51:24 +02:00
expect(missingConnectionSlSearchReadiness('/tmp/ktx-search', 'warehouse', 'revenue')).toMatchObject({
2026-05-10 23:12:26 +02:00
code: 'agent_sl_search_unknown_connection',
2026-05-10 23:51:24 +02:00
message: 'Semantic-layer search connection "warehouse" is not configured in /tmp/ktx-search.',
2026-05-10 23:12:26 +02:00
});
});
2026-05-10 23:51:24 +02:00
it('detects missing ktx.yaml read errors', () => {
2026-05-10 23:12:26 +02:00
const error = Object.assign(new Error('ENOENT: no such file or directory'), {
code: 'ENOENT',
2026-05-10 23:51:24 +02:00
path: '/tmp/ktx-search/ktx.yaml',
2026-05-10 23:12:26 +02:00
});
expect(isMissingProjectConfigError(error)).toBe(true);
expect(isMissingProjectConfigError(new Error('other'))).toBe(false);
});
});