mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-13 08:15:14 +02:00
Align the tree with AGENTS.md/CLAUDE.md conventions: - Rewrite user-facing strings, docs, and tests to lowercase `ktx` (no bare uppercase `KTX` tokens remain outside literal identifiers). - Drop the legacy `historicSql` migration path and its now-unused helpers, per the no-backward-compat rule. - Remove `as unknown as` / `any` casts: narrow `BaseTool` generics to `z.ZodObject`, add a typed `createLookerClient`, and delete the dead `getParametersSchema`/`toAnthropicFormat` pre-AI-SDK helpers. - Use `InvalidArgumentError` for Commander parse failures. - Finish the adapter→connector prose conversion in the `ktx.yaml` docs while keeping the literal `adapters` config key.
119 lines
4.6 KiB
TypeScript
119 lines
4.6 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import {
|
|
classifyKtxSetupCompletion,
|
|
runKtxSetupReadyChangeMenu,
|
|
runKtxSetupReadyMenu,
|
|
} from '../src/setup-ready-menu.js';
|
|
import type { KtxSetupStatus } from '../src/setup.js';
|
|
|
|
const readyStatus: KtxSetupStatus = {
|
|
project: { path: '/tmp/revenue', ready: true },
|
|
llm: { backend: 'anthropic', ready: true, model: 'claude-sonnet-4-6' },
|
|
embeddings: { backend: 'openai', ready: true, model: 'text-embedding-3-small', dimensions: 1536 },
|
|
databases: [{ connectionId: 'warehouse', ready: true }],
|
|
sources: [],
|
|
runtime: { required: false, ready: true, features: [] },
|
|
context: { ready: true, status: 'completed' },
|
|
agents: [{ target: 'codex', scope: 'project', ready: true }],
|
|
};
|
|
|
|
describe('classifyKtxSetupCompletion', () => {
|
|
it('reports ready only when config, context, and agents are all ready', () => {
|
|
expect(classifyKtxSetupCompletion(readyStatus)).toBe('ready');
|
|
});
|
|
|
|
it('reports needs-agents when config and context are ready but no agent is installed', () => {
|
|
expect(classifyKtxSetupCompletion({ ...readyStatus, agents: [] })).toBe('needs-agents');
|
|
});
|
|
|
|
it('reports needs-context when config is ready but context is not built', () => {
|
|
expect(
|
|
classifyKtxSetupCompletion({ ...readyStatus, context: { ready: false, status: 'not_started' } }),
|
|
).toBe('needs-context');
|
|
});
|
|
|
|
it('reports incomplete when a required config section is not ready', () => {
|
|
expect(classifyKtxSetupCompletion({ ...readyStatus, embeddings: { ready: false } })).toBe('incomplete');
|
|
expect(
|
|
classifyKtxSetupCompletion({ ...readyStatus, runtime: { required: true, ready: false, features: ['core'] } }),
|
|
).toBe('incomplete');
|
|
});
|
|
|
|
it('reports incomplete when no context targets are configured', () => {
|
|
expect(classifyKtxSetupCompletion({ ...readyStatus, databases: [], sources: [] })).toBe('incomplete');
|
|
});
|
|
});
|
|
|
|
describe('runKtxSetupReadyMenu', () => {
|
|
it('exits when the user is done', async () => {
|
|
const prompts = { select: vi.fn(async () => 'done'), cancel: vi.fn() };
|
|
|
|
await expect(runKtxSetupReadyMenu(readyStatus, { prompts })).resolves.toEqual({ action: 'exit' });
|
|
|
|
expect(prompts.select).toHaveBeenCalledTimes(1);
|
|
expect(prompts.select).toHaveBeenCalledWith({
|
|
message: 'Anything else?',
|
|
options: [
|
|
{ value: 'done', label: "Done — I'll start using ktx" },
|
|
{ value: 'change', label: 'Change a setting' },
|
|
],
|
|
});
|
|
});
|
|
|
|
it('opens the section menu when the user chooses to change a setting', async () => {
|
|
const select = vi.fn().mockResolvedValueOnce('change').mockResolvedValueOnce('models');
|
|
const prompts = { select, cancel: vi.fn() };
|
|
|
|
await expect(runKtxSetupReadyMenu(readyStatus, { prompts })).resolves.toEqual({ action: 'models' });
|
|
|
|
expect(select).toHaveBeenCalledTimes(2);
|
|
expect(select).toHaveBeenLastCalledWith({
|
|
message: 'What would you like to change?',
|
|
options: [
|
|
{ value: 'models', label: 'Models' },
|
|
{ value: 'embeddings', label: 'Embeddings' },
|
|
{ value: 'databases', label: 'Databases' },
|
|
{ value: 'sources', label: 'Context sources' },
|
|
{ value: 'context', label: 'Rebuild ktx context' },
|
|
{ value: 'agents', label: 'Agent integration' },
|
|
{ value: 'exit', label: 'Exit' },
|
|
],
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('runKtxSetupReadyChangeMenu', () => {
|
|
it('maps ready-project menu choices to setup sections', async () => {
|
|
const prompts = { select: vi.fn(async () => 'agents'), cancel: vi.fn() };
|
|
|
|
await expect(runKtxSetupReadyChangeMenu(readyStatus, { prompts })).resolves.toEqual({ action: 'agents' });
|
|
|
|
expect(prompts.select).toHaveBeenCalledWith({
|
|
message: 'What would you like to change?',
|
|
options: [
|
|
{ value: 'models', label: 'Models' },
|
|
{ value: 'embeddings', label: 'Embeddings' },
|
|
{ value: 'databases', label: 'Databases' },
|
|
{ value: 'sources', label: 'Context sources' },
|
|
{ value: 'context', label: 'Rebuild ktx context' },
|
|
{ value: 'agents', label: 'Agent integration' },
|
|
{ value: 'exit', label: 'Exit' },
|
|
],
|
|
});
|
|
});
|
|
|
|
it('includes the runtime option only when the runtime is required', async () => {
|
|
const prompts = { select: vi.fn(async () => 'runtime'), cancel: vi.fn() };
|
|
|
|
await runKtxSetupReadyChangeMenu(
|
|
{ ...readyStatus, runtime: { required: true, ready: true, features: ['core'] } },
|
|
{ prompts },
|
|
);
|
|
|
|
expect(prompts.select).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
options: expect.arrayContaining([{ value: 'runtime', label: 'Runtime' }]),
|
|
}),
|
|
);
|
|
});
|
|
});
|