mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-07 07:55:13 +02:00
66 lines
2.5 KiB
JavaScript
66 lines
2.5 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { readdir, readFile } from 'node:fs/promises';
|
|
import { describe, it } from 'node:test';
|
|
|
|
const KTX_ROOT = new URL('../', import.meta.url);
|
|
|
|
const RELATIONSHIP_RUNTIME_SOURCES = Object.freeze([
|
|
'packages/context/src/scan/relationship-benchmarks.ts',
|
|
'packages/context/src/scan/relationship-budget.ts',
|
|
'packages/context/src/scan/relationship-candidates.ts',
|
|
'packages/context/src/scan/relationship-composite-candidates.ts',
|
|
'packages/context/src/scan/relationship-graph-resolver.ts',
|
|
'packages/context/src/scan/relationship-locality.ts',
|
|
'packages/context/src/scan/relationship-name-similarity.ts',
|
|
'packages/context/src/scan/relationship-discovery.ts',
|
|
'packages/context/src/scan/relationship-profiling.ts',
|
|
'packages/context/src/scan/relationship-scoring.ts',
|
|
'packages/context/src/scan/relationship-validation.ts',
|
|
]);
|
|
|
|
async function checkedInFixtureIds() {
|
|
const fixtureRoot = new URL('packages/context/test/fixtures/relationship-benchmarks/', KTX_ROOT);
|
|
const entries = await readdir(fixtureRoot, { withFileTypes: true });
|
|
return entries
|
|
.filter((entry) => entry.isDirectory())
|
|
.map((entry) => entry.name)
|
|
.sort((left, right) => left.localeCompare(right));
|
|
}
|
|
|
|
async function readRuntimeSources() {
|
|
return Promise.all(
|
|
RELATIONSHIP_RUNTIME_SOURCES.map(async (relativePath) => ({
|
|
relativePath,
|
|
source: await readFile(new URL(relativePath, KTX_ROOT), 'utf8'),
|
|
})),
|
|
);
|
|
}
|
|
|
|
describe('relationship evidence-fusion source guardrails', () => {
|
|
it('keeps runtime relationship modules free of fixture-id conditionals', async () => {
|
|
const fixtureIds = await checkedInFixtureIds();
|
|
const sources = await readRuntimeSources();
|
|
const hits = [];
|
|
|
|
for (const { relativePath, source } of sources) {
|
|
for (const fixtureId of fixtureIds) {
|
|
if (source.includes(fixtureId)) {
|
|
hits.push(`${relativePath}: ${fixtureId}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
assert.deepEqual(hits, []);
|
|
});
|
|
|
|
it('keeps runtime relationship modules free of length-threshold drop-all cliffs', async () => {
|
|
const sources = await readRuntimeSources();
|
|
const dropAllPattern = /if\s*\([^)]*\.length\s*>\s*\d+[^)]*\)\s*(?:\{\s*)?return\s*\[\];/gs;
|
|
const hits = sources.flatMap(({ relativePath, source }) => {
|
|
const matches = Array.from(source.matchAll(dropAllPattern));
|
|
return matches.map((match) => `${relativePath}: ${match[0].replace(/\s+/g, ' ').trim()}`);
|
|
});
|
|
|
|
assert.deepEqual(hits, []);
|
|
});
|
|
});
|