mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-07 07:55:13 +02:00
* feat(cli): define full warehouse dialect contract
* test(cli): keep dialect edge tests focused
* fix(cli): stabilize dialect contract foundation
* refactor(connectors): own read-only query preparation
* refactor(connectors): resolve dialects through registry
* refactor(connectors): keep concrete dialect classes internal
* chore(workspace): enforce dialect import boundary
* refactor(cli): resolve relationship dialect at scan boundary
* refactor(cli): use dialect display parsing for entity details
* refactor(cli): use dialect display parsing for warehouse catalog
* refactor(cli): use dialect SQL in relationship workflows
* test(cli): verify solid dialect scan workflow closure
* test: split cli tests from source tree
* refactor(cli): standardize BigQuery scope listing
* feat(sqlite): implement connector scope listing
* test(connectors): cover required table listing
* feat(cli): add warehouse driver registry
* refactor(setup): route scope discovery through driver registry
* refactor(cli): route local query execution through driver registry
* refactor(historic-sql): route dialect support through driver registry
* refactor(cli): test warehouse connections through driver registry
* fix(cli): close driver registry type export gaps
* Improve setup daemon diagnostics
* refactor(setup): centralize rail-prefixed diagnostics + query-history fallback
Extract errorMessage, writePrefixedLines, and flushPrefixedBufferedCommandOutput
into clack.ts so the setup wizard, managed daemons, and embedding/agent steps
share one rail-formatted writer. setup-databases.ts also adds a
"disable query history and retry" option when the schema-context build fails
and query history is the likely culprit, surfaced via a new
failed-query-history-unavailable status.
* fix(cli): carry catalog through the picker so BigQuery/Snowflake/SQL Server scope filters match
The setup picker's KtxTableListEntry was a 2-level { schema, name }, so
qualifiedTableId always wrote db.name into enabled_tables. When BigQuery,
Snowflake, or SQL Server later ran fast ingest, their introspect step filtered
the scope set with scopedTableNames(scope, { catalog: projectId|database, db })
— catalog was non-null on the introspect side but null in the scope refs, so
every entry was rejected, the live-database adapter staged zero table files,
and detect() failed with 'Adapter "live-database" did not recognize fetched
source output'.
Align the picker boundary with the canonical 3-level KtxTableRef:
- Add catalog: string | null to KtxTableListEntry.
- BigQuery/Snowflake/SQL Server listTables populate catalog from the
resolved projectId / database; Postgres/MySQL/ClickHouse/SQLite set null.
- qualifiedTableId emits catalog.schema.name when catalog is non-null
(resolveEnabledTables already accepts the 3-part shape) and
schemasFromEnabledTables now goes through parseDottedTableEntry so it
recovers the schema correctly from both 2-part and 3-part entries.
- Export parseDottedTableEntry from enabled-tables.ts (@internal) for picker
reuse.
Update listTables expectations in all seven connector tests and the setup /
picker test fixtures. Add a picker regression test that covers the
catalog-bearing round-trip (save + refine).
* fix(cli): allow debug telemetry under opt-out env
330 lines
10 KiB
TypeScript
330 lines
10 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import {
|
|
createManagedPythonSemanticLayerComputePort,
|
|
ensureManagedPythonCommandRuntime,
|
|
managedRuntimeInstallCommand,
|
|
runtimeInstallPolicyFromFlags,
|
|
} from '../src/managed-python-command.js';
|
|
import type {
|
|
InstalledKtxRuntimeManifest,
|
|
KtxRuntimeFeature,
|
|
ManagedPythonRuntimeInstallResult,
|
|
ManagedPythonRuntimeLayout,
|
|
ManagedPythonRuntimeStatus,
|
|
} from '../src/managed-python-runtime.js';
|
|
|
|
function makeIo() {
|
|
let stdout = '';
|
|
let stderr = '';
|
|
return {
|
|
io: {
|
|
stdout: {
|
|
write: (chunk: string) => {
|
|
stdout += chunk;
|
|
},
|
|
},
|
|
stderr: {
|
|
write: (chunk: string) => {
|
|
stderr += chunk;
|
|
},
|
|
},
|
|
},
|
|
stdout: () => stdout,
|
|
stderr: () => stderr,
|
|
};
|
|
}
|
|
|
|
function layout(): ManagedPythonRuntimeLayout {
|
|
return {
|
|
cliVersion: '0.2.0',
|
|
runtimeRoot: '/runtime',
|
|
versionDir: '/runtime/0.2.0',
|
|
venvDir: '/runtime/0.2.0/.venv',
|
|
manifestPath: '/runtime/0.2.0/manifest.json',
|
|
installLogPath: '/runtime/0.2.0/install.log',
|
|
assetDir: '/assets/python',
|
|
assetManifestPath: '/assets/python/manifest.json',
|
|
pythonPath: '/runtime/0.2.0/.venv/bin/python',
|
|
daemonPath: '/runtime/0.2.0/.venv/bin/ktx-daemon',
|
|
};
|
|
}
|
|
|
|
function manifest(features: KtxRuntimeFeature[] = ['core']): InstalledKtxRuntimeManifest {
|
|
return {
|
|
schemaVersion: 1,
|
|
cliVersion: '0.2.0',
|
|
installedAt: '2026-05-11T00:00:00.000Z',
|
|
asset: {
|
|
schemaVersion: 1,
|
|
distributionName: 'kaelio-ktx',
|
|
normalizedName: 'kaelio_ktx',
|
|
version: '0.2.0',
|
|
wheel: {
|
|
file: 'kaelio_ktx-0.2.0-py3-none-any.whl',
|
|
sha256: 'a'.repeat(64),
|
|
bytes: 123,
|
|
},
|
|
},
|
|
features,
|
|
python: {
|
|
executable: '/runtime/0.2.0/.venv/bin/python',
|
|
daemonExecutable: '/runtime/0.2.0/.venv/bin/ktx-daemon',
|
|
},
|
|
installLog: '/runtime/0.2.0/install.log',
|
|
};
|
|
}
|
|
|
|
function readyStatus(features: KtxRuntimeFeature[] = ['core']): ManagedPythonRuntimeStatus {
|
|
return {
|
|
kind: 'ready',
|
|
detail: 'Runtime ready at /runtime/0.2.0',
|
|
layout: layout(),
|
|
manifest: manifest(features),
|
|
};
|
|
}
|
|
|
|
function missingStatus(): ManagedPythonRuntimeStatus {
|
|
return {
|
|
kind: 'missing',
|
|
detail: 'No runtime manifest at /runtime/0.2.0/manifest.json',
|
|
layout: layout(),
|
|
};
|
|
}
|
|
|
|
function installResult(features: KtxRuntimeFeature[] = ['core']): ManagedPythonRuntimeInstallResult {
|
|
const installedManifest = manifest(features);
|
|
return {
|
|
status: 'installed',
|
|
layout: layout(),
|
|
asset: {
|
|
manifest: installedManifest.asset,
|
|
wheelPath: '/assets/python/kaelio_ktx-0.2.0-py3-none-any.whl',
|
|
requiresPython: { specifier: '>=3.13', minimumVersion: '3.13' },
|
|
},
|
|
manifest: installedManifest,
|
|
};
|
|
}
|
|
|
|
function makeSpinnerEvents() {
|
|
const events: string[] = [];
|
|
const spinner = vi.fn(() => ({
|
|
start: (msg: string) => events.push(`start:${msg}`),
|
|
message: (msg: string) => events.push(`message:${msg}`),
|
|
stop: (msg: string) => events.push(`stop:${msg}`),
|
|
error: (msg: string) => events.push(`error:${msg}`),
|
|
}));
|
|
return { events, spinner };
|
|
}
|
|
|
|
describe('managedRuntimeInstallCommand', () => {
|
|
it('prints the exact command for each managed runtime feature', () => {
|
|
expect(managedRuntimeInstallCommand('core')).toBe('ktx admin runtime install --yes');
|
|
expect(managedRuntimeInstallCommand('local-embeddings')).toBe(
|
|
'ktx admin runtime install --feature local-embeddings --yes',
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('runtimeInstallPolicyFromFlags', () => {
|
|
it('maps command flags to managed runtime install policies', () => {
|
|
expect(runtimeInstallPolicyFromFlags({})).toBe('prompt');
|
|
expect(runtimeInstallPolicyFromFlags({ yes: false })).toBe('prompt');
|
|
expect(runtimeInstallPolicyFromFlags({ yes: true })).toBe('auto');
|
|
expect(runtimeInstallPolicyFromFlags({ input: false })).toBe('never');
|
|
});
|
|
|
|
it('rejects conflicting runtime install flags', () => {
|
|
expect(() => runtimeInstallPolicyFromFlags({ yes: true, input: false })).toThrow(
|
|
'Choose only one runtime install mode: --yes or --no-input',
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('createManagedPythonSemanticLayerComputePort', () => {
|
|
it('uses non-animated runtime setup status by default', async () => {
|
|
const io = makeIo();
|
|
|
|
await expect(
|
|
ensureManagedPythonCommandRuntime({
|
|
cliVersion: '0.2.0',
|
|
installPolicy: 'auto',
|
|
io: io.io,
|
|
readStatus: vi.fn(async () => missingStatus()),
|
|
installRuntime: vi.fn(async () => installResult(['local-embeddings'])),
|
|
feature: 'local-embeddings',
|
|
}),
|
|
).resolves.toMatchObject({
|
|
layout: { versionDir: '/runtime/0.2.0' },
|
|
});
|
|
|
|
expect(io.stderr()).toContain('Installing KTX Python runtime (local-embeddings) with uv...');
|
|
expect(io.stderr()).toContain('KTX Python runtime ready: /runtime/0.2.0');
|
|
expect(io.stderr().match(/Installing KTX Python runtime/g)).toHaveLength(1);
|
|
});
|
|
|
|
it('shows runtime installation progress with the CLI spinner', async () => {
|
|
const io = makeIo();
|
|
const { events, spinner } = makeSpinnerEvents();
|
|
|
|
const options = {
|
|
cliVersion: '0.2.0',
|
|
installPolicy: 'auto' as const,
|
|
io: io.io,
|
|
readStatus: vi.fn(async () => missingStatus()),
|
|
installRuntime: vi.fn(async () => installResult(['local-embeddings'])),
|
|
feature: 'local-embeddings' as const,
|
|
spinner,
|
|
};
|
|
|
|
await expect(ensureManagedPythonCommandRuntime(options)).resolves.toMatchObject({
|
|
layout: { versionDir: '/runtime/0.2.0' },
|
|
});
|
|
|
|
expect(events).toEqual([
|
|
'start:Installing KTX Python runtime (local-embeddings) with uv...',
|
|
'stop:KTX Python runtime ready: /runtime/0.2.0',
|
|
]);
|
|
});
|
|
|
|
it('uses the managed ktx-daemon executable when the runtime is ready', async () => {
|
|
const io = makeIo();
|
|
const compute = { query: vi.fn(), validateSources: vi.fn(), generateSources: vi.fn() };
|
|
const createPythonCompute = vi.fn(() => compute);
|
|
|
|
await expect(
|
|
createManagedPythonSemanticLayerComputePort({
|
|
cliVersion: '0.2.0',
|
|
installPolicy: 'never',
|
|
io: io.io,
|
|
readStatus: vi.fn(async () => readyStatus()),
|
|
installRuntime: vi.fn(),
|
|
createPythonCompute,
|
|
}),
|
|
).resolves.toBe(compute);
|
|
|
|
expect(createPythonCompute).toHaveBeenCalledWith({
|
|
command: '/runtime/0.2.0/.venv/bin/ktx-daemon',
|
|
args: [],
|
|
});
|
|
expect(io.stderr()).toBe('');
|
|
});
|
|
|
|
it('fails with a preparation command when input is disabled and the runtime is missing', async () => {
|
|
const io = makeIo();
|
|
const installRuntime = vi.fn();
|
|
|
|
await expect(
|
|
createManagedPythonSemanticLayerComputePort({
|
|
cliVersion: '0.2.0',
|
|
installPolicy: 'never',
|
|
io: io.io,
|
|
readStatus: vi.fn(async () => missingStatus()),
|
|
installRuntime,
|
|
}),
|
|
).rejects.toThrow('KTX Python runtime is required for this command. Run: ktx admin runtime install --yes');
|
|
|
|
expect(installRuntime).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('installs the core runtime without prompting when policy is auto', async () => {
|
|
const io = makeIo();
|
|
const { events, spinner } = makeSpinnerEvents();
|
|
const compute = { query: vi.fn(), validateSources: vi.fn(), generateSources: vi.fn() };
|
|
const createPythonCompute = vi.fn(() => compute);
|
|
const installRuntime = vi.fn(async () => installResult());
|
|
|
|
await expect(
|
|
createManagedPythonSemanticLayerComputePort({
|
|
cliVersion: '0.2.0',
|
|
installPolicy: 'auto',
|
|
io: io.io,
|
|
readStatus: vi.fn(async () => missingStatus()),
|
|
installRuntime,
|
|
createPythonCompute,
|
|
spinner,
|
|
}),
|
|
).resolves.toBe(compute);
|
|
|
|
expect(installRuntime).toHaveBeenCalledWith({
|
|
cliVersion: '0.2.0',
|
|
features: ['core'],
|
|
force: false,
|
|
});
|
|
expect(events).toEqual([
|
|
'start:Installing KTX Python runtime (core) with uv...',
|
|
'stop:KTX Python runtime ready: /runtime/0.2.0',
|
|
]);
|
|
});
|
|
|
|
it('prompts before installing when policy is prompt', async () => {
|
|
const io = makeIo();
|
|
const { events, spinner } = makeSpinnerEvents();
|
|
const confirmInstall = vi.fn(async () => true);
|
|
const installRuntime = vi.fn(async () => installResult());
|
|
|
|
await createManagedPythonSemanticLayerComputePort({
|
|
cliVersion: '0.2.0',
|
|
installPolicy: 'prompt',
|
|
io: io.io,
|
|
readStatus: vi.fn(async () => missingStatus()),
|
|
installRuntime,
|
|
createPythonCompute: vi.fn(() => ({ query: vi.fn(), validateSources: vi.fn(), generateSources: vi.fn() })),
|
|
confirmInstall,
|
|
spinner,
|
|
});
|
|
|
|
expect(confirmInstall).toHaveBeenCalledWith(
|
|
'KTX needs to install the core Python runtime. This downloads Python dependencies with uv. Continue?',
|
|
io.io,
|
|
);
|
|
expect(installRuntime).toHaveBeenCalledWith({
|
|
cliVersion: '0.2.0',
|
|
features: ['core'],
|
|
force: false,
|
|
});
|
|
expect(events).toContainEqual('start:Installing KTX Python runtime (core) with uv...');
|
|
});
|
|
|
|
it('uses injected runtime confirmation instead of reading process TTY directly', async () => {
|
|
const io = makeIo();
|
|
const { events, spinner } = makeSpinnerEvents();
|
|
const compute = { query: vi.fn(), validateSources: vi.fn(), generateSources: vi.fn() };
|
|
const installRuntime = vi.fn(async (): Promise<ManagedPythonRuntimeInstallResult> => installResult());
|
|
const confirmInstall = vi.fn(async () => true);
|
|
|
|
await expect(
|
|
createManagedPythonSemanticLayerComputePort({
|
|
cliVersion: '0.2.0',
|
|
installPolicy: 'prompt',
|
|
io: io.io,
|
|
readStatus: async () => missingStatus(),
|
|
installRuntime,
|
|
confirmInstall,
|
|
createPythonCompute: () => compute,
|
|
spinner,
|
|
}),
|
|
).resolves.toBe(compute);
|
|
|
|
expect(confirmInstall).toHaveBeenCalledWith(
|
|
'KTX needs to install the core Python runtime. This downloads Python dependencies with uv. Continue?',
|
|
io.io,
|
|
);
|
|
expect(events).toContainEqual('start:Installing KTX Python runtime (core) with uv...');
|
|
});
|
|
|
|
it('can decide default runtime prompting from injected io capabilities', async () => {
|
|
const io = makeIo();
|
|
Object.assign(io.io.stdout, { isTTY: false });
|
|
|
|
await expect(
|
|
createManagedPythonSemanticLayerComputePort({
|
|
cliVersion: '0.2.0',
|
|
installPolicy: 'prompt',
|
|
io: io.io,
|
|
readStatus: async () => missingStatus(),
|
|
installRuntime: vi.fn(),
|
|
createPythonCompute: () => ({ query: vi.fn(), validateSources: vi.fn(), generateSources: vi.fn() }),
|
|
}),
|
|
).rejects.toThrow('KTX Python runtime installation was cancelled');
|
|
});
|
|
});
|