ktx/packages/cli/test/context/scan/embedding-text.test.ts
Andrey Avtomonov 00cdf2de90
refactor: enforce ktx naming and AGENTS.md compliance sweep (#289)
Align the tree with AGENTS.md/CLAUDE.md conventions:

- Rewrite user-facing strings, docs, and tests to lowercase `ktx`
  (no bare uppercase `KTX` tokens remain outside literal identifiers).
- Drop the legacy `historicSql` migration path and its now-unused
  helpers, per the no-backward-compat rule.
- Remove `as unknown as` / `any` casts: narrow `BaseTool` generics to
  `z.ZodObject`, add a typed `createLookerClient`, and delete the dead
  `getParametersSchema`/`toAnthropicFormat` pre-AI-SDK helpers.
- Use `InvalidArgumentError` for Commander parse failures.
- Finish the adapter→connector prose conversion in the `ktx.yaml` docs
  while keeping the literal `adapters` config key.
2026-06-11 13:49:45 +02:00

47 lines
1.6 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { buildKtxColumnEmbeddingText } from '../../../src/context/scan/embedding-text.js';
describe('ktx scan embedding text', () => {
it('builds column embedding text with table, description, FK, and sample-value context', () => {
expect(
buildKtxColumnEmbeddingText({
tableName: 'orders',
columnName: 'status',
columnType: 'varchar',
resolvedDescription: 'Payment lifecycle state',
sampleValues: ['paid', 'refunded', 'pending'],
resolvedTableDescription: 'Customer orders',
foreignKeys: {
outgoing: [{ toTable: 'customers', toColumn: 'id' }],
incoming: [{ fromTable: 'refunds', fromColumn: 'order_status' }],
},
maxSampleValues: 2,
}),
).toBe(
'orders.status (varchar). Table: Customer orders. Payment lifecycle state. FK -> customers.id. FK <- refunds.order_status. Values: paid, refunded',
);
});
it('omits optional sections when the scan has no enrichment context yet', () => {
expect(
buildKtxColumnEmbeddingText({
tableName: 'orders',
columnName: 'id',
columnType: 'integer',
resolvedDescription: null,
}),
).toBe('orders.id (integer)');
});
it('keeps all available sample values when no explicit max is supplied', () => {
expect(
buildKtxColumnEmbeddingText({
tableName: 'orders',
columnName: 'status',
columnType: 'varchar',
resolvedDescription: null,
sampleValues: ['paid', 'refunded'],
}),
).toBe('orders.status (varchar). Values: paid, refunded');
});
});