2026-05-11 15:50:34 +02:00
|
|
|
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
|
|
|
|
|
import { tmpdir } from 'node:os';
|
|
|
|
|
import { join } from 'node:path';
|
|
|
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
|
import {
|
test: split cli tests from source tree (#216)
* 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
2026-05-26 08:49:05 +02:00
|
|
|
ManagedPythonDaemonStartError,
|
2026-05-11 15:50:34 +02:00
|
|
|
readManagedPythonDaemonStatus,
|
|
|
|
|
startManagedPythonDaemon,
|
2026-05-12 13:00:08 +02:00
|
|
|
stopAllManagedPythonDaemons,
|
2026-05-11 15:50:34 +02:00
|
|
|
stopManagedPythonDaemon,
|
|
|
|
|
type ManagedPythonDaemonChild,
|
|
|
|
|
type ManagedPythonDaemonFetch,
|
2026-05-12 13:00:08 +02:00
|
|
|
type ManagedPythonDaemonProcessInfo,
|
2026-05-11 15:50:34 +02:00
|
|
|
type ManagedPythonDaemonSpawn,
|
|
|
|
|
type ManagedPythonDaemonState,
|
test: split cli tests from source tree (#216)
* 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
2026-05-26 08:49:05 +02:00
|
|
|
} from '../src/managed-python-daemon.js';
|
2026-05-11 15:50:34 +02:00
|
|
|
import type {
|
|
|
|
|
InstalledKtxRuntimeManifest,
|
2026-05-14 14:35:55 +02:00
|
|
|
ManagedPythonDaemonLayout,
|
2026-05-11 15:50:34 +02:00
|
|
|
ManagedPythonRuntimeInstallResult,
|
|
|
|
|
ManagedPythonRuntimeLayout,
|
test: split cli tests from source tree (#216)
* 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
2026-05-26 08:49:05 +02:00
|
|
|
} from '../src/managed-python-runtime.js';
|
2026-05-11 15:50:34 +02:00
|
|
|
|
2026-05-14 14:35:55 +02:00
|
|
|
function layout(root: string): ManagedPythonDaemonLayout {
|
|
|
|
|
const projectDir = join(root, 'project');
|
2026-05-11 15:50:34 +02:00
|
|
|
return {
|
|
|
|
|
cliVersion: '0.2.0',
|
|
|
|
|
runtimeRoot: join(root, 'runtime'),
|
|
|
|
|
versionDir: join(root, 'runtime', '0.2.0'),
|
|
|
|
|
venvDir: join(root, 'runtime', '0.2.0', '.venv'),
|
|
|
|
|
manifestPath: join(root, 'runtime', '0.2.0', 'manifest.json'),
|
|
|
|
|
installLogPath: join(root, 'runtime', '0.2.0', 'install.log'),
|
|
|
|
|
assetDir: join(root, 'assets', 'python'),
|
|
|
|
|
assetManifestPath: join(root, 'assets', 'python', 'manifest.json'),
|
|
|
|
|
pythonPath: join(root, 'runtime', '0.2.0', '.venv', 'bin', 'python'),
|
|
|
|
|
daemonPath: join(root, 'runtime', '0.2.0', '.venv', 'bin', 'ktx-daemon'),
|
2026-05-14 14:35:55 +02:00
|
|
|
projectDir,
|
|
|
|
|
daemonStateDir: join(projectDir, '.ktx', 'runtime'),
|
|
|
|
|
daemonStatePath: join(projectDir, '.ktx', 'runtime', 'daemon.json'),
|
|
|
|
|
daemonStdoutPath: join(projectDir, '.ktx', 'runtime', 'daemon.stdout.log'),
|
|
|
|
|
daemonStderrPath: join(projectDir, '.ktx', 'runtime', 'daemon.stderr.log'),
|
2026-05-11 15:50:34 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-14 14:35:55 +02:00
|
|
|
function installLayout(root: string): ManagedPythonRuntimeLayout {
|
|
|
|
|
const { projectDir: _projectDir, daemonStateDir: _d, daemonStatePath: _ds, daemonStdoutPath: _so, daemonStderrPath: _se, ...rest } = layout(root);
|
|
|
|
|
return rest;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-11 15:50:34 +02:00
|
|
|
function manifest(root: string, features: Array<'core' | 'local-embeddings'> = ['core']): InstalledKtxRuntimeManifest {
|
|
|
|
|
const runtimeLayout = layout(root);
|
|
|
|
|
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: runtimeLayout.pythonPath,
|
|
|
|
|
daemonExecutable: runtimeLayout.daemonPath,
|
|
|
|
|
},
|
|
|
|
|
installLog: runtimeLayout.installLogPath,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function installResult(root: string, features: Array<'core' | 'local-embeddings'> = ['core']): ManagedPythonRuntimeInstallResult {
|
|
|
|
|
return {
|
|
|
|
|
status: 'ready',
|
2026-05-14 14:35:55 +02:00
|
|
|
layout: installLayout(root),
|
2026-05-11 15:50:34 +02:00
|
|
|
asset: {
|
|
|
|
|
manifest: manifest(root, features).asset,
|
|
|
|
|
wheelPath: join(root, 'assets', 'python', 'kaelio_ktx-0.2.0-py3-none-any.whl'),
|
2026-05-19 18:18:38 +02:00
|
|
|
requiresPython: { specifier: '>=3.13', minimumVersion: '3.13' },
|
2026-05-11 15:50:34 +02:00
|
|
|
},
|
|
|
|
|
manifest: manifest(root, features),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function makeFetch(version = '0.2.0'): ManagedPythonDaemonFetch {
|
|
|
|
|
return vi.fn(async () => ({
|
|
|
|
|
ok: true,
|
|
|
|
|
status: 200,
|
|
|
|
|
json: async () => ({ status: 'healthy', version }),
|
|
|
|
|
text: async () => '',
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function makeSpawn(pid = 4242): ManagedPythonDaemonSpawn {
|
|
|
|
|
return vi.fn((_command, _args, _options): ManagedPythonDaemonChild => ({
|
|
|
|
|
pid,
|
|
|
|
|
unref: vi.fn(),
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function runningState(root: string, overrides: Partial<ManagedPythonDaemonState> = {}): ManagedPythonDaemonState {
|
|
|
|
|
const runtimeLayout = layout(root);
|
|
|
|
|
return {
|
|
|
|
|
schemaVersion: 1,
|
|
|
|
|
pid: 4242,
|
|
|
|
|
host: '127.0.0.1',
|
|
|
|
|
port: 58731,
|
|
|
|
|
version: '0.2.0',
|
|
|
|
|
features: ['core'],
|
|
|
|
|
startedAt: '2026-05-11T00:00:00.000Z',
|
|
|
|
|
stdoutLog: runtimeLayout.daemonStdoutPath,
|
|
|
|
|
stderrLog: runtimeLayout.daemonStderrPath,
|
|
|
|
|
...overrides,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-14 14:35:55 +02:00
|
|
|
function daemonOptionsBase(root: string) {
|
2026-05-12 13:00:08 +02:00
|
|
|
return {
|
2026-05-14 14:35:55 +02:00
|
|
|
cliVersion: '0.2.0',
|
|
|
|
|
projectDir: layout(root).projectDir,
|
|
|
|
|
runtimeRoot: join(root, 'runtime'),
|
|
|
|
|
} as const;
|
2026-05-12 13:00:08 +02:00
|
|
|
}
|
|
|
|
|
|
refactor(release): drop release-policy.json runtime dep and next branch (#180)
* 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.
2026-05-20 13:53:14 +02:00
|
|
|
describe('KTX daemon lifecycle', () => {
|
2026-05-11 15:50:34 +02:00
|
|
|
let tempDir: string;
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
tempDir = await mkdtemp(join(tmpdir(), 'ktx-managed-daemon-'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(async () => {
|
2026-05-19 18:18:56 +02:00
|
|
|
vi.unstubAllEnvs();
|
2026-05-11 15:50:34 +02:00
|
|
|
await rm(tempDir, { recursive: true, force: true });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('reports stopped when no daemon state exists', async () => {
|
|
|
|
|
const status = await readManagedPythonDaemonStatus({
|
2026-05-14 14:35:55 +02:00
|
|
|
...daemonOptionsBase(tempDir),
|
2026-05-11 15:50:34 +02:00
|
|
|
processAlive: vi.fn(() => false),
|
|
|
|
|
fetch: makeFetch(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(status.kind).toBe('stopped');
|
|
|
|
|
expect(status.detail).toContain('No daemon state');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('starts ktx-daemon serve-http, waits for health, and writes state', async () => {
|
|
|
|
|
const spawnDaemon = makeSpawn(5555);
|
|
|
|
|
const installRuntime = vi.fn(async () => installResult(tempDir));
|
|
|
|
|
|
|
|
|
|
const result = await startManagedPythonDaemon({
|
2026-05-14 14:35:55 +02:00
|
|
|
...daemonOptionsBase(tempDir),
|
2026-05-11 15:50:34 +02:00
|
|
|
features: ['core'],
|
|
|
|
|
installRuntime,
|
|
|
|
|
spawnDaemon,
|
|
|
|
|
fetch: makeFetch(),
|
|
|
|
|
allocatePort: vi.fn(async () => 61234),
|
|
|
|
|
now: () => new Date('2026-05-11T00:00:00.000Z'),
|
|
|
|
|
pollIntervalMs: 1,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(result.status).toBe('started');
|
|
|
|
|
expect(result.baseUrl).toBe('http://127.0.0.1:61234');
|
|
|
|
|
expect(installRuntime).toHaveBeenCalledWith({
|
|
|
|
|
cliVersion: '0.2.0',
|
|
|
|
|
runtimeRoot: join(tempDir, 'runtime'),
|
|
|
|
|
features: ['core'],
|
|
|
|
|
force: false,
|
|
|
|
|
});
|
|
|
|
|
expect(spawnDaemon).toHaveBeenCalledWith(
|
|
|
|
|
layout(tempDir).daemonPath,
|
|
|
|
|
['serve-http', '--host', '127.0.0.1', '--port', '61234'],
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
detached: true,
|
|
|
|
|
env: expect.objectContaining({ KTX_DAEMON_VERSION: '0.2.0' }),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
expect(JSON.parse(await readFile(layout(tempDir).daemonStatePath, 'utf8'))).toMatchObject({
|
|
|
|
|
pid: 5555,
|
|
|
|
|
port: 61234,
|
|
|
|
|
version: '0.2.0',
|
|
|
|
|
features: ['core'],
|
|
|
|
|
stdoutLog: layout(tempDir).daemonStdoutPath,
|
|
|
|
|
stderrLog: layout(tempDir).daemonStderrPath,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-19 18:18:56 +02:00
|
|
|
it('sanitizes IPv6 CIDR entries from child NO_PROXY env', async () => {
|
|
|
|
|
vi.stubEnv('NO_PROXY', 'localhost,fd07:b51a:cc66:f0::/64,127.0.0.0/8');
|
|
|
|
|
vi.stubEnv('no_proxy', '::1,fd00::/8,*.orb.local');
|
|
|
|
|
const spawnDaemon = makeSpawn(5555);
|
|
|
|
|
|
|
|
|
|
await startManagedPythonDaemon({
|
|
|
|
|
...daemonOptionsBase(tempDir),
|
|
|
|
|
features: ['local-embeddings'],
|
|
|
|
|
installRuntime: vi.fn(async () => installResult(tempDir, ['core', 'local-embeddings'])),
|
|
|
|
|
spawnDaemon,
|
|
|
|
|
fetch: makeFetch(),
|
|
|
|
|
allocatePort: vi.fn(async () => 61234),
|
|
|
|
|
now: () => new Date('2026-05-11T00:00:00.000Z'),
|
|
|
|
|
pollIntervalMs: 1,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const env = vi.mocked(spawnDaemon).mock.calls[0]?.[2].env;
|
|
|
|
|
expect(env?.NO_PROXY).toBe('localhost,127.0.0.0/8,::1,*.orb.local');
|
|
|
|
|
expect(env?.no_proxy).toBe(env?.NO_PROXY);
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-12 10:26:01 +02:00
|
|
|
it('makes a final health probe before reporting startup failure', async () => {
|
|
|
|
|
const spawnDaemon = makeSpawn(5556);
|
|
|
|
|
const installRuntime = vi.fn(async () => installResult(tempDir));
|
|
|
|
|
const fetch = vi
|
|
|
|
|
.fn<ManagedPythonDaemonFetch>()
|
|
|
|
|
.mockRejectedValueOnce(new Error('fetch failed'))
|
|
|
|
|
.mockResolvedValueOnce({
|
|
|
|
|
ok: true,
|
|
|
|
|
status: 200,
|
|
|
|
|
json: async () => ({ status: 'healthy', version: '0.2.0' }),
|
|
|
|
|
text: async () => '',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await startManagedPythonDaemon({
|
2026-05-14 14:35:55 +02:00
|
|
|
...daemonOptionsBase(tempDir),
|
2026-05-12 10:26:01 +02:00
|
|
|
features: ['core'],
|
|
|
|
|
installRuntime,
|
|
|
|
|
spawnDaemon,
|
|
|
|
|
fetch,
|
|
|
|
|
allocatePort: vi.fn(async () => 61234),
|
|
|
|
|
now: () => new Date('2026-05-11T00:00:00.000Z'),
|
|
|
|
|
startupTimeoutMs: 5,
|
|
|
|
|
pollIntervalMs: 20,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(result.status).toBe('started');
|
|
|
|
|
expect(fetch).toHaveBeenCalledTimes(2);
|
|
|
|
|
expect(JSON.parse(await readFile(layout(tempDir).daemonStatePath, 'utf8'))).toMatchObject({
|
|
|
|
|
pid: 5556,
|
|
|
|
|
port: 61234,
|
|
|
|
|
version: '0.2.0',
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
test: split cli tests from source tree (#216)
* 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
2026-05-26 08:49:05 +02:00
|
|
|
it('kills the spawned daemon when the startup health check times out', async () => {
|
|
|
|
|
const spawnDaemon = makeSpawn(7777);
|
|
|
|
|
const killProcess = vi.fn();
|
|
|
|
|
const fetch = vi.fn<ManagedPythonDaemonFetch>().mockRejectedValue(new Error('fetch failed'));
|
|
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
startManagedPythonDaemon({
|
|
|
|
|
...daemonOptionsBase(tempDir),
|
|
|
|
|
features: ['core'],
|
|
|
|
|
installRuntime: vi.fn(async () => installResult(tempDir)),
|
|
|
|
|
spawnDaemon,
|
|
|
|
|
fetch,
|
|
|
|
|
processAlive: vi.fn(() => true),
|
|
|
|
|
killProcess,
|
|
|
|
|
allocatePort: vi.fn(async () => 61234),
|
|
|
|
|
now: () => new Date('2026-05-11T00:00:00.000Z'),
|
|
|
|
|
startupTimeoutMs: 5,
|
|
|
|
|
pollIntervalMs: 1,
|
|
|
|
|
}),
|
|
|
|
|
).rejects.toBeInstanceOf(ManagedPythonDaemonStartError);
|
|
|
|
|
|
|
|
|
|
expect(killProcess).toHaveBeenCalledWith(7777);
|
|
|
|
|
await expect(readFile(layout(tempDir).daemonStatePath, 'utf8')).rejects.toMatchObject({ code: 'ENOENT' });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('surfaces the underlying fetch cause in the startup failure message', async () => {
|
|
|
|
|
const cause = new Error('connect ECONNREFUSED 127.0.0.1:61234');
|
|
|
|
|
const fetchError = new Error('fetch failed');
|
|
|
|
|
(fetchError as Error & { cause?: unknown }).cause = cause;
|
|
|
|
|
|
|
|
|
|
const error = await startManagedPythonDaemon({
|
|
|
|
|
...daemonOptionsBase(tempDir),
|
|
|
|
|
features: ['core'],
|
|
|
|
|
installRuntime: vi.fn(async () => installResult(tempDir)),
|
|
|
|
|
spawnDaemon: makeSpawn(7778),
|
|
|
|
|
fetch: vi.fn<ManagedPythonDaemonFetch>().mockRejectedValue(fetchError),
|
|
|
|
|
processAlive: vi.fn(() => false),
|
|
|
|
|
killProcess: vi.fn(),
|
|
|
|
|
allocatePort: vi.fn(async () => 61234),
|
|
|
|
|
now: () => new Date('2026-05-11T00:00:00.000Z'),
|
|
|
|
|
startupTimeoutMs: 5,
|
|
|
|
|
pollIntervalMs: 1,
|
|
|
|
|
}).catch((value: unknown) => value);
|
|
|
|
|
|
|
|
|
|
expect(error).toBeInstanceOf(ManagedPythonDaemonStartError);
|
|
|
|
|
const startError = error as ManagedPythonDaemonStartError;
|
|
|
|
|
expect(startError.detail).toContain('fetch failed');
|
|
|
|
|
expect(startError.detail).toContain('ECONNREFUSED');
|
|
|
|
|
expect(startError.message).toContain('ECONNREFUSED');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('exposes the daemon stderr log path on startup failure', async () => {
|
|
|
|
|
const error = await startManagedPythonDaemon({
|
|
|
|
|
...daemonOptionsBase(tempDir),
|
|
|
|
|
features: ['core'],
|
|
|
|
|
installRuntime: vi.fn(async () => installResult(tempDir)),
|
|
|
|
|
spawnDaemon: makeSpawn(7779),
|
|
|
|
|
fetch: vi.fn<ManagedPythonDaemonFetch>().mockRejectedValue(new Error('fetch failed')),
|
|
|
|
|
processAlive: vi.fn(() => false),
|
|
|
|
|
killProcess: vi.fn(),
|
|
|
|
|
allocatePort: vi.fn(async () => 61234),
|
|
|
|
|
now: () => new Date('2026-05-11T00:00:00.000Z'),
|
|
|
|
|
startupTimeoutMs: 5,
|
|
|
|
|
pollIntervalMs: 1,
|
|
|
|
|
}).catch((value: unknown) => value);
|
|
|
|
|
|
|
|
|
|
expect(error).toBeInstanceOf(ManagedPythonDaemonStartError);
|
|
|
|
|
expect((error as ManagedPythonDaemonStartError).stderrLog).toBe(layout(tempDir).daemonStderrPath);
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-11 15:50:34 +02:00
|
|
|
it('reuses a healthy daemon with the requested feature set', async () => {
|
2026-05-14 14:35:55 +02:00
|
|
|
await mkdir(layout(tempDir).daemonStateDir, { recursive: true });
|
2026-05-11 15:50:34 +02:00
|
|
|
await writeFile(layout(tempDir).daemonStatePath, `${JSON.stringify(runningState(tempDir), null, 2)}\n`);
|
|
|
|
|
const spawnDaemon = makeSpawn(9999);
|
|
|
|
|
|
|
|
|
|
const result = await startManagedPythonDaemon({
|
2026-05-14 14:35:55 +02:00
|
|
|
...daemonOptionsBase(tempDir),
|
2026-05-11 15:50:34 +02:00
|
|
|
features: ['core'],
|
|
|
|
|
installRuntime: vi.fn(async () => installResult(tempDir)),
|
|
|
|
|
spawnDaemon,
|
|
|
|
|
fetch: makeFetch(),
|
|
|
|
|
processAlive: vi.fn(() => true),
|
|
|
|
|
pollIntervalMs: 1,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(result.status).toBe('reused');
|
|
|
|
|
expect(result.baseUrl).toBe('http://127.0.0.1:58731');
|
|
|
|
|
expect(spawnDaemon).not.toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('starts a fresh daemon when the previous state is stale', async () => {
|
2026-05-14 14:35:55 +02:00
|
|
|
await mkdir(layout(tempDir).daemonStateDir, { recursive: true });
|
2026-05-11 15:50:34 +02:00
|
|
|
await writeFile(
|
|
|
|
|
layout(tempDir).daemonStatePath,
|
|
|
|
|
`${JSON.stringify(runningState(tempDir, { version: '0.1.0' }), null, 2)}\n`,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const result = await startManagedPythonDaemon({
|
2026-05-14 14:35:55 +02:00
|
|
|
...daemonOptionsBase(tempDir),
|
2026-05-11 15:50:34 +02:00
|
|
|
features: ['core'],
|
|
|
|
|
installRuntime: vi.fn(async () => installResult(tempDir)),
|
|
|
|
|
spawnDaemon: makeSpawn(6666),
|
|
|
|
|
fetch: makeFetch(),
|
|
|
|
|
processAlive: vi.fn(() => true),
|
|
|
|
|
killProcess: vi.fn(),
|
|
|
|
|
allocatePort: vi.fn(async () => 61235),
|
|
|
|
|
now: () => new Date('2026-05-11T00:00:00.000Z'),
|
|
|
|
|
pollIntervalMs: 1,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(result.status).toBe('started');
|
|
|
|
|
expect(JSON.parse(await readFile(layout(tempDir).daemonStatePath, 'utf8'))).toMatchObject({
|
|
|
|
|
pid: 6666,
|
|
|
|
|
port: 61235,
|
|
|
|
|
version: '0.2.0',
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('stops a recorded daemon and removes the state file', async () => {
|
2026-05-14 14:35:55 +02:00
|
|
|
await mkdir(layout(tempDir).daemonStateDir, { recursive: true });
|
2026-05-11 15:50:34 +02:00
|
|
|
await writeFile(layout(tempDir).daemonStatePath, `${JSON.stringify(runningState(tempDir), null, 2)}\n`);
|
|
|
|
|
const killProcess = vi.fn();
|
|
|
|
|
|
|
|
|
|
const result = await stopManagedPythonDaemon({
|
2026-05-14 14:35:55 +02:00
|
|
|
...daemonOptionsBase(tempDir),
|
2026-05-11 15:50:34 +02:00
|
|
|
processAlive: vi.fn(() => true),
|
|
|
|
|
killProcess,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(result.status).toBe('stopped');
|
|
|
|
|
expect(killProcess).toHaveBeenCalledWith(4242);
|
|
|
|
|
await expect(readFile(layout(tempDir).daemonStatePath, 'utf8')).rejects.toThrow();
|
|
|
|
|
});
|
2026-05-12 13:00:08 +02:00
|
|
|
|
2026-05-14 14:35:55 +02:00
|
|
|
it('stops the recorded daemon for this project and removes the state file', async () => {
|
|
|
|
|
await mkdir(layout(tempDir).daemonStateDir, { recursive: true });
|
|
|
|
|
await writeFile(layout(tempDir).daemonStatePath, `${JSON.stringify(runningState(tempDir), null, 2)}\n`);
|
|
|
|
|
const alive = new Set([4242]);
|
2026-05-12 13:00:08 +02:00
|
|
|
const killProcess = vi.fn((pid: number) => {
|
|
|
|
|
alive.delete(pid);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await stopAllManagedPythonDaemons({
|
2026-05-14 14:35:55 +02:00
|
|
|
...daemonOptionsBase(tempDir),
|
2026-05-12 13:00:08 +02:00
|
|
|
listProcesses: vi.fn(async () => []),
|
|
|
|
|
processAlive: vi.fn((pid) => alive.has(pid)),
|
|
|
|
|
killProcess,
|
|
|
|
|
stopGraceMs: 0,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(result.failed).toHaveLength(0);
|
2026-05-14 14:35:55 +02:00
|
|
|
expect(result.stopped.map((entry) => entry.pid)).toEqual([4242]);
|
|
|
|
|
expect(killProcess).toHaveBeenCalledWith(4242, 'SIGTERM');
|
|
|
|
|
await expect(readFile(layout(tempDir).daemonStatePath, 'utf8')).rejects.toThrow();
|
2026-05-12 13:00:08 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('removes stale state when the recorded daemon process is no longer alive', async () => {
|
2026-05-14 14:35:55 +02:00
|
|
|
await mkdir(layout(tempDir).daemonStateDir, { recursive: true });
|
2026-05-12 13:00:08 +02:00
|
|
|
await writeFile(layout(tempDir).daemonStatePath, `${JSON.stringify(runningState(tempDir), null, 2)}\n`);
|
|
|
|
|
|
|
|
|
|
const result = await stopAllManagedPythonDaemons({
|
2026-05-14 14:35:55 +02:00
|
|
|
...daemonOptionsBase(tempDir),
|
2026-05-12 13:00:08 +02:00
|
|
|
listProcesses: vi.fn(async () => []),
|
|
|
|
|
processAlive: vi.fn(() => false),
|
|
|
|
|
killProcess: vi.fn(),
|
|
|
|
|
stopGraceMs: 0,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(result.stopped).toHaveLength(0);
|
|
|
|
|
expect(result.stale.map((entry) => entry.pid)).toEqual([4242]);
|
|
|
|
|
await expect(readFile(layout(tempDir).daemonStatePath, 'utf8')).rejects.toThrow();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('deduplicates a daemon found by state and process scan, preferring state metadata', async () => {
|
2026-05-14 14:35:55 +02:00
|
|
|
await mkdir(layout(tempDir).daemonStateDir, { recursive: true });
|
2026-05-12 13:00:08 +02:00
|
|
|
await writeFile(layout(tempDir).daemonStatePath, `${JSON.stringify(runningState(tempDir), null, 2)}\n`);
|
|
|
|
|
const alive = new Set([4242]);
|
|
|
|
|
const killProcess = vi.fn((pid: number) => {
|
|
|
|
|
alive.delete(pid);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await stopAllManagedPythonDaemons({
|
2026-05-14 14:35:55 +02:00
|
|
|
...daemonOptionsBase(tempDir),
|
2026-05-12 13:00:08 +02:00
|
|
|
listProcesses: vi.fn(async (): Promise<ManagedPythonDaemonProcessInfo[]> => [
|
|
|
|
|
{ pid: 4242, command: 'uv run ktx-daemon serve-http --host 127.0.0.1 --port 61234' },
|
|
|
|
|
]),
|
|
|
|
|
processAlive: vi.fn((pid) => alive.has(pid)),
|
|
|
|
|
killProcess,
|
|
|
|
|
stopGraceMs: 0,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(result.stopped).toHaveLength(1);
|
|
|
|
|
expect(result.stopped[0]).toMatchObject({
|
|
|
|
|
pid: 4242,
|
|
|
|
|
source: 'state',
|
|
|
|
|
url: 'http://127.0.0.1:58731',
|
|
|
|
|
});
|
|
|
|
|
expect(killProcess).toHaveBeenCalledTimes(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('stops unrecorded ktx-daemon serve-http processes from process scan results', async () => {
|
|
|
|
|
const alive = new Set([3333, 5555]);
|
|
|
|
|
const killProcess = vi.fn((pid: number) => {
|
|
|
|
|
alive.delete(pid);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await stopAllManagedPythonDaemons({
|
2026-05-14 14:35:55 +02:00
|
|
|
...daemonOptionsBase(tempDir),
|
2026-05-12 13:00:08 +02:00
|
|
|
listProcesses: vi.fn(async (): Promise<ManagedPythonDaemonProcessInfo[]> => [
|
|
|
|
|
{ pid: 3333, command: 'uv run ktx-daemon serve-http --host 127.0.0.1 --port 8765' },
|
|
|
|
|
{ pid: 4444, command: 'node server.js --port 8765' },
|
|
|
|
|
{ pid: 5555, command: 'grep ktx-daemon serve-http --port 8765' },
|
|
|
|
|
]),
|
|
|
|
|
processAlive: vi.fn((pid) => alive.has(pid)),
|
|
|
|
|
killProcess,
|
|
|
|
|
stopGraceMs: 0,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(result.failed).toHaveLength(0);
|
|
|
|
|
expect(result.stopped).toEqual([
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
pid: 3333,
|
|
|
|
|
source: 'process',
|
|
|
|
|
url: 'http://127.0.0.1:8765',
|
|
|
|
|
}),
|
|
|
|
|
]);
|
|
|
|
|
expect(killProcess).toHaveBeenCalledWith(3333, 'SIGTERM');
|
|
|
|
|
expect(killProcess).not.toHaveBeenCalledWith(4444, expect.anything());
|
|
|
|
|
expect(killProcess).not.toHaveBeenCalledWith(5555, expect.anything());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('reports a failed stop when TERM and KILL leave a daemon running', async () => {
|
2026-05-14 14:35:55 +02:00
|
|
|
await mkdir(layout(tempDir).daemonStateDir, { recursive: true });
|
2026-05-12 13:00:08 +02:00
|
|
|
await writeFile(layout(tempDir).daemonStatePath, `${JSON.stringify(runningState(tempDir), null, 2)}\n`);
|
|
|
|
|
|
|
|
|
|
const result = await stopAllManagedPythonDaemons({
|
2026-05-14 14:35:55 +02:00
|
|
|
...daemonOptionsBase(tempDir),
|
2026-05-12 13:00:08 +02:00
|
|
|
listProcesses: vi.fn(async () => []),
|
|
|
|
|
processAlive: vi.fn(() => true),
|
|
|
|
|
killProcess: vi.fn(),
|
|
|
|
|
stopGraceMs: 0,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(result.stopped).toHaveLength(0);
|
|
|
|
|
expect(result.failed).toEqual([
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
pid: 4242,
|
|
|
|
|
detail: 'Process still running after SIGKILL',
|
|
|
|
|
}),
|
|
|
|
|
]);
|
|
|
|
|
expect(await readFile(layout(tempDir).daemonStatePath, 'utf8')).toContain('"pid": 4242');
|
|
|
|
|
});
|
2026-05-11 15:50:34 +02:00
|
|
|
});
|