mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-10 08:05:14 +02:00
Setup wizard flow tweaks: - Add a reveal-tail password prompt (reveal-password-prompt.ts) that unmasks the last few characters of a typed/pasted secret, and wire it into the setup prompt adapter in place of clack's password(); adds the @clack/core dep. - Reorder wizard select options: surface "Paste a key" before the environment-variable option across embeddings/models/sources, promote Metabase/Notion in the source list, put Git URL before Local path, reorder the Notion crawl-mode choices, and relabel the sources "Done" action. Query-history filter picker output: - Collapse the per-template parse-failure lines into a single count in the setup output and route the full template-id list to --debug stderr. - Model parse failures as a structured parseFailedTemplateIds field instead of warning strings. - Add a privacy-safe query_history_filter_completed telemetry event (counts/enums only), mirrored into the Python daemon schema.
166 lines
4.2 KiB
TypeScript
166 lines
4.2 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import {
|
|
buildTelemetryEvent,
|
|
telemetryEventCatalog,
|
|
telemetryEventSchemas,
|
|
type TelemetryCommonEnvelope,
|
|
} from '../../src/telemetry/events.js';
|
|
|
|
const envelope: TelemetryCommonEnvelope = {
|
|
cliVersion: '0.4.1',
|
|
nodeVersion: 'v22.0.0',
|
|
osPlatform: 'darwin',
|
|
osRelease: '25.0.0',
|
|
arch: 'arm64',
|
|
runtime: 'node',
|
|
isCi: false,
|
|
};
|
|
|
|
describe('telemetry event schemas', () => {
|
|
it('catalogs all v1 telemetry events', () => {
|
|
expect(telemetryEventCatalog.map((event) => event.name)).toEqual([
|
|
'install_first_run',
|
|
'command',
|
|
'setup_step',
|
|
'connection_added',
|
|
'connection_test',
|
|
'project_stack_snapshot',
|
|
'ingest_completed',
|
|
'scan_completed',
|
|
'sl_validate_completed',
|
|
'sl_query_completed',
|
|
'sql_completed',
|
|
'wiki_query_completed',
|
|
'mcp_request_completed',
|
|
'daemon_started',
|
|
'daemon_stopped',
|
|
'sl_plan_completed',
|
|
'sql_gen_completed',
|
|
'query_history_filter_completed',
|
|
]);
|
|
});
|
|
|
|
it('builds strict daemon telemetry events', () => {
|
|
const daemonEnvelope = {
|
|
...envelope,
|
|
runtime: 'daemon-py' as const,
|
|
nodeVersion: '3.13.0',
|
|
};
|
|
|
|
expect(
|
|
buildTelemetryEvent('sl_plan_completed', daemonEnvelope, {
|
|
outcome: 'ok',
|
|
stage: 'transpile',
|
|
durationMs: 25,
|
|
sourceCount: 2,
|
|
joinCount: 1,
|
|
}),
|
|
).toMatchObject({
|
|
name: 'sl_plan_completed',
|
|
properties: {
|
|
runtime: 'daemon-py',
|
|
outcome: 'ok',
|
|
stage: 'transpile',
|
|
sourceCount: 2,
|
|
joinCount: 1,
|
|
},
|
|
});
|
|
|
|
expect(() =>
|
|
telemetryEventSchemas.sql_gen_completed.parse({
|
|
...daemonEnvelope,
|
|
outcome: 'ok',
|
|
dialect: 'postgres',
|
|
durationMs: 4,
|
|
sql: 'select * from private_table',
|
|
}),
|
|
).toThrow();
|
|
});
|
|
|
|
it('builds a strict install_first_run event', () => {
|
|
expect(buildTelemetryEvent('install_first_run', envelope, {})).toEqual({
|
|
name: 'install_first_run',
|
|
properties: envelope,
|
|
});
|
|
});
|
|
|
|
it('builds a strict command event with project grouping fields', () => {
|
|
expect(
|
|
buildTelemetryEvent('command', envelope, {
|
|
commandPath: ['ktx', 'status'],
|
|
durationMs: 12,
|
|
outcome: 'ok',
|
|
flagsPresent: { json: true },
|
|
hasProject: true,
|
|
projectGroupAttached: true,
|
|
}),
|
|
).toEqual({
|
|
name: 'command',
|
|
properties: {
|
|
...envelope,
|
|
commandPath: ['ktx', 'status'],
|
|
durationMs: 12,
|
|
outcome: 'ok',
|
|
flagsPresent: { json: true },
|
|
hasProject: true,
|
|
projectGroupAttached: true,
|
|
},
|
|
});
|
|
});
|
|
|
|
it('rejects unmodeled event properties', () => {
|
|
expect(() =>
|
|
telemetryEventSchemas.command.parse({
|
|
...envelope,
|
|
commandPath: ['ktx', 'status'],
|
|
durationMs: 12,
|
|
outcome: 'ok',
|
|
flagsPresent: {},
|
|
hasProject: true,
|
|
projectGroupAttached: true,
|
|
tableName: 'private_table',
|
|
}),
|
|
).toThrow();
|
|
});
|
|
|
|
it('builds strict Phase 2 events without private names or text', () => {
|
|
expect(
|
|
buildTelemetryEvent('connection_test', envelope, {
|
|
driver: 'postgres',
|
|
isDemoConnection: false,
|
|
outcome: 'ok',
|
|
durationMs: 34,
|
|
serverVersion: '16',
|
|
}),
|
|
).toMatchObject({
|
|
name: 'connection_test',
|
|
properties: {
|
|
driver: 'postgres',
|
|
isDemoConnection: false,
|
|
outcome: 'ok',
|
|
durationMs: 34,
|
|
serverVersion: '16',
|
|
},
|
|
});
|
|
|
|
expect(() =>
|
|
telemetryEventSchemas.sql_completed.parse({
|
|
...envelope,
|
|
driver: 'postgres',
|
|
isDemoConnection: false,
|
|
queryVerb: 'select',
|
|
referencedTableCount: 1,
|
|
durationMs: 10,
|
|
outcome: 'ok',
|
|
sql: 'select * from private_table',
|
|
}),
|
|
).toThrow();
|
|
});
|
|
|
|
it('rejects raw private field names that are not in the telemetry schemas', () => {
|
|
expect(JSON.stringify(telemetryEventSchemas)).not.toContain('tableName');
|
|
expect(Object.keys(telemetryEventSchemas.sql_completed.shape)).not.toContain('sql');
|
|
expect(JSON.stringify(telemetryEventSchemas)).not.toContain('path');
|
|
});
|
|
});
|