mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-22 08:38:08 +02:00
Initial open-source release
This commit is contained in:
commit
1a42152e6f
1199 changed files with 257054 additions and 0 deletions
147
scripts/check-boundaries.test.mjs
Normal file
147
scripts/check-boundaries.test.mjs
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { describe, it } from 'node:test';
|
||||
|
||||
import { scanFileContent } from './check-boundaries.mjs';
|
||||
|
||||
function productName() {
|
||||
return ['Kae', 'lio'].join('');
|
||||
}
|
||||
|
||||
function lowerProductName() {
|
||||
return ['kae', 'lio'].join('');
|
||||
}
|
||||
|
||||
describe('scanFileContent', () => {
|
||||
it('rejects source imports from application directories', () => {
|
||||
const serverAlias = '@' + 'server/contracts';
|
||||
const pythonAppPath = 'python-service/' + 'app/api/endpoints/semantic_layer.py';
|
||||
|
||||
const violations = [
|
||||
...scanFileContent('packages/context/src/index.ts', `import { orpc } from '${serverAlias}';`),
|
||||
...scanFileContent('packages/context/src/index.ts', `import "${pythonAppPath}";`),
|
||||
];
|
||||
|
||||
assert.deepEqual(
|
||||
violations.map((violation) => violation.kind),
|
||||
['app-import', 'app-import'],
|
||||
);
|
||||
});
|
||||
|
||||
it('rejects forbidden product identifiers in code source files', () => {
|
||||
const violations = scanFileContent('packages/context/src/index.ts', `export const owner = '${lowerProductName()}';`);
|
||||
|
||||
assert.equal(violations.length, 1);
|
||||
assert.equal(violations[0]?.kind, 'identifier');
|
||||
});
|
||||
|
||||
it('rejects forbidden product identifiers in shipped runtime prompt assets', () => {
|
||||
const violations = scanFileContent(
|
||||
'packages/context/prompts/memory_agent_bundle_ingest_work_unit.md',
|
||||
`Write output for ${productName()}.`,
|
||||
);
|
||||
|
||||
assert.equal(violations.length, 1);
|
||||
assert.equal(violations[0]?.kind, 'identifier');
|
||||
assert.equal(violations[0]?.file, 'packages/context/prompts/memory_agent_bundle_ingest_work_unit.md');
|
||||
});
|
||||
|
||||
it('rejects forbidden product identifiers in shipped runtime skill assets', () => {
|
||||
const violations = scanFileContent(
|
||||
'packages/context/skills/metabase_ingest/SKILL.md',
|
||||
`Use ${productName()} project conventions.`,
|
||||
);
|
||||
|
||||
assert.equal(violations.length, 1);
|
||||
assert.equal(violations[0]?.kind, 'identifier');
|
||||
assert.equal(violations[0]?.file, 'packages/context/skills/metabase_ingest/SKILL.md');
|
||||
});
|
||||
|
||||
it('allows product identifiers in docs, examples, and transition metadata', () => {
|
||||
const name = productName();
|
||||
|
||||
assert.equal(scanFileContent('docs/transition.md', name).length, 0);
|
||||
assert.equal(scanFileContent('examples/transition.md', name).length, 0);
|
||||
assert.equal(scanFileContent('python/klo-sl/plans/brainstorm.md', name).length, 0);
|
||||
assert.equal(scanFileContent('python/klo-sl/openspec/specs/semantic-layer/spec.md', name).length, 0);
|
||||
});
|
||||
|
||||
it('allows clean source files and clean runtime prompt assets', () => {
|
||||
assert.deepEqual(
|
||||
scanFileContent('packages/context/src/index.ts', "export const packageName = '@klo/context';"),
|
||||
[],
|
||||
);
|
||||
assert.deepEqual(
|
||||
scanFileContent('packages/context/prompts/memory_agent_bundle_ingest_work_unit.md', 'Write output for KLO.'),
|
||||
[],
|
||||
);
|
||||
});
|
||||
|
||||
it('rejects context-owned LLM provider construction after @klo/llm migration', () => {
|
||||
const violations = [
|
||||
...scanFileContent(
|
||||
'packages/context/src/agent/local-llm-provider.ts',
|
||||
"import { createAnthropic } from '@ai-sdk/anthropic';",
|
||||
),
|
||||
...scanFileContent('packages/context/src/scan/local-ai-gateway-enrichment.ts', "import { createGateway } from 'ai';"),
|
||||
...scanFileContent('packages/context/src/core/local-embedding-provider.ts', "import { embedMany } from 'ai';"),
|
||||
];
|
||||
|
||||
assert.deepEqual(
|
||||
violations.map((violation) => violation.kind),
|
||||
['llm-boundary', 'llm-boundary', 'llm-boundary'],
|
||||
);
|
||||
});
|
||||
|
||||
it('rejects old KLO LLM port declarations in context', () => {
|
||||
const violations = [
|
||||
...scanFileContent('packages/context/src/agent/agent-runner.service.ts', 'export interface LlmProviderPort {}'),
|
||||
...scanFileContent('packages/context/src/scan/types.ts', 'export interface KloScanLlmPort {}'),
|
||||
...scanFileContent('packages/context/src/agent/gateway-llm-provider.ts', 'export function createGatewayLlmProvider() {}'),
|
||||
];
|
||||
|
||||
assert.deepEqual(
|
||||
violations.map((violation) => violation.kind),
|
||||
['llm-boundary', 'llm-boundary', 'llm-boundary'],
|
||||
);
|
||||
});
|
||||
|
||||
it('rejects getModelByName calls in context production source', () => {
|
||||
const violations = scanFileContent(
|
||||
'packages/context/src/ingest/page-triage/page-triage.service.ts',
|
||||
"const model = this.deps.llmProvider.getModelByName('claude-sonnet-4-6');",
|
||||
);
|
||||
|
||||
assert.equal(violations.length, 1);
|
||||
assert.equal(violations[0]?.kind, 'llm-boundary');
|
||||
assert.equal(
|
||||
violations[0]?.message,
|
||||
'Forbidden context getModelByName call; use getModel(role) inside @klo/context',
|
||||
);
|
||||
});
|
||||
|
||||
it('allows role-driven getModel calls, test calls, and provider shape declarations', () => {
|
||||
assert.deepEqual(
|
||||
scanFileContent(
|
||||
'packages/context/src/ingest/page-triage/page-triage.service.ts',
|
||||
"const model = this.deps.llmProvider.getModel('triage');",
|
||||
),
|
||||
[],
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
scanFileContent(
|
||||
'packages/context/src/ingest/page-triage/page-triage.service.test.ts',
|
||||
"const model = this.deps.llmProvider.getModelByName('test-model');",
|
||||
),
|
||||
[],
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
scanFileContent(
|
||||
'packages/context/src/scan/local-enrichment.ts',
|
||||
'return { getModel() { return model; }, getModelByName() { return model; } };',
|
||||
),
|
||||
[],
|
||||
);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue