Files
baiyue-firstleg/firstleg/scripts/analyze-firstleg-dependencies.test.mjs
T
2026-08-25 11:52:25 +08:00

40 lines
1.9 KiB
JavaScript

import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
import path from 'node:path';
import test from 'node:test';
const moduleRoot = path.resolve(import.meta.dirname, '..');
const analyzer = path.join(moduleRoot, 'scripts', 'analyze-firstleg-dependencies.mjs');
const contract = path.join(moduleRoot, 'src', 'test', 'resources', 'architecture', 'firstleg-slice-dependencies.json');
function analyze() {
return JSON.parse(execFileSync(process.execPath, [analyzer, '--source-set', 'main', '--format', 'json'], {
cwd: moduleRoot,
encoding: 'utf8',
}));
}
test('current source does not add slice dependencies beyond the baseline', () => {
execFileSync(process.execPath, [analyzer, '--source-set', 'main', '--format', 'dot', '--check', contract], {
cwd: moduleRoot,
encoding: 'utf8',
});
});
test('customer statistics remains an independently packaged low-coupling slice', () => {
const report = analyze();
const classes = report.classes.filter(entry => entry.slice === 'customer-statistics');
assert.deepEqual(classes.map(entry => entry.fqcn).sort(), [
'com.baiyue.firstleg.customerstatistics.controller.PlatformCustomerTransitStatisticsController',
'com.baiyue.firstleg.customerstatistics.dto.CustomerTransitStatisticsDtos',
'com.baiyue.firstleg.customerstatistics.mapper.CustomerTransitStatisticsMapper',
'com.baiyue.firstleg.customerstatistics.service.CustomerTransitStatisticsService',
]);
const outgoing = report.sliceEdges.filter(edge => edge.source === 'customer-statistics');
const incoming = report.sliceEdges.filter(edge => edge.target === 'customer-statistics');
assert.deepEqual(outgoing, [{ source: 'customer-statistics', target: 'shared-technical', count: 1 }]);
assert.deepEqual(incoming, []);
assert.equal(report.sliceSccs.some(component => component.includes('customer-statistics')), false);
});