ktx/packages/cli/src/context/project/setup-config.test.ts

59 lines
2.2 KiB
TypeScript
Raw Normal View History

import { mkdtemp, readFile, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2026-05-10 23:51:24 +02:00
import { buildDefaultKtxProjectConfig } from './config.js';
2026-05-10 23:12:26 +02:00
import {
markKtxSetupStateStepComplete,
2026-05-10 23:51:24 +02:00
mergeKtxSetupGitignoreEntries,
readKtxSetupState,
2026-05-10 23:51:24 +02:00
setKtxSetupDatabaseConnectionIds,
2026-05-10 23:12:26 +02:00
} from './setup-config.js';
2026-05-10 23:51:24 +02:00
describe('KTX setup config helpers', () => {
let tempDir: string;
2026-05-10 23:12:26 +02:00
beforeEach(async () => {
tempDir = await mkdtemp(join(tmpdir(), 'ktx-setup-state-'));
});
2026-05-10 23:12:26 +02:00
afterEach(async () => {
await rm(tempDir, { recursive: true, force: true });
2026-05-10 23:12:26 +02:00
});
it('marks setup steps complete in local state without duplicating existing state', async () => {
await markKtxSetupStateStepComplete(tempDir, 'project');
await markKtxSetupStateStepComplete(tempDir, 'project');
await markKtxSetupStateStepComplete(tempDir, 'llm');
await markKtxSetupStateStepComplete(tempDir, 'runtime');
await markKtxSetupStateStepComplete(tempDir, 'context');
2026-05-10 23:12:26 +02:00
expect(await readKtxSetupState(tempDir)).toEqual({
completed_steps: ['project', 'llm', 'runtime', 'context'],
2026-05-10 23:12:26 +02:00
});
await expect(readFile(join(tempDir, '.ktx', 'setup', 'state.json'), 'utf-8')).resolves.toBe(
`${JSON.stringify({ completed_steps: ['project', 'llm', 'runtime', 'context'] }, null, 2)}\n`,
);
2026-05-10 23:12:26 +02:00
});
it('sets setup database connection ids without duplicates', () => {
const config = buildDefaultKtxProjectConfig();
2026-05-10 23:12:26 +02:00
2026-05-10 23:51:24 +02:00
const withDatabases = setKtxSetupDatabaseConnectionIds(config, ['warehouse', 'analytics', 'warehouse']);
2026-05-10 23:12:26 +02:00
expect(withDatabases.setup).toEqual({
database_connection_ids: ['warehouse', 'analytics'],
});
expect(config.setup).toBeUndefined();
});
it('merges setup-local gitignore entries without removing existing lines', () => {
2026-05-10 23:51:24 +02:00
expect(mergeKtxSetupGitignoreEntries('cache/\ndb.sqlite\n')).toBe(
2026-05-11 00:31:15 -07:00
['cache/', 'db.sqlite', 'db.sqlite-*', 'ingest-transcripts/', 'secrets/', 'setup/', 'agents/', ''].join('\n'),
2026-05-10 23:12:26 +02:00
);
2026-05-10 23:51:24 +02:00
expect(mergeKtxSetupGitignoreEntries('cache/\nsecrets/\n')).toBe(
2026-05-11 00:31:15 -07:00
['cache/', 'secrets/', 'db.sqlite', 'db.sqlite-*', 'ingest-transcripts/', 'setup/', 'agents/', ''].join('\n'),
2026-05-10 23:12:26 +02:00
);
});
});