mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-10 08:05:14 +02:00
* feat(setup): write per-role llm model presets * feat(setup): remove llm model setup flag * chore(setup): update llm preset guidance * docs(setup): document llm model presets * chore(release): sync uv.lock to 0.9.0 * fix(cli): make sl query --execute work on secret-backed connections sl query --execute used a parallel SQL executor (createDefaultLocalQueryExecutor) that passed connection.url verbatim into pg, so file:/env: secret references failed with "SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string". Collapse onto the connector-based executor already used by MCP and ingest (createKtxCliIngestQueryExecutor), which resolves secret references and supports every driver. Delete the now-dead local/postgres/sqlite query executors, their tests, and the orphaned hasLocalQueryExecutor driver flag. * docs(agents): require one implementation per capability Add a design-reasoning default and a matching self-check question telling agents to route callers through a single shared implementation of a capability rather than forking a parallel one, and to fix the shared layer rather than patch one branch. Encodes the lesson from a divergent SQL-execution-path bug, stated generally. CLAUDE.md is a symlink to AGENTS.md, so both agent-instruction files are covered.
143 lines
4.6 KiB
TypeScript
143 lines
4.6 KiB
TypeScript
import { mkdtemp, rm } from 'node:fs/promises';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
import {
|
|
driverRegistrations,
|
|
getDriverRegistration,
|
|
listSupportedDrivers,
|
|
} from '../../../src/context/connections/drivers.js';
|
|
import type {
|
|
KtxDriverConnectorModule,
|
|
KtxScopeConfigKey,
|
|
} from '../../../src/context/connections/drivers.js';
|
|
import type { KtxConnectionDriver } from '../../../src/context/scan/types.js';
|
|
|
|
type FixtureFactory = (projectDir: string) => Record<string, unknown>;
|
|
|
|
const connectionFixtures: Record<KtxConnectionDriver, FixtureFactory> = {
|
|
postgres: () => ({
|
|
driver: 'postgres',
|
|
url: 'postgresql://reader:secret@localhost:5432/analytics', // pragma: allowlist secret
|
|
schemas: ['public'],
|
|
}),
|
|
sqlite: () => ({ driver: 'sqlite', path: 'warehouse.db' }),
|
|
mysql: () => ({
|
|
driver: 'mysql',
|
|
host: 'localhost',
|
|
database: 'analytics',
|
|
username: 'reader',
|
|
password: 'secret', // pragma: allowlist secret
|
|
schemas: ['analytics'],
|
|
}),
|
|
clickhouse: () => ({
|
|
driver: 'clickhouse',
|
|
url: 'http://localhost:8123',
|
|
database: 'analytics',
|
|
username: 'reader',
|
|
password: 'secret', // pragma: allowlist secret
|
|
}),
|
|
sqlserver: () => ({
|
|
driver: 'sqlserver',
|
|
host: 'localhost',
|
|
database: 'analytics',
|
|
username: 'reader',
|
|
password: 'secret', // pragma: allowlist secret
|
|
schemas: ['dbo'],
|
|
}),
|
|
bigquery: () => ({
|
|
driver: 'bigquery',
|
|
dataset_id: 'analytics',
|
|
credentials_json: JSON.stringify({
|
|
project_id: 'project-1',
|
|
client_email: 'reader@example.test',
|
|
private_key: '-----BEGIN PRIVATE KEY-----\nsecret\n-----END PRIVATE KEY-----\n', // pragma: allowlist secret
|
|
}),
|
|
location: 'US',
|
|
}),
|
|
snowflake: () => ({
|
|
driver: 'snowflake',
|
|
account: 'example-account',
|
|
username: 'reader',
|
|
password: 'secret', // pragma: allowlist secret
|
|
warehouse: 'COMPUTE_WH',
|
|
database: 'ANALYTICS',
|
|
schema: 'PUBLIC',
|
|
}),
|
|
};
|
|
|
|
const allowedScopeKeys = new Set(['dataset_ids', 'databases', 'schemas', 'schema_names']);
|
|
const historicSqlReaderDrivers = new Set<KtxConnectionDriver>(['postgres', 'bigquery', 'snowflake']);
|
|
|
|
function assertExportedRegistryBoundaryTypes(input: {
|
|
scopeConfigKey: KtxScopeConfigKey;
|
|
connectorModule: KtxDriverConnectorModule;
|
|
}): {
|
|
scopeConfigKey: KtxScopeConfigKey;
|
|
connectorModule: KtxDriverConnectorModule;
|
|
} {
|
|
return input;
|
|
}
|
|
|
|
describe('driverRegistrations', () => {
|
|
let projectDir: string;
|
|
|
|
beforeEach(async () => {
|
|
projectDir = await mkdtemp(join(tmpdir(), 'ktx-driver-registry-'));
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await rm(projectDir, { recursive: true, force: true });
|
|
});
|
|
|
|
it('lists every supported warehouse driver', () => {
|
|
const registryDrivers = Object.keys(driverRegistrations).sort();
|
|
expect(listSupportedDrivers()).toEqual(registryDrivers);
|
|
expect(listSupportedDrivers()).toEqual([
|
|
'bigquery',
|
|
'clickhouse',
|
|
'mysql',
|
|
'postgres',
|
|
'snowflake',
|
|
'sqlite',
|
|
'sqlserver',
|
|
]);
|
|
});
|
|
|
|
it('resolves registered drivers case-insensitively', () => {
|
|
expect(getDriverRegistration(' Postgres ')?.driver).toBe('postgres');
|
|
expect(getDriverRegistration('unknown')).toBeUndefined();
|
|
});
|
|
|
|
it.each(Object.values(driverRegistrations))('adapts $driver connector exports', async (registration) => {
|
|
const connectorModule = await registration.load();
|
|
const connection = connectionFixtures[registration.driver](projectDir);
|
|
const exportedBoundary = assertExportedRegistryBoundaryTypes({
|
|
scopeConfigKey: registration.scopeConfigKey ?? 'schemas',
|
|
connectorModule,
|
|
});
|
|
expect(exportedBoundary.connectorModule.createScanConnector).toEqual(expect.any(Function));
|
|
|
|
expect(connectorModule.isConnectionConfig(connection)).toBe(true);
|
|
expect(connectorModule.isConnectionConfig({})).toBe(false);
|
|
|
|
const connector = connectorModule.createScanConnector({
|
|
connectionId: 'warehouse',
|
|
connection,
|
|
projectDir,
|
|
});
|
|
|
|
expect(connector.driver).toBe(registration.driver);
|
|
expect(connector.listSchemas).toEqual(expect.any(Function));
|
|
expect(connector.listTables).toEqual(expect.any(Function));
|
|
await connector.cleanup?.();
|
|
|
|
if (registration.driver === 'sqlite') {
|
|
expect(registration.scopeConfigKey).toBeNull();
|
|
} else {
|
|
expect(registration.scopeConfigKey).not.toBeNull();
|
|
expect(allowedScopeKeys.has(registration.scopeConfigKey ?? '')).toBe(true);
|
|
}
|
|
expect(registration.hasHistoricSqlReader).toBe(historicSqlReaderDrivers.has(registration.driver));
|
|
});
|
|
});
|