mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-07 07:55:13 +02:00
* chore: standardize daemon naming on "KTX daemon"
Replace inconsistent names ("KTX Python daemon", "KTX local embeddings
daemon", "KTX managed daemon", "Python daemon") with the single name
"KTX daemon" in CLI output, errors, command descriptions, test
assertions, smoke scripts, docs, AGENTS.md, issue templates, and
codecov flags. The daemon is a portable compute server with endpoints
for SQL analysis, semantic layer, LookML, database introspection, and
embeddings; the previous labels misrepresented it as embeddings-only or
exposed implementation details ("Python", "managed").
The "KTX Python runtime" concept (installed interpreter + packages) is
deliberately left as-is — it is a separate concept from the daemon
process.
* refactor(release): drop release-policy.json runtime dep and next branch
Strips the release-policy.json fallback from release-version.ts so the CLI
reads its version straight from packages/cli/package.json. dev → 0.0.0-private,
installed @kaelio/ktx → the real semver baked into the published package.json.
KtxCliPackageInfo collapses to { name, version, contextPackageName }; /health
no longer depends on version files surviving past a CI run.
Replaces the dual-branch (main + next) semantic-release model with a single-
branch model on main. rcs and stables interleave on the same branch via
{ name: 'main', prerelease: 'rc', channel: 'next' } / ['main']. Drops
@semantic-release/git and @semantic-release/changelog (nothing is committed
back to the repo on any channel) and the workflow's "Prepare next prerelease
branch" step plus the KTX_PRERELEASE_BRANCH plumbing. The git tag plus the
published npm artifact carry the version forward.
Updates docs/release.md, removes the two now-unused devDeps, regenerates
pnpm-lock.yaml. 611/611 @ktx/cli tests, 173/173 script tests, type-check,
biome, knip all clean.
* fix(release): don't throw on non-main branches at config-load time
knip loads .releaserc.cjs on every PR run, where GITHUB_REF_NAME is the
merge ref (e.g. 180/merge). The previous version of releaseBranches threw
immediately when the branch wasn't main, which made knip fail to evaluate
the config and then mis-flag @semantic-release/exec as an unused dep.
semantic-release already refuses to publish when the current branch doesn't
match a configured release branch, so the explicit throw was redundant.
Drop it (and the unused currentBranch helper) and replace the
"rejects releases from non-main" assertion with one that exercises a CI-
shaped GITHUB_REF_NAME and confirms the config loads.
205 lines
6.9 KiB
TypeScript
205 lines
6.9 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import {
|
|
createManagedDaemonHttpJsonRunner,
|
|
createManagedDaemonLookerTableIdentifierParser,
|
|
createManagedDaemonSqlAnalysisPort,
|
|
createManagedPythonDaemonBaseUrlResolver,
|
|
managedDaemonDatabaseIntrospectionOptions,
|
|
} from './managed-python-http.js';
|
|
|
|
function io() {
|
|
let stderr = '';
|
|
return {
|
|
io: {
|
|
stdout: { write: vi.fn() },
|
|
stderr: { write: (chunk: string) => (stderr += chunk) },
|
|
},
|
|
stderr: () => stderr,
|
|
};
|
|
}
|
|
|
|
describe('createManagedPythonDaemonBaseUrlResolver', () => {
|
|
it('ensures the core runtime, starts the daemon, reports the URL, and caches the result', async () => {
|
|
const testIo = io();
|
|
const ensureRuntime = vi.fn(async () => ({
|
|
layout: {} as never,
|
|
manifest: {} as never,
|
|
}));
|
|
const startDaemon = vi.fn(async () => ({
|
|
status: 'started' as const,
|
|
layout: {} as never,
|
|
state: { pid: 1234 } as never,
|
|
baseUrl: 'http://127.0.0.1:61234',
|
|
}));
|
|
const resolveBaseUrl = createManagedPythonDaemonBaseUrlResolver({
|
|
cliVersion: '0.2.0',
|
|
projectDir: '/work/proj',
|
|
installPolicy: 'auto',
|
|
io: testIo.io,
|
|
ensureRuntime,
|
|
startDaemon,
|
|
});
|
|
|
|
await expect(resolveBaseUrl()).resolves.toBe('http://127.0.0.1:61234');
|
|
await expect(resolveBaseUrl()).resolves.toBe('http://127.0.0.1:61234');
|
|
|
|
expect(ensureRuntime).toHaveBeenCalledTimes(1);
|
|
expect(ensureRuntime).toHaveBeenCalledWith({
|
|
cliVersion: '0.2.0',
|
|
installPolicy: 'auto',
|
|
io: testIo.io,
|
|
feature: 'core',
|
|
});
|
|
expect(startDaemon).toHaveBeenCalledTimes(1);
|
|
expect(startDaemon).toHaveBeenCalledWith({
|
|
cliVersion: '0.2.0',
|
|
projectDir: '/work/proj',
|
|
features: ['core'],
|
|
force: false,
|
|
});
|
|
expect(testIo.stderr()).toContain('Started KTX daemon: http://127.0.0.1:61234');
|
|
});
|
|
|
|
it('reports daemon reuse without reinstalling after the first resolved URL', async () => {
|
|
const testIo = io();
|
|
const ensureRuntime = vi.fn(async () => ({
|
|
layout: {} as never,
|
|
manifest: {} as never,
|
|
}));
|
|
const startDaemon = vi.fn(async () => ({
|
|
status: 'reused' as const,
|
|
layout: {} as never,
|
|
state: { pid: 1234 } as never,
|
|
baseUrl: 'http://127.0.0.1:61234',
|
|
}));
|
|
const resolveBaseUrl = createManagedPythonDaemonBaseUrlResolver({
|
|
cliVersion: '0.2.0',
|
|
projectDir: '/work/proj',
|
|
installPolicy: 'never',
|
|
io: testIo.io,
|
|
ensureRuntime,
|
|
startDaemon,
|
|
});
|
|
|
|
await expect(resolveBaseUrl()).resolves.toBe('http://127.0.0.1:61234');
|
|
await expect(resolveBaseUrl()).resolves.toBe('http://127.0.0.1:61234');
|
|
|
|
expect(ensureRuntime).toHaveBeenCalledTimes(1);
|
|
expect(startDaemon).toHaveBeenCalledTimes(1);
|
|
expect(testIo.stderr()).toContain('Using existing KTX daemon: http://127.0.0.1:61234');
|
|
});
|
|
});
|
|
|
|
describe('createManagedDaemonHttpJsonRunner', () => {
|
|
it('resolves the managed base URL lazily for each HTTP JSON request', async () => {
|
|
const postJson = vi.fn(async () => ({ ok: true }));
|
|
const runner = createManagedDaemonHttpJsonRunner({
|
|
resolveBaseUrl: async () => 'http://127.0.0.1:61234',
|
|
postJson,
|
|
});
|
|
|
|
await expect(runner('/sql/parse-table-identifier', { items: [] })).resolves.toEqual({ ok: true });
|
|
|
|
expect(postJson).toHaveBeenCalledWith('http://127.0.0.1:61234', '/sql/parse-table-identifier', { items: [] });
|
|
});
|
|
});
|
|
|
|
describe('KTX daemon ingest ports', () => {
|
|
it('creates a Looker table parser backed by the KTX daemon runner', async () => {
|
|
const requestJson = vi.fn(async () => ({
|
|
results: {
|
|
'model.explore': {
|
|
ok: true,
|
|
catalog: 'warehouse',
|
|
schema: 'public',
|
|
name: 'orders',
|
|
canonical_table: 'public.orders',
|
|
},
|
|
},
|
|
}));
|
|
const parser = createManagedDaemonLookerTableIdentifierParser({ requestJson });
|
|
|
|
await expect(
|
|
parser.parse([{ key: 'model.explore', sql_table_name: 'public.orders', dialect: 'postgres' }]),
|
|
).resolves.toEqual({
|
|
'model.explore': {
|
|
ok: true,
|
|
catalog: 'warehouse',
|
|
schema: 'public',
|
|
name: 'orders',
|
|
canonical_table: 'public.orders',
|
|
},
|
|
});
|
|
expect(requestJson).toHaveBeenCalledWith('/sql/parse-table-identifier', {
|
|
items: [{ key: 'model.explore', sql_table_name: 'public.orders', dialect: 'postgres' }],
|
|
});
|
|
});
|
|
|
|
it('creates a SQL analysis port backed by the KTX daemon runner', async () => {
|
|
const requestJson = vi.fn(async () => ({
|
|
fingerprint: 'select-orders',
|
|
normalized_sql: 'SELECT * FROM public.orders WHERE id = ?',
|
|
tables_touched: ['public.orders'],
|
|
literal_slots: [{ position: 1, type: 'number', example_value: '42' }],
|
|
}));
|
|
const sqlAnalysis = createManagedDaemonSqlAnalysisPort({ requestJson });
|
|
|
|
await expect(sqlAnalysis.analyzeForFingerprint('SELECT * FROM public.orders WHERE id = 42', 'postgres')).resolves
|
|
.toEqual({
|
|
fingerprint: 'select-orders',
|
|
normalizedSql: 'SELECT * FROM public.orders WHERE id = ?',
|
|
tablesTouched: ['public.orders'],
|
|
literalSlots: [{ position: 1, type: 'number', exampleValue: '42' }],
|
|
});
|
|
expect(requestJson).toHaveBeenCalledWith('/api/sql/analyze-for-fingerprint', {
|
|
sql: 'SELECT * FROM public.orders WHERE id = 42',
|
|
dialect: 'postgres',
|
|
});
|
|
});
|
|
|
|
it('routes SQL batch analysis through the KTX daemon runner', async () => {
|
|
const requestJson = vi.fn(async () => ({
|
|
results: {
|
|
orders: {
|
|
tables_touched: ['public.orders'],
|
|
columns_by_clause: { select: ['status'] },
|
|
error: null,
|
|
},
|
|
},
|
|
}));
|
|
const sqlAnalysis = createManagedDaemonSqlAnalysisPort({ requestJson });
|
|
|
|
await expect(sqlAnalysis.analyzeBatch([{ id: 'orders', sql: 'select status from public.orders' }], 'postgres'))
|
|
.resolves.toEqual(
|
|
new Map([
|
|
[
|
|
'orders',
|
|
{
|
|
tablesTouched: ['public.orders'],
|
|
columnsByClause: { select: ['status'] },
|
|
error: null,
|
|
},
|
|
],
|
|
]),
|
|
);
|
|
expect(requestJson).toHaveBeenCalledWith('/sql/analyze-batch', {
|
|
dialect: 'postgres',
|
|
items: [{ id: 'orders', sql: 'select status from public.orders' }],
|
|
});
|
|
});
|
|
|
|
it('returns live-database daemon request options backed by the managed runner', async () => {
|
|
const requestJson = vi.fn(async () => ({
|
|
connection_id: 'warehouse',
|
|
tables: [],
|
|
}));
|
|
const options = managedDaemonDatabaseIntrospectionOptions({ requestJson });
|
|
expect(options.requestJson).toBeDefined();
|
|
|
|
await expect(options.requestJson?.('/database/introspect', { connection_id: 'warehouse' })).resolves.toEqual({
|
|
connection_id: 'warehouse',
|
|
tables: [],
|
|
});
|
|
expect(requestJson).toHaveBeenCalledWith('/database/introspect', { connection_id: 'warehouse' });
|
|
});
|
|
});
|