ktx/packages/cli/src/serve.test.ts

552 lines
18 KiB
TypeScript
Raw Normal View History

2026-05-10 23:12:26 +02:00
import { mkdtemp, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
2026-05-10 23:51:24 +02:00
import type { SourceAdapter } from '@ktx/context/ingest';
import { initKtxProject } from '@ktx/context/project';
2026-05-10 23:12:26 +02:00
import { describe, expect, it, vi } from 'vitest';
2026-05-10 23:51:24 +02:00
import { runKtxServeStdio } from './serve.js';
2026-05-10 23:12:26 +02:00
feat: npm-managed Python runtime for @kaelio/ktx (#7) * docs: add npm managed python runtime design * build: add bundled python runtime wheel builder * build: make local embedding dependencies optional * build: bundle python runtime wheel in cli artifacts * build: track bundled python runtime release artifact * test: verify bundled python runtime wheel * docs: add plan for bundled python runtime wheel * test: cover managed python runtime lifecycle * feat: add managed python runtime installer * feat: add runtime command runner * feat: expose runtime management commands * test: verify managed python runtime commands * docs: add plan for managed python runtime installer * feat: add managed python command helper * feat: use managed runtime for sl query compute * feat: route sl query managed runtime policy * docs: add plan for managed runtime sl query integration * feat: add managed runtime daemon metadata * feat: manage python daemon lifecycle * feat: add runtime daemon start stop commands * fix: verify managed runtime daemon lifecycle * docs: add plan for managed runtime daemon lifecycle * feat: add managed local embeddings config marker * feat: add managed local embeddings daemon helper * feat: use managed runtime for local embedding setup * feat: pass managed runtime policy through setup * docs: add plan for managed local embeddings runtime * feat: read CLI package metadata dynamically * feat: assemble public kaelio ktx npm package * feat: release one public kaelio ktx npm artifact * test: cover public kaelio ktx package invocations * chore: verify public kaelio ktx package artifacts * docs: add plan for public kaelio ktx npm package * test: verify managed runtime in public package smoke * test: finalize managed runtime release smoke * docs: add plan for managed runtime release smoke * test: specify local embeddings release smoke * feat: add local embeddings runtime smoke * chore: register local embeddings smoke * fix: verify local embeddings smoke * fix: restore artifact smoke python env helper * docs: add plan for managed local embeddings release smoke * refactor: share managed runtime install policy parsing * feat: use managed runtime for agent semantic queries * feat: use managed runtime for MCP semantic compute * docs: add plan for managed agent and MCP semantic runtime * feat(cli): add managed daemon HTTP helpers * feat(cli): route local adapters through managed daemon * feat(cli): use managed daemon for ingest helpers * feat(cli): pass managed daemon options to scan * feat(context): pass MCP ingest pull config options * feat(cli): pass managed daemon options to serve ingest * test: verify managed local ingest daemon runtime * docs: add plan for managed local ingest daemon runtime * docs: align managed runtime examples * docs: add plan for managed runtime docs cleanup * test: cover published package runtime smoke commands * test: validate published package smoke outputs * docs: add plan for published package runtime smoke * build: stamp public npm package version * release: add npm public release policy * release: add guarded npm publish script * release: document public npm release handoff * docs: add plan for public npm release handoff * test: cover managed runtime prune in package smoke * docs: document managed runtime prune * docs: add plan for managed runtime prune smoke and docs * chore: encode uv runtime prerequisite policy * fix: clarify missing uv runtime error * docs: document uv runtime prerequisite * docs: add plan for uv runtime prerequisite contract * refactor: limit release artifacts to public package runtime * chore: align release policy with bundled runtime wheel * docs: describe single public runtime artifact surface * test: verify single public runtime artifact contract * docs: add plan for single public runtime artifact cleanup * fix: align local embeddings smoke with public version * docs: add plan for local embeddings smoke public version * release: soft-launch as @kaelio/ktx@0.1.0-rc.0 on next tag Publish target moves to the pre-release version 0.1.0-rc.0 under the next dist-tag so npm install @kaelio/ktx (which resolves to latest) does not pick up the soft-launch build. Users opt in via @kaelio/ktx@next. * Fix release script boundary checks * Remove PostHog from public package bundle
2026-05-11 15:50:34 +02:00
function makeManagedRuntimeIo() {
let stdout = '';
let stderr = '';
return {
io: {
stdout: { write: (chunk: string) => (stdout += chunk) },
stderr: { write: (chunk: string) => (stderr += chunk) },
},
stdout: () => stdout,
stderr: () => stderr,
};
}
2026-05-10 23:51:24 +02:00
describe('runKtxServeStdio', () => {
2026-05-10 23:12:26 +02:00
it('loads the project, creates local ports, and connects the server to stdio', async () => {
const connect = vi.fn().mockResolvedValue(undefined);
const project = {
2026-05-10 23:51:24 +02:00
projectDir: '/tmp/ktx-project',
2026-05-10 23:12:26 +02:00
config: {
connections: {},
llm: {
provider: { backend: 'gateway' },
models: { default: 'anthropic/claude-sonnet' },
},
},
} as never;
const loadProject = vi.fn().mockResolvedValue(project);
const contextTools = { connections: { list: vi.fn() } };
const createContextTools = vi.fn().mockReturnValue(contextTools);
const createServer = vi.fn().mockReturnValue({ connect });
const createTransport = vi.fn().mockReturnValue({ kind: 'stdio' });
let stderr = '';
await expect(
2026-05-10 23:51:24 +02:00
runKtxServeStdio(
2026-05-10 23:12:26 +02:00
{
mcp: 'stdio',
2026-05-10 23:51:24 +02:00
projectDir: '/tmp/ktx-project',
2026-05-10 23:12:26 +02:00
userId: 'agent',
semanticCompute: false,
semanticComputeUrl: undefined,
databaseIntrospectionUrl: undefined,
executeQueries: false,
memoryCapture: false,
memoryModel: undefined,
},
{
loadProject,
createContextTools,
createServer,
createTransport,
stderr: { write: (chunk: string) => (stderr += chunk) },
},
),
).resolves.toBe(0);
2026-05-10 23:51:24 +02:00
expect(loadProject).toHaveBeenCalledWith({ projectDir: '/tmp/ktx-project' });
2026-05-10 23:12:26 +02:00
expect(createContextTools).toHaveBeenCalledWith(
project,
expect.objectContaining({
localIngest: expect.objectContaining({
adapters: expect.any(Array),
}),
localScan: expect.objectContaining({
adapters: expect.any(Array),
}),
}),
);
expect(createServer).toHaveBeenCalledWith({
2026-05-10 23:51:24 +02:00
name: 'ktx',
2026-05-10 23:12:26 +02:00
version: '0.0.0-private',
userContext: { userId: 'agent' },
contextTools,
memoryCapture: undefined,
});
expect(connect).toHaveBeenCalledWith({ kind: 'stdio' });
2026-05-10 23:51:24 +02:00
expect(stderr).toContain('ktx MCP server running on stdio for /tmp/ktx-project');
2026-05-10 23:12:26 +02:00
});
it('enables local ingest ports by default when serving stdio', async () => {
2026-05-10 23:51:24 +02:00
const project = { projectDir: '/tmp/ktx-project', config: { connections: {} } } as never;
2026-05-10 23:12:26 +02:00
const connect = vi.fn().mockResolvedValue(undefined);
const createContextTools = vi.fn(() => ({ connections: { list: async () => [] } }));
await expect(
2026-05-10 23:51:24 +02:00
runKtxServeStdio(
2026-05-10 23:12:26 +02:00
{
mcp: 'stdio',
2026-05-10 23:51:24 +02:00
projectDir: '/tmp/ktx-project',
2026-05-10 23:12:26 +02:00
userId: 'agent',
semanticCompute: false,
semanticComputeUrl: undefined,
databaseIntrospectionUrl: undefined,
executeQueries: false,
memoryCapture: false,
memoryModel: undefined,
},
{
loadProject: async () => project,
createContextTools,
createServer: vi.fn(() => ({ connect }) as never),
createTransport: vi.fn(() => ({}) as never),
stderr: { write: vi.fn() },
},
),
).resolves.toBe(0);
expect(createContextTools).toHaveBeenCalledWith(
project,
expect.objectContaining({
localIngest: expect.objectContaining({
adapters: expect.any(Array),
}),
localScan: expect.objectContaining({
adapters: expect.any(Array),
}),
}),
);
});
it('passes daemon database introspection URL to MCP local ingest adapters', async () => {
2026-05-10 23:51:24 +02:00
const project = { projectDir: '/tmp/ktx-project', config: { connections: {} } } as never;
2026-05-10 23:12:26 +02:00
const connect = vi.fn().mockResolvedValue(undefined);
const createContextTools = vi.fn(() => ({ connections: { list: async () => [] } }));
const createdAdapters: SourceAdapter[] = [];
const createIngestAdapters = vi.fn(() => createdAdapters);
await expect(
2026-05-10 23:51:24 +02:00
runKtxServeStdio(
2026-05-10 23:12:26 +02:00
{
mcp: 'stdio',
2026-05-10 23:51:24 +02:00
projectDir: '/tmp/ktx-project',
2026-05-10 23:12:26 +02:00
userId: 'agent',
semanticCompute: false,
semanticComputeUrl: undefined,
databaseIntrospectionUrl: 'http://127.0.0.1:8765',
executeQueries: false,
memoryCapture: false,
memoryModel: undefined,
},
{
loadProject: async () => project,
createContextTools,
createIngestAdapters,
createServer: vi.fn(() => ({ connect }) as never),
createTransport: vi.fn(() => ({}) as never),
stderr: { write: vi.fn() },
},
),
).resolves.toBe(0);
expect(createContextTools).toHaveBeenCalledWith(
project,
expect.objectContaining({
localIngest: expect.objectContaining({
adapters: expect.any(Array),
feat: npm-managed Python runtime for @kaelio/ktx (#7) * docs: add npm managed python runtime design * build: add bundled python runtime wheel builder * build: make local embedding dependencies optional * build: bundle python runtime wheel in cli artifacts * build: track bundled python runtime release artifact * test: verify bundled python runtime wheel * docs: add plan for bundled python runtime wheel * test: cover managed python runtime lifecycle * feat: add managed python runtime installer * feat: add runtime command runner * feat: expose runtime management commands * test: verify managed python runtime commands * docs: add plan for managed python runtime installer * feat: add managed python command helper * feat: use managed runtime for sl query compute * feat: route sl query managed runtime policy * docs: add plan for managed runtime sl query integration * feat: add managed runtime daemon metadata * feat: manage python daemon lifecycle * feat: add runtime daemon start stop commands * fix: verify managed runtime daemon lifecycle * docs: add plan for managed runtime daemon lifecycle * feat: add managed local embeddings config marker * feat: add managed local embeddings daemon helper * feat: use managed runtime for local embedding setup * feat: pass managed runtime policy through setup * docs: add plan for managed local embeddings runtime * feat: read CLI package metadata dynamically * feat: assemble public kaelio ktx npm package * feat: release one public kaelio ktx npm artifact * test: cover public kaelio ktx package invocations * chore: verify public kaelio ktx package artifacts * docs: add plan for public kaelio ktx npm package * test: verify managed runtime in public package smoke * test: finalize managed runtime release smoke * docs: add plan for managed runtime release smoke * test: specify local embeddings release smoke * feat: add local embeddings runtime smoke * chore: register local embeddings smoke * fix: verify local embeddings smoke * fix: restore artifact smoke python env helper * docs: add plan for managed local embeddings release smoke * refactor: share managed runtime install policy parsing * feat: use managed runtime for agent semantic queries * feat: use managed runtime for MCP semantic compute * docs: add plan for managed agent and MCP semantic runtime * feat(cli): add managed daemon HTTP helpers * feat(cli): route local adapters through managed daemon * feat(cli): use managed daemon for ingest helpers * feat(cli): pass managed daemon options to scan * feat(context): pass MCP ingest pull config options * feat(cli): pass managed daemon options to serve ingest * test: verify managed local ingest daemon runtime * docs: add plan for managed local ingest daemon runtime * docs: align managed runtime examples * docs: add plan for managed runtime docs cleanup * test: cover published package runtime smoke commands * test: validate published package smoke outputs * docs: add plan for published package runtime smoke * build: stamp public npm package version * release: add npm public release policy * release: add guarded npm publish script * release: document public npm release handoff * docs: add plan for public npm release handoff * test: cover managed runtime prune in package smoke * docs: document managed runtime prune * docs: add plan for managed runtime prune smoke and docs * chore: encode uv runtime prerequisite policy * fix: clarify missing uv runtime error * docs: document uv runtime prerequisite * docs: add plan for uv runtime prerequisite contract * refactor: limit release artifacts to public package runtime * chore: align release policy with bundled runtime wheel * docs: describe single public runtime artifact surface * test: verify single public runtime artifact contract * docs: add plan for single public runtime artifact cleanup * fix: align local embeddings smoke with public version * docs: add plan for local embeddings smoke public version * release: soft-launch as @kaelio/ktx@0.1.0-rc.0 on next tag Publish target moves to the pre-release version 0.1.0-rc.0 under the next dist-tag so npm install @kaelio/ktx (which resolves to latest) does not pick up the soft-launch build. Users opt in via @kaelio/ktx@next. * Fix release script boundary checks * Remove PostHog from public package bundle
2026-05-11 15:50:34 +02:00
pullConfigOptions: {
databaseIntrospectionUrl: 'http://127.0.0.1:8765',
},
2026-05-10 23:12:26 +02:00
}),
localScan: expect.objectContaining({
adapters: createdAdapters,
databaseIntrospectionUrl: 'http://127.0.0.1:8765',
}),
}),
);
expect(createIngestAdapters).toHaveBeenCalledWith(project, {
databaseIntrospectionUrl: 'http://127.0.0.1:8765',
});
});
feat: npm-managed Python runtime for @kaelio/ktx (#7) * docs: add npm managed python runtime design * build: add bundled python runtime wheel builder * build: make local embedding dependencies optional * build: bundle python runtime wheel in cli artifacts * build: track bundled python runtime release artifact * test: verify bundled python runtime wheel * docs: add plan for bundled python runtime wheel * test: cover managed python runtime lifecycle * feat: add managed python runtime installer * feat: add runtime command runner * feat: expose runtime management commands * test: verify managed python runtime commands * docs: add plan for managed python runtime installer * feat: add managed python command helper * feat: use managed runtime for sl query compute * feat: route sl query managed runtime policy * docs: add plan for managed runtime sl query integration * feat: add managed runtime daemon metadata * feat: manage python daemon lifecycle * feat: add runtime daemon start stop commands * fix: verify managed runtime daemon lifecycle * docs: add plan for managed runtime daemon lifecycle * feat: add managed local embeddings config marker * feat: add managed local embeddings daemon helper * feat: use managed runtime for local embedding setup * feat: pass managed runtime policy through setup * docs: add plan for managed local embeddings runtime * feat: read CLI package metadata dynamically * feat: assemble public kaelio ktx npm package * feat: release one public kaelio ktx npm artifact * test: cover public kaelio ktx package invocations * chore: verify public kaelio ktx package artifacts * docs: add plan for public kaelio ktx npm package * test: verify managed runtime in public package smoke * test: finalize managed runtime release smoke * docs: add plan for managed runtime release smoke * test: specify local embeddings release smoke * feat: add local embeddings runtime smoke * chore: register local embeddings smoke * fix: verify local embeddings smoke * fix: restore artifact smoke python env helper * docs: add plan for managed local embeddings release smoke * refactor: share managed runtime install policy parsing * feat: use managed runtime for agent semantic queries * feat: use managed runtime for MCP semantic compute * docs: add plan for managed agent and MCP semantic runtime * feat(cli): add managed daemon HTTP helpers * feat(cli): route local adapters through managed daemon * feat(cli): use managed daemon for ingest helpers * feat(cli): pass managed daemon options to scan * feat(context): pass MCP ingest pull config options * feat(cli): pass managed daemon options to serve ingest * test: verify managed local ingest daemon runtime * docs: add plan for managed local ingest daemon runtime * docs: align managed runtime examples * docs: add plan for managed runtime docs cleanup * test: cover published package runtime smoke commands * test: validate published package smoke outputs * docs: add plan for published package runtime smoke * build: stamp public npm package version * release: add npm public release policy * release: add guarded npm publish script * release: document public npm release handoff * docs: add plan for public npm release handoff * test: cover managed runtime prune in package smoke * docs: document managed runtime prune * docs: add plan for managed runtime prune smoke and docs * chore: encode uv runtime prerequisite policy * fix: clarify missing uv runtime error * docs: document uv runtime prerequisite * docs: add plan for uv runtime prerequisite contract * refactor: limit release artifacts to public package runtime * chore: align release policy with bundled runtime wheel * docs: describe single public runtime artifact surface * test: verify single public runtime artifact contract * docs: add plan for single public runtime artifact cleanup * fix: align local embeddings smoke with public version * docs: add plan for local embeddings smoke public version * release: soft-launch as @kaelio/ktx@0.1.0-rc.0 on next tag Publish target moves to the pre-release version 0.1.0-rc.0 under the next dist-tag so npm install @kaelio/ktx (which resolves to latest) does not pick up the soft-launch build. Users opt in via @kaelio/ktx@next. * Fix release script boundary checks * Remove PostHog from public package bundle
2026-05-11 15:50:34 +02:00
it('passes managed daemon options to MCP local ingest adapters and pull-config options', async () => {
const project = { projectDir: '/tmp/ktx-project', config: { connections: {} } } as never;
const adapters: SourceAdapter[] = [
{ source: 'looker', skillNames: [], detect: async () => true, chunk: async () => ({ workUnits: [] }) },
];
const createIngestAdapters = vi.fn(() => adapters);
const createContextTools = vi.fn(() => ({ connections: { list: async () => [] } }));
const managedRuntimeIo = makeManagedRuntimeIo();
await expect(
runKtxServeStdio(
{
mcp: 'stdio',
projectDir: '/tmp/ktx-project',
userId: 'agent',
semanticCompute: false,
semanticComputeUrl: undefined,
databaseIntrospectionUrl: undefined,
executeQueries: false,
memoryCapture: false,
memoryModel: undefined,
cliVersion: '0.2.0',
runtimeInstallPolicy: 'auto',
},
{
loadProject: async () => project,
createContextTools,
createIngestAdapters,
managedRuntimeIo: managedRuntimeIo.io,
createServer: vi.fn(() => ({ connect: vi.fn(async () => undefined) }) as never),
createTransport: vi.fn(() => ({}) as never),
stderr: { write: vi.fn() },
},
),
).resolves.toBe(0);
const expectedManagedDaemon = {
cliVersion: '0.2.0',
installPolicy: 'auto',
io: managedRuntimeIo.io,
};
expect(createIngestAdapters).toHaveBeenCalledWith(project, {
managedDaemon: expectedManagedDaemon,
});
expect(createContextTools).toHaveBeenCalledWith(
project,
expect.objectContaining({
localIngest: expect.objectContaining({
adapters,
pullConfigOptions: {
managedDaemon: expectedManagedDaemon,
},
}),
}),
);
});
2026-05-10 23:12:26 +02:00
it('uses CLI-native local ingest adapters for standalone scan tools', async () => {
2026-05-10 23:51:24 +02:00
const project = { projectDir: '/tmp/ktx-project', config: { connections: {} } } as never;
2026-05-10 23:12:26 +02:00
const createContextTools = vi.fn(() => ({}) as never);
2026-05-10 23:51:24 +02:00
await runKtxServeStdio(
2026-05-10 23:12:26 +02:00
{
mcp: 'stdio',
2026-05-10 23:51:24 +02:00
projectDir: '/tmp/ktx-project',
2026-05-10 23:12:26 +02:00
userId: 'local',
semanticCompute: false,
executeQueries: false,
memoryCapture: false,
},
{
loadProject: vi.fn(async () => project),
createContextTools,
createServer: vi.fn(() => ({ connect: vi.fn(async () => undefined) }) as never),
createTransport: vi.fn(() => ({}) as never),
stderr: { write: vi.fn() },
},
);
expect(createContextTools).toHaveBeenCalledWith(
project,
expect.objectContaining({
localIngest: expect.objectContaining({ adapters: expect.any(Array) }),
localScan: expect.objectContaining({ adapters: expect.any(Array) }),
}),
);
});
it('passes semantic compute to local project ports when enabled', async () => {
2026-05-10 23:51:24 +02:00
const tempDir = await mkdtemp(join(tmpdir(), 'ktx-cli-serve-'));
2026-05-10 23:12:26 +02:00
try {
2026-05-10 23:51:24 +02:00
const project = await initKtxProject({ projectDir: tempDir, projectName: 'warehouse' });
2026-05-10 23:12:26 +02:00
const createContextTools = vi.fn(() => ({ connections: { list: async () => [] } }));
const semanticLayerCompute = { query: vi.fn(), validateSources: vi.fn(), generateSources: vi.fn() };
await expect(
2026-05-10 23:51:24 +02:00
runKtxServeStdio(
2026-05-10 23:12:26 +02:00
{
mcp: 'stdio',
projectDir: project.projectDir,
userId: 'local',
semanticCompute: true,
semanticComputeUrl: undefined,
databaseIntrospectionUrl: undefined,
executeQueries: false,
memoryCapture: false,
memoryModel: undefined,
},
{
loadProject: async () => project,
createContextTools,
createSemanticLayerCompute: () => semanticLayerCompute,
createServer: vi.fn(() => ({ connect: vi.fn(async () => undefined) }) as never),
createTransport: vi.fn(() => ({}) as never),
stderr: { write: vi.fn() },
},
),
).resolves.toBe(0);
expect(createContextTools).toHaveBeenCalledWith(
project,
expect.objectContaining({
semanticLayerCompute,
localIngest: expect.objectContaining({
adapters: expect.any(Array),
semanticLayerCompute,
}),
localScan: expect.objectContaining({
adapters: expect.any(Array),
}),
}),
);
} finally {
await rm(tempDir, { recursive: true, force: true });
}
});
feat: npm-managed Python runtime for @kaelio/ktx (#7) * docs: add npm managed python runtime design * build: add bundled python runtime wheel builder * build: make local embedding dependencies optional * build: bundle python runtime wheel in cli artifacts * build: track bundled python runtime release artifact * test: verify bundled python runtime wheel * docs: add plan for bundled python runtime wheel * test: cover managed python runtime lifecycle * feat: add managed python runtime installer * feat: add runtime command runner * feat: expose runtime management commands * test: verify managed python runtime commands * docs: add plan for managed python runtime installer * feat: add managed python command helper * feat: use managed runtime for sl query compute * feat: route sl query managed runtime policy * docs: add plan for managed runtime sl query integration * feat: add managed runtime daemon metadata * feat: manage python daemon lifecycle * feat: add runtime daemon start stop commands * fix: verify managed runtime daemon lifecycle * docs: add plan for managed runtime daemon lifecycle * feat: add managed local embeddings config marker * feat: add managed local embeddings daemon helper * feat: use managed runtime for local embedding setup * feat: pass managed runtime policy through setup * docs: add plan for managed local embeddings runtime * feat: read CLI package metadata dynamically * feat: assemble public kaelio ktx npm package * feat: release one public kaelio ktx npm artifact * test: cover public kaelio ktx package invocations * chore: verify public kaelio ktx package artifacts * docs: add plan for public kaelio ktx npm package * test: verify managed runtime in public package smoke * test: finalize managed runtime release smoke * docs: add plan for managed runtime release smoke * test: specify local embeddings release smoke * feat: add local embeddings runtime smoke * chore: register local embeddings smoke * fix: verify local embeddings smoke * fix: restore artifact smoke python env helper * docs: add plan for managed local embeddings release smoke * refactor: share managed runtime install policy parsing * feat: use managed runtime for agent semantic queries * feat: use managed runtime for MCP semantic compute * docs: add plan for managed agent and MCP semantic runtime * feat(cli): add managed daemon HTTP helpers * feat(cli): route local adapters through managed daemon * feat(cli): use managed daemon for ingest helpers * feat(cli): pass managed daemon options to scan * feat(context): pass MCP ingest pull config options * feat(cli): pass managed daemon options to serve ingest * test: verify managed local ingest daemon runtime * docs: add plan for managed local ingest daemon runtime * docs: align managed runtime examples * docs: add plan for managed runtime docs cleanup * test: cover published package runtime smoke commands * test: validate published package smoke outputs * docs: add plan for published package runtime smoke * build: stamp public npm package version * release: add npm public release policy * release: add guarded npm publish script * release: document public npm release handoff * docs: add plan for public npm release handoff * test: cover managed runtime prune in package smoke * docs: document managed runtime prune * docs: add plan for managed runtime prune smoke and docs * chore: encode uv runtime prerequisite policy * fix: clarify missing uv runtime error * docs: document uv runtime prerequisite * docs: add plan for uv runtime prerequisite contract * refactor: limit release artifacts to public package runtime * chore: align release policy with bundled runtime wheel * docs: describe single public runtime artifact surface * test: verify single public runtime artifact contract * docs: add plan for single public runtime artifact cleanup * fix: align local embeddings smoke with public version * docs: add plan for local embeddings smoke public version * release: soft-launch as @kaelio/ktx@0.1.0-rc.0 on next tag Publish target moves to the pre-release version 0.1.0-rc.0 under the next dist-tag so npm install @kaelio/ktx (which resolves to latest) does not pick up the soft-launch build. Users opt in via @kaelio/ktx@next. * Fix release script boundary checks * Remove PostHog from public package bundle
2026-05-11 15:50:34 +02:00
it('uses managed semantic compute when MCP semantic compute has no explicit HTTP URL', async () => {
const project = { projectDir: '/tmp/ktx-project', config: { connections: {} } } as never;
const semanticLayerCompute = { query: vi.fn(), validateSources: vi.fn(), generateSources: vi.fn() };
const createManagedSemanticLayerCompute = vi.fn(async () => semanticLayerCompute);
const createContextTools = vi.fn(() => ({ connections: { list: async () => [] } }));
const managedRuntimeIo = makeManagedRuntimeIo();
await expect(
runKtxServeStdio(
{
mcp: 'stdio',
projectDir: '/tmp/ktx-project',
userId: 'agent',
semanticCompute: true,
semanticComputeUrl: undefined,
databaseIntrospectionUrl: undefined,
executeQueries: false,
memoryCapture: false,
memoryModel: undefined,
cliVersion: '0.2.0',
runtimeInstallPolicy: 'auto',
},
{
loadProject: async () => project,
createContextTools,
createManagedSemanticLayerCompute,
managedRuntimeIo: managedRuntimeIo.io,
createServer: vi.fn(() => ({ connect: vi.fn(async () => undefined) }) as never),
createTransport: vi.fn(() => ({}) as never),
stderr: { write: vi.fn() },
},
),
).resolves.toBe(0);
expect(createManagedSemanticLayerCompute).toHaveBeenCalledWith({
cliVersion: '0.2.0',
installPolicy: 'auto',
io: managedRuntimeIo.io,
});
expect(createContextTools).toHaveBeenCalledWith(
project,
expect.objectContaining({
semanticLayerCompute,
}),
);
});
2026-05-10 23:12:26 +02:00
it('uses the HTTP semantic compute port when a daemon URL is provided', async () => {
2026-05-10 23:51:24 +02:00
const project = { projectDir: '/tmp/ktx-project', config: { connections: {} } } as never;
2026-05-10 23:12:26 +02:00
const semanticLayerCompute = { query: vi.fn(), validateSources: vi.fn(), generateSources: vi.fn() };
const createHttpSemanticLayerCompute = vi.fn(() => semanticLayerCompute);
const createContextTools = vi.fn(() => ({ connections: { list: async () => [] } }));
await expect(
2026-05-10 23:51:24 +02:00
runKtxServeStdio(
2026-05-10 23:12:26 +02:00
{
mcp: 'stdio',
2026-05-10 23:51:24 +02:00
projectDir: '/tmp/ktx-project',
2026-05-10 23:12:26 +02:00
userId: 'agent',
semanticCompute: true,
semanticComputeUrl: 'http://127.0.0.1:8765',
databaseIntrospectionUrl: undefined,
executeQueries: false,
memoryCapture: false,
memoryModel: undefined,
},
{
loadProject: async () => project,
createContextTools,
createHttpSemanticLayerCompute,
createServer: vi.fn(() => ({ connect: vi.fn(async () => undefined) }) as never),
createTransport: vi.fn(() => ({}) as never),
stderr: { write: vi.fn() },
},
),
).resolves.toBe(0);
expect(createHttpSemanticLayerCompute).toHaveBeenCalledWith('http://127.0.0.1:8765');
expect(createContextTools).toHaveBeenCalledWith(
project,
expect.objectContaining({
semanticLayerCompute,
}),
);
});
it('passes a query executor to local project ports only when query execution is enabled', async () => {
2026-05-10 23:51:24 +02:00
const project = { projectDir: '/tmp/ktx-project', config: { connections: {} } } as never;
2026-05-10 23:12:26 +02:00
const connect = vi.fn().mockResolvedValue(undefined);
const createContextTools = vi.fn(() => ({ connections: { list: async () => [] } }));
const semanticLayerCompute = { query: vi.fn(), validateSources: vi.fn(), generateSources: vi.fn() };
const queryExecutor = { execute: vi.fn() };
await expect(
2026-05-10 23:51:24 +02:00
runKtxServeStdio(
2026-05-10 23:12:26 +02:00
{
mcp: 'stdio',
2026-05-10 23:51:24 +02:00
projectDir: '/tmp/ktx-project',
2026-05-10 23:12:26 +02:00
userId: 'agent',
semanticCompute: true,
semanticComputeUrl: undefined,
databaseIntrospectionUrl: undefined,
executeQueries: true,
memoryCapture: false,
memoryModel: undefined,
},
{
loadProject: async () => project,
createContextTools,
createSemanticLayerCompute: () => semanticLayerCompute,
createQueryExecutor: () => queryExecutor,
createServer: vi.fn(() => ({ connect }) as never),
createTransport: vi.fn(() => ({}) as never),
stderr: { write: vi.fn() },
},
),
).resolves.toBe(0);
expect(createContextTools).toHaveBeenCalledWith(
project,
expect.objectContaining({
semanticLayerCompute,
queryExecutor,
localIngest: expect.objectContaining({
adapters: expect.any(Array),
semanticLayerCompute,
queryExecutor,
}),
localScan: expect.objectContaining({
adapters: expect.any(Array),
}),
}),
);
});
it('creates a local memory capture port when memory capture is enabled', async () => {
const project = {
2026-05-10 23:51:24 +02:00
projectDir: '/tmp/ktx-project',
2026-05-10 23:12:26 +02:00
config: {
connections: {},
llm: {
provider: { backend: 'gateway' },
models: { default: 'anthropic/claude-sonnet' },
},
},
} as never;
const connect = vi.fn().mockResolvedValue(undefined);
const contextTools = { connections: { list: vi.fn() } };
const memoryCapture = { capture: vi.fn(), status: vi.fn() };
const createContextTools = vi.fn().mockReturnValue(contextTools);
const createMemoryCapture = vi.fn().mockReturnValue(memoryCapture);
const createServer = vi.fn().mockReturnValue({ connect });
await expect(
2026-05-10 23:51:24 +02:00
runKtxServeStdio(
2026-05-10 23:12:26 +02:00
{
mcp: 'stdio',
2026-05-10 23:51:24 +02:00
projectDir: '/tmp/ktx-project',
2026-05-10 23:12:26 +02:00
userId: 'agent',
semanticCompute: false,
semanticComputeUrl: undefined,
databaseIntrospectionUrl: undefined,
executeQueries: false,
memoryCapture: true,
memoryModel: 'anthropic/claude-sonnet',
},
{
loadProject: async () => project,
createContextTools,
createMemoryCapture,
createServer,
createTransport: vi.fn(() => ({}) as never),
stderr: { write: vi.fn() },
},
),
).resolves.toBe(0);
expect(createMemoryCapture).toHaveBeenCalledWith(project, {
llmProvider: expect.objectContaining({ getModel: expect.any(Function) }),
semanticLayerCompute: undefined,
});
expect(createServer).toHaveBeenCalledWith({
2026-05-10 23:51:24 +02:00
name: 'ktx',
2026-05-10 23:12:26 +02:00
version: '0.0.0-private',
userContext: { userId: 'agent' },
contextTools,
memoryCapture,
});
});
it('reuses semantic compute for local memory capture when enabled', async () => {
const project = {
2026-05-10 23:51:24 +02:00
projectDir: '/tmp/ktx-project',
2026-05-10 23:12:26 +02:00
config: {
connections: {},
llm: {
provider: { backend: 'gateway' },
models: { default: 'openai/gpt' },
},
},
} as never;
const semanticLayerCompute = { query: vi.fn(), validateSources: vi.fn(), generateSources: vi.fn() };
const createMemoryCapture = vi.fn().mockReturnValue({ capture: vi.fn(), status: vi.fn() });
await expect(
2026-05-10 23:51:24 +02:00
runKtxServeStdio(
2026-05-10 23:12:26 +02:00
{
mcp: 'stdio',
2026-05-10 23:51:24 +02:00
projectDir: '/tmp/ktx-project',
2026-05-10 23:12:26 +02:00
userId: 'agent',
semanticCompute: true,
semanticComputeUrl: undefined,
databaseIntrospectionUrl: undefined,
executeQueries: false,
memoryCapture: true,
memoryModel: 'openai/gpt',
},
{
loadProject: async () => project,
createContextTools: vi.fn(() => ({ connections: { list: async () => [] } })),
createSemanticLayerCompute: () => semanticLayerCompute,
createMemoryCapture,
createServer: vi.fn(() => ({ connect: vi.fn(async () => undefined) }) as never),
createTransport: vi.fn(() => ({}) as never),
stderr: { write: vi.fn() },
},
),
).resolves.toBe(0);
expect(createMemoryCapture).toHaveBeenCalledWith(project, {
llmProvider: expect.objectContaining({ getModel: expect.any(Function) }),
semanticLayerCompute,
});
});
});