rename klo to ktx

This commit is contained in:
Andrey Avtomonov 2026-05-10 23:51:24 +02:00
parent 1a42152e6f
commit 3ce510b55b
704 changed files with 10205 additions and 10255 deletions

View file

@ -1,9 +1,9 @@
import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { initKloProject, parseKloProjectConfig } from '@klo/context/project';
import { initKtxProject, parseKtxProjectConfig } from '@ktx/context/project';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { type KloSetupProjectPromptAdapter, runKloSetupProjectStep } from './setup-project.js';
import { type KtxSetupProjectPromptAdapter, runKtxSetupProjectStep } from './setup-project.js';
function makeIo(options: { stdoutIsTty?: boolean } = {}) {
let stdout = '';
@ -34,14 +34,14 @@ function makePromptAdapter(options: { choice?: string; choices?: string[]; textV
select: vi.fn(async () => choices.shift() ?? 'exit'),
text: vi.fn(async () => textValues.shift() ?? ''),
cancel: vi.fn(),
} satisfies KloSetupProjectPromptAdapter;
} satisfies KtxSetupProjectPromptAdapter;
}
describe('setup project step', () => {
let tempDir: string;
beforeEach(async () => {
tempDir = await mkdtemp(join(tmpdir(), 'klo-setup-project-'));
tempDir = await mkdtemp(join(tmpdir(), 'ktx-setup-project-'));
});
afterEach(async () => {
@ -52,26 +52,26 @@ describe('setup project step', () => {
const projectDir = join(tempDir, 'warehouse');
const testIo = makeIo();
const result = await runKloSetupProjectStep(
const result = await runKtxSetupProjectStep(
{ projectDir, mode: 'new', inputMode: 'disabled', yes: false },
testIo.io,
);
expect(result.status).toBe('ready');
expect(result.projectDir).toBe(projectDir);
const config = parseKloProjectConfig(await readFile(join(projectDir, 'klo.yaml'), 'utf-8'));
const config = parseKtxProjectConfig(await readFile(join(projectDir, 'ktx.yaml'), 'utf-8'));
expect(config.setup?.completed_steps).toEqual(['project']);
await expect(stat(join(projectDir, '.git'))).resolves.toBeDefined();
await expect(readFile(join(projectDir, '.klo/.gitignore'), 'utf-8')).resolves.toContain('secrets/');
await expect(readFile(join(projectDir, '.ktx/.gitignore'), 'utf-8')).resolves.toContain('secrets/');
expect(testIo.stdout()).toContain(`Project: ${projectDir}`);
expect(testIo.stderr()).toBe('');
});
it('loads an existing project with --existing and preserves existing setup metadata', async () => {
const projectDir = join(tempDir, 'warehouse');
await initKloProject({ projectDir, projectName: 'warehouse' });
await initKtxProject({ projectDir, projectName: 'warehouse' });
await writeFile(
join(projectDir, 'klo.yaml'),
join(projectDir, 'ktx.yaml'),
[
'project: warehouse',
'setup:',
@ -84,13 +84,13 @@ describe('setup project step', () => {
'utf-8',
);
const result = await runKloSetupProjectStep(
const result = await runKtxSetupProjectStep(
{ projectDir, mode: 'existing', inputMode: 'disabled', yes: false },
makeIo().io,
);
expect(result.status).toBe('ready');
const config = parseKloProjectConfig(await readFile(join(projectDir, 'klo.yaml'), 'utf-8'));
const config = parseKtxProjectConfig(await readFile(join(projectDir, 'ktx.yaml'), 'utf-8'));
expect(config.setup).toEqual({
database_connection_ids: ['warehouse'],
completed_steps: ['llm', 'project'],
@ -103,26 +103,26 @@ describe('setup project step', () => {
const acceptedIo = makeIo();
await expect(
runKloSetupProjectStep({ projectDir, mode: 'auto', inputMode: 'disabled', yes: false }, rejectedIo.io),
runKtxSetupProjectStep({ projectDir, mode: 'auto', inputMode: 'disabled', yes: false }, rejectedIo.io),
).resolves.toMatchObject({ status: 'missing-input' });
expect(rejectedIo.stderr()).toContain('Missing setup choice: pass --new or --yes');
await expect(stat(join(projectDir, 'klo.yaml'))).rejects.toThrow();
await expect(stat(join(projectDir, 'ktx.yaml'))).rejects.toThrow();
await expect(
runKloSetupProjectStep({ projectDir, mode: 'auto', inputMode: 'disabled', yes: true }, acceptedIo.io),
runKtxSetupProjectStep({ projectDir, mode: 'auto', inputMode: 'disabled', yes: true }, acceptedIo.io),
).resolves.toMatchObject({ status: 'ready', projectDir });
await expect(stat(join(projectDir, 'klo.yaml'))).resolves.toBeDefined();
await expect(stat(join(projectDir, 'ktx.yaml'))).resolves.toBeDefined();
});
it('fails --existing clearly when klo.yaml is missing', async () => {
it('fails --existing clearly when ktx.yaml is missing', async () => {
const projectDir = join(tempDir, 'warehouse');
const testIo = makeIo();
await expect(
runKloSetupProjectStep({ projectDir, mode: 'existing', inputMode: 'disabled', yes: false }, testIo.io),
runKtxSetupProjectStep({ projectDir, mode: 'existing', inputMode: 'disabled', yes: false }, testIo.io),
).resolves.toMatchObject({ status: 'missing-input' });
expect(testIo.stderr()).toContain(`No existing KLO project found at ${projectDir}`);
expect(testIo.stderr()).toContain(`No existing KTX project found at ${projectDir}`);
});
it('prompts to use the current directory and creates a project in interactive auto mode', async () => {
@ -130,7 +130,7 @@ describe('setup project step', () => {
const prompts = makePromptAdapter({ choice: 'current' });
const testIo = makeIo({ stdoutIsTty: true });
const result = await runKloSetupProjectStep(
const result = await runKtxSetupProjectStep(
{ projectDir, mode: 'auto', inputMode: 'auto', yes: false },
testIo.io,
{ prompts },
@ -140,7 +140,7 @@ describe('setup project step', () => {
expect(result.projectDir).toBe(projectDir);
expect(prompts.select).toHaveBeenCalledWith(
expect.objectContaining({
message: 'Which KLO project should setup use?',
message: 'Which KTX project should setup use?',
options: [
expect.objectContaining({ value: 'current', label: 'Use current directory' }),
expect.objectContaining({ value: 'new', label: 'Create a new project folder' }),
@ -149,17 +149,17 @@ describe('setup project step', () => {
}),
);
expect(prompts.text).not.toHaveBeenCalled();
const config = parseKloProjectConfig(await readFile(join(projectDir, 'klo.yaml'), 'utf-8'));
const config = parseKtxProjectConfig(await readFile(join(projectDir, 'ktx.yaml'), 'utf-8'));
expect(config.setup?.completed_steps).toEqual(['project']);
});
it('offers an absolute default destination for a new project folder', async () => {
const startDir = join(tempDir, 'start');
const projectDir = join(startDir, 'klo-project');
const projectDir = join(startDir, 'ktx-project');
const prompts = makePromptAdapter({ choices: ['new', 'default', 'create'] });
const testIo = makeIo({ stdoutIsTty: true });
const result = await runKloSetupProjectStep(
const result = await runKtxSetupProjectStep(
{ projectDir: startDir, mode: 'auto', inputMode: 'auto', yes: false },
testIo.io,
{ prompts },
@ -170,7 +170,7 @@ describe('setup project step', () => {
expect(prompts.select).toHaveBeenNthCalledWith(
2,
expect.objectContaining({
message: 'Where should KLO create the project?',
message: 'Where should KTX create the project?',
options: [
expect.objectContaining({
value: 'default',
@ -183,20 +183,20 @@ describe('setup project step', () => {
);
expect(prompts.select).toHaveBeenNthCalledWith(
3,
expect.objectContaining({ message: `Create KLO project at ${projectDir}?` }),
expect.objectContaining({ message: `Create KTX project at ${projectDir}?` }),
);
expect(prompts.text).not.toHaveBeenCalled();
expect(result.status === 'ready' ? result.project.config.project : '').toBe('klo-project');
expect(testIo.stdout()).toContain(`KLO will create:\n ${projectDir}`);
await expect(stat(join(projectDir, 'klo.yaml'))).resolves.toBeDefined();
expect(result.status === 'ready' ? result.project.config.project : '').toBe('ktx-project');
expect(testIo.stdout()).toContain(`KTX will create:\n ${projectDir}`);
await expect(stat(join(projectDir, 'ktx.yaml'))).resolves.toBeDefined();
});
it('prompts for a custom path and resolves it inside the current setup directory', async () => {
const startDir = join(tempDir, 'start');
const projectDir = join(startDir, 'analytics-klo');
const prompts = makePromptAdapter({ choices: ['new', 'custom', 'create'], textValue: 'analytics-klo' });
const projectDir = join(startDir, 'analytics-ktx');
const prompts = makePromptAdapter({ choices: ['new', 'custom', 'create'], textValue: 'analytics-ktx' });
const result = await runKloSetupProjectStep(
const result = await runKtxSetupProjectStep(
{ projectDir: startDir, mode: 'auto', inputMode: 'auto', yes: false },
makeIo({ stdoutIsTty: true }).io,
{ prompts },
@ -207,19 +207,19 @@ describe('setup project step', () => {
expect(prompts.text).toHaveBeenCalledWith(
expect.objectContaining({
message: 'Project folder path\nPress Escape to go back.\n',
placeholder: './analytics-klo, ~/analytics-klo, or /Users/you/projects/analytics-klo',
placeholder: './analytics-ktx, ~/analytics-ktx, or /Users/you/projects/analytics-ktx',
}),
);
await expect(stat(join(projectDir, 'klo.yaml'))).resolves.toBeDefined();
await expect(stat(join(projectDir, 'ktx.yaml'))).resolves.toBeDefined();
});
it('expands a custom home-directory path before creating a new project', async () => {
const startDir = join(tempDir, 'start');
const homeDir = join(tempDir, 'home');
const projectDir = join(homeDir, 'analytics-klo');
const prompts = makePromptAdapter({ choices: ['new', 'custom', 'create'], textValue: '~/analytics-klo' });
const projectDir = join(homeDir, 'analytics-ktx');
const prompts = makePromptAdapter({ choices: ['new', 'custom', 'create'], textValue: '~/analytics-ktx' });
const result = await runKloSetupProjectStep(
const result = await runKtxSetupProjectStep(
{ projectDir: startDir, mode: 'auto', inputMode: 'auto', yes: false },
makeIo({ stdoutIsTty: true }).io,
{ prompts, homeDir },
@ -227,19 +227,19 @@ describe('setup project step', () => {
expect(result.status).toBe('ready');
expect(result.projectDir).toBe(projectDir);
await expect(stat(join(projectDir, 'klo.yaml'))).resolves.toBeDefined();
await expect(stat(join(projectDir, 'ktx.yaml'))).resolves.toBeDefined();
});
it('confirms a custom new project path and lets Back return to the project choice', async () => {
const startDir = join(tempDir, 'start');
const homeDir = join(tempDir, 'home');
const customProjectDir = join(homeDir, 'analytics-klo');
const customProjectDir = join(homeDir, 'analytics-ktx');
const prompts = makePromptAdapter({
choices: ['new', 'custom', 'back', 'exit'],
textValue: '~/analytics-klo',
textValue: '~/analytics-ktx',
});
const result = await runKloSetupProjectStep(
const result = await runKtxSetupProjectStep(
{ projectDir: startDir, mode: 'auto', inputMode: 'auto', yes: false },
makeIo({ stdoutIsTty: true }).io,
{ prompts, homeDir },
@ -250,7 +250,7 @@ describe('setup project step', () => {
expect(prompts.select).toHaveBeenNthCalledWith(
3,
expect.objectContaining({
message: `Create KLO project at ${customProjectDir}?`,
message: `Create KTX project at ${customProjectDir}?`,
options: [
expect.objectContaining({ value: 'create', label: 'Create project' }),
expect.objectContaining({ value: 'choose-another', label: 'Choose another folder' }),
@ -260,9 +260,9 @@ describe('setup project step', () => {
);
expect(prompts.select).toHaveBeenNthCalledWith(
4,
expect.objectContaining({ message: 'Which KLO project should setup use?' }),
expect.objectContaining({ message: 'Which KTX project should setup use?' }),
);
await expect(stat(join(customProjectDir, 'klo.yaml'))).rejects.toThrow();
await expect(stat(join(customProjectDir, 'ktx.yaml'))).rejects.toThrow();
});
it('rejects an empty new folder path without creating a project in the process cwd', async () => {
@ -274,7 +274,7 @@ describe('setup project step', () => {
const testIo = makeIo({ stdoutIsTty: true });
await expect(
runKloSetupProjectStep(
runKtxSetupProjectStep(
{ projectDir: startDir, mode: 'auto', inputMode: 'auto', yes: false },
testIo.io,
{ prompts, initProject },
@ -283,18 +283,18 @@ describe('setup project step', () => {
expect(initProject).not.toHaveBeenCalled();
expect(testIo.stderr()).toContain(
'Enter a relative path like ./analytics-klo, a home path like ~/analytics-klo, or an absolute path.',
'Enter a relative path like ./analytics-ktx, a home path like ~/analytics-ktx, or an absolute path.',
);
});
it('confirms before creating KLO files inside an existing non-empty folder', async () => {
it('confirms before creating KTX files inside an existing non-empty folder', async () => {
const startDir = join(tempDir, 'start');
const projectDir = join(startDir, 'analytics-klo');
const projectDir = join(startDir, 'analytics-ktx');
await mkdir(projectDir, { recursive: true });
await writeFile(join(projectDir, 'README.md'), 'Existing project notes\n', 'utf-8');
const prompts = makePromptAdapter({ choices: ['new', 'custom', 'use-existing'], textValue: 'analytics-klo' });
const prompts = makePromptAdapter({ choices: ['new', 'custom', 'use-existing'], textValue: 'analytics-ktx' });
const result = await runKloSetupProjectStep(
const result = await runKtxSetupProjectStep(
{ projectDir: startDir, mode: 'auto', inputMode: 'auto', yes: false },
makeIo({ stdoutIsTty: true }).io,
{ prompts },
@ -307,13 +307,13 @@ describe('setup project step', () => {
expect.objectContaining({
message: `That folder already exists and is not empty: ${projectDir}`,
options: expect.arrayContaining([
expect.objectContaining({ value: 'use-existing', label: 'Yes, create KLO files there' }),
expect.objectContaining({ value: 'use-existing', label: 'Yes, create KTX files there' }),
expect.objectContaining({ value: 'choose-another', label: 'Choose another folder' }),
]),
}),
);
await expect(readFile(join(projectDir, 'README.md'), 'utf-8')).resolves.toBe('Existing project notes\n');
await expect(stat(join(projectDir, 'klo.yaml'))).resolves.toBeDefined();
await expect(stat(join(projectDir, 'ktx.yaml'))).resolves.toBeDefined();
});
it('prompts to exit and returns cancelled in interactive auto mode', async () => {
@ -321,7 +321,7 @@ describe('setup project step', () => {
const prompts = makePromptAdapter({ choice: 'exit' });
await expect(
runKloSetupProjectStep(
runKtxSetupProjectStep(
{ projectDir, mode: 'auto', inputMode: 'auto', yes: false },
makeIo({ stdoutIsTty: true }).io,
{ prompts },
@ -330,6 +330,6 @@ describe('setup project step', () => {
expect(prompts.cancel).toHaveBeenCalledWith('Setup cancelled.');
expect(prompts.text).not.toHaveBeenCalled();
await expect(stat(join(projectDir, 'klo.yaml'))).rejects.toThrow();
await expect(stat(join(projectDir, 'ktx.yaml'))).rejects.toThrow();
});
});