ktx/scripts/relationship-benchmark-report.mjs

55 lines
2 KiB
JavaScript
Raw Normal View History

2026-05-10 23:12:26 +02:00
import { dirname, join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import {
2026-05-10 23:51:24 +02:00
buildKtxRelationshipBenchmarkReport,
formatKtxRelationshipBenchmarkReportMarkdown,
refactor(cli): delete internal barrel index.ts files The 34 `index.ts` re-export barrels inside `packages/cli/src/` were holdovers from the pre-fold multi-workspace structure. Post-fold-in they served no production purpose: external consumers go through the single package main entry, and in-repo callers mostly imported through them only because the path was short. Internally, knip flagged most barrel re-exports as production-dead (only reached via tests). This change: - Deletes every internal barrel except `packages/cli/src/index.ts` (the published package entry). - Rewrites ~270 source/test files to import each name directly from the file that defines it. - Moves `tools/warehouse-verification/index.ts` to `create-warehouse-verification-tools.ts` (the function it defined locally) and updates its single consumer. - Renames `search/backend-conformance.ts` → `.test-utils.ts` to match the existing test-helper file convention. - Deletes 13 dead test-only chains (dbt-descriptions/*, live-database/extracted-schema, live-database/structural-sync, relationship-* feedback/review chain) plus their tests and a cascading orphan integration test. - Updates test mocks that pointed at deleted barrel paths (notion-client, connector barrels in scan/local-scan-connectors tests) to mock the source files instead. - Points the maintainer benchmark script (`scripts/relationship-benchmark-report.mjs`) at source files instead of `dist/context/scan/index.js`. - Drops the barrel `!` entries from `knip.json`; adds explicit production entries only for the benchmark code reached via dist by the maintainer script. Net: 413 files changed, ~1.2k insertions, ~9.4k deletions. `pnpm run dead-code` (Biome + knip default + knip production) and `pnpm run type-check` are clean; 2277 tests pass.
2026-05-21 12:41:20 +02:00
} from '../packages/cli/dist/context/scan/relationship-benchmark-report.js';
import {
KTX_RELATIONSHIP_BENCHMARK_MODES,
currentKtxRelationshipBenchmarkDetector,
2026-05-10 23:51:24 +02:00
ktxRelationshipBenchmarkDetectorWithLlm,
loadKtxRelationshipBenchmarkFixtures,
runKtxRelationshipBenchmarkSuite,
refactor(cli): delete internal barrel index.ts files The 34 `index.ts` re-export barrels inside `packages/cli/src/` were holdovers from the pre-fold multi-workspace structure. Post-fold-in they served no production purpose: external consumers go through the single package main entry, and in-repo callers mostly imported through them only because the path was short. Internally, knip flagged most barrel re-exports as production-dead (only reached via tests). This change: - Deletes every internal barrel except `packages/cli/src/index.ts` (the published package entry). - Rewrites ~270 source/test files to import each name directly from the file that defines it. - Moves `tools/warehouse-verification/index.ts` to `create-warehouse-verification-tools.ts` (the function it defined locally) and updates its single consumer. - Renames `search/backend-conformance.ts` → `.test-utils.ts` to match the existing test-helper file convention. - Deletes 13 dead test-only chains (dbt-descriptions/*, live-database/extracted-schema, live-database/structural-sync, relationship-* feedback/review chain) plus their tests and a cascading orphan integration test. - Updates test mocks that pointed at deleted barrel paths (notion-client, connector barrels in scan/local-scan-connectors tests) to mock the source files instead. - Points the maintainer benchmark script (`scripts/relationship-benchmark-report.mjs`) at source files instead of `dist/context/scan/index.js`. - Drops the barrel `!` entries from `knip.json`; adds explicit production entries only for the benchmark code reached via dist by the maintainer script. Net: 413 files changed, ~1.2k insertions, ~9.4k deletions. `pnpm run dead-code` (Biome + knip default + knip production) and `pnpm run type-check` are clean; 2277 tests pass.
2026-05-21 12:41:20 +02:00
} from '../packages/cli/dist/context/scan/relationship-benchmarks.js';
2026-05-10 23:12:26 +02:00
const scriptDir = dirname(fileURLToPath(import.meta.url));
const ktxRoot = resolve(scriptDir, '..');
const fixtureRoot = join(ktxRoot, 'packages/cli/src/test/fixtures/relationship-benchmarks');
2026-05-10 23:12:26 +02:00
async function buildDetector() {
2026-05-10 23:51:24 +02:00
const backend = process.env.KTX_BENCHMARK_LLM_BACKEND;
2026-05-10 23:12:26 +02:00
if (!backend || backend === 'none') {
2026-05-10 23:51:24 +02:00
return currentKtxRelationshipBenchmarkDetector();
2026-05-10 23:12:26 +02:00
}
if (backend !== 'vertex') {
2026-05-10 23:51:24 +02:00
throw new Error(`Unsupported KTX_BENCHMARK_LLM_BACKEND: ${backend}`);
2026-05-10 23:12:26 +02:00
}
2026-05-10 23:51:24 +02:00
const project = process.env.KTX_BENCHMARK_VERTEX_PROJECT;
const location = process.env.KTX_BENCHMARK_VERTEX_LOCATION;
const model = process.env.KTX_BENCHMARK_LLM_MODEL ?? 'claude-sonnet-4-6';
2026-05-10 23:12:26 +02:00
if (!project || !location) {
2026-05-10 23:51:24 +02:00
throw new Error('KTX_BENCHMARK_VERTEX_PROJECT and KTX_BENCHMARK_VERTEX_LOCATION are required for vertex backend');
2026-05-10 23:12:26 +02:00
}
const { createKtxLlmProvider } = await import('../packages/cli/dist/llm/index.js');
2026-05-10 23:51:24 +02:00
const provider = createKtxLlmProvider({
2026-05-10 23:12:26 +02:00
backend: 'vertex',
vertex: { project, location },
modelSlots: { default: model },
});
2026-05-10 23:51:24 +02:00
return ktxRelationshipBenchmarkDetectorWithLlm(provider);
2026-05-10 23:12:26 +02:00
}
2026-05-10 23:51:24 +02:00
const fixtures = await loadKtxRelationshipBenchmarkFixtures(fixtureRoot);
2026-05-10 23:12:26 +02:00
const detector = await buildDetector();
2026-05-10 23:51:24 +02:00
const suite = await runKtxRelationshipBenchmarkSuite({
2026-05-10 23:12:26 +02:00
fixtures,
detector,
});
2026-05-10 23:51:24 +02:00
const report = buildKtxRelationshipBenchmarkReport({
2026-05-10 23:12:26 +02:00
fixtures,
suite,
2026-05-10 23:51:24 +02:00
modes: KTX_RELATIONSHIP_BENCHMARK_MODES,
2026-05-10 23:12:26 +02:00
});
2026-05-10 23:51:24 +02:00
process.stdout.write(formatKtxRelationshipBenchmarkReportMarkdown(report));