@girardelli/architect-core 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/core/analyzer.d.ts +42 -0
- package/dist/src/core/analyzer.js +431 -0
- package/dist/src/core/analyzer.js.map +1 -0
- package/dist/src/core/analyzers/forecast.d.ts +84 -0
- package/dist/src/core/analyzers/forecast.js +338 -0
- package/dist/src/core/analyzers/forecast.js.map +1 -0
- package/dist/src/core/analyzers/index.d.ts +9 -0
- package/dist/src/core/analyzers/index.js +7 -0
- package/dist/src/core/analyzers/index.js.map +1 -0
- package/dist/src/core/analyzers/temporal-scorer.d.ts +71 -0
- package/dist/src/core/analyzers/temporal-scorer.js +141 -0
- package/dist/src/core/analyzers/temporal-scorer.js.map +1 -0
- package/dist/src/core/anti-patterns.d.ts +28 -0
- package/dist/src/core/anti-patterns.js +264 -0
- package/dist/src/core/anti-patterns.js.map +1 -0
- package/dist/src/core/ast/ast-parser.interface.d.ts +20 -0
- package/dist/src/core/ast/ast-parser.interface.js +2 -0
- package/dist/src/core/ast/ast-parser.interface.js.map +1 -0
- package/dist/src/core/ast/path-resolver.d.ts +13 -0
- package/dist/src/core/ast/path-resolver.js +54 -0
- package/dist/src/core/ast/path-resolver.js.map +1 -0
- package/dist/src/core/ast/tree-sitter-parser.d.ts +10 -0
- package/dist/src/core/ast/tree-sitter-parser.js +142 -0
- package/dist/src/core/ast/tree-sitter-parser.js.map +1 -0
- package/dist/src/core/config.d.ts +11 -0
- package/dist/src/core/config.js +112 -0
- package/dist/src/core/config.js.map +1 -0
- package/dist/src/core/diagram.d.ts +9 -0
- package/dist/src/core/diagram.js +101 -0
- package/dist/src/core/diagram.js.map +1 -0
- package/dist/src/core/i18n.d.ts +14 -0
- package/dist/src/core/i18n.js +54 -0
- package/dist/src/core/i18n.js.map +1 -0
- package/dist/src/core/locales/en.d.ts +2 -0
- package/dist/src/core/locales/en.js +337 -0
- package/dist/src/core/locales/en.js.map +1 -0
- package/dist/src/core/locales/pt-BR.d.ts +172 -0
- package/dist/src/core/locales/pt-BR.js +337 -0
- package/dist/src/core/locales/pt-BR.js.map +1 -0
- package/dist/src/core/locales/types.d.ts +86 -0
- package/dist/src/core/locales/types.js +2 -0
- package/dist/src/core/locales/types.js.map +1 -0
- package/dist/src/core/plugin-loader.d.ts +11 -0
- package/dist/src/core/plugin-loader.js +67 -0
- package/dist/src/core/plugin-loader.js.map +1 -0
- package/dist/src/core/project-summarizer.d.ts +16 -0
- package/dist/src/core/project-summarizer.js +37 -0
- package/dist/src/core/project-summarizer.js.map +1 -0
- package/dist/src/core/refactor-engine.d.ts +18 -0
- package/dist/src/core/refactor-engine.js +87 -0
- package/dist/src/core/refactor-engine.js.map +1 -0
- package/dist/src/core/rules/barrel-optimizer.d.ts +13 -0
- package/dist/src/core/rules/barrel-optimizer.js +76 -0
- package/dist/src/core/rules/barrel-optimizer.js.map +1 -0
- package/dist/src/core/rules/dead-code-detector.d.ts +21 -0
- package/dist/src/core/rules/dead-code-detector.js +116 -0
- package/dist/src/core/rules/dead-code-detector.js.map +1 -0
- package/dist/src/core/rules/hub-splitter.d.ts +13 -0
- package/dist/src/core/rules/hub-splitter.js +117 -0
- package/dist/src/core/rules/hub-splitter.js.map +1 -0
- package/dist/src/core/rules/import-organizer.d.ts +13 -0
- package/dist/src/core/rules/import-organizer.js +84 -0
- package/dist/src/core/rules/import-organizer.js.map +1 -0
- package/dist/src/core/rules/module-grouper.d.ts +13 -0
- package/dist/src/core/rules/module-grouper.js +116 -0
- package/dist/src/core/rules/module-grouper.js.map +1 -0
- package/dist/src/core/rules-engine.d.ts +7 -0
- package/dist/src/core/rules-engine.js +89 -0
- package/dist/src/core/rules-engine.js.map +1 -0
- package/dist/src/core/scorer.d.ts +15 -0
- package/dist/src/core/scorer.js +165 -0
- package/dist/src/core/scorer.js.map +1 -0
- package/dist/src/core/summarizer/keyword-extractor.d.ts +6 -0
- package/dist/src/core/summarizer/keyword-extractor.js +38 -0
- package/dist/src/core/summarizer/keyword-extractor.js.map +1 -0
- package/dist/src/core/summarizer/module-inferrer.d.ts +11 -0
- package/dist/src/core/summarizer/module-inferrer.js +171 -0
- package/dist/src/core/summarizer/module-inferrer.js.map +1 -0
- package/dist/src/core/summarizer/package-reader.d.ts +3 -0
- package/dist/src/core/summarizer/package-reader.js +33 -0
- package/dist/src/core/summarizer/package-reader.js.map +1 -0
- package/dist/src/core/summarizer/purpose-inferrer.d.ts +8 -0
- package/dist/src/core/summarizer/purpose-inferrer.js +179 -0
- package/dist/src/core/summarizer/purpose-inferrer.js.map +1 -0
- package/dist/src/core/summarizer/readme-reader.d.ts +3 -0
- package/dist/src/core/summarizer/readme-reader.js +24 -0
- package/dist/src/core/summarizer/readme-reader.js.map +1 -0
- package/dist/src/core/types/architect-rules.d.ts +27 -0
- package/dist/src/core/types/architect-rules.js +2 -0
- package/dist/src/core/types/architect-rules.js.map +1 -0
- package/dist/src/core/types/core.d.ts +87 -0
- package/dist/src/core/types/core.js +2 -0
- package/dist/src/core/types/core.js.map +1 -0
- package/dist/src/core/types/infrastructure.d.ts +38 -0
- package/dist/src/core/types/infrastructure.js +2 -0
- package/dist/src/core/types/infrastructure.js.map +1 -0
- package/dist/src/core/types/plugin.d.ts +12 -0
- package/dist/src/core/types/plugin.js +2 -0
- package/dist/src/core/types/plugin.js.map +1 -0
- package/dist/src/core/types/rules.d.ts +53 -0
- package/dist/src/core/types/rules.js +2 -0
- package/dist/src/core/types/rules.js.map +1 -0
- package/dist/src/core/types/summarizer.d.ts +12 -0
- package/dist/src/core/types/summarizer.js +2 -0
- package/dist/src/core/types/summarizer.js.map +1 -0
- package/dist/src/infrastructure/git-cache.d.ts +6 -0
- package/dist/src/infrastructure/git-cache.js +41 -0
- package/dist/src/infrastructure/git-cache.js.map +1 -0
- package/dist/src/infrastructure/git-history.d.ts +112 -0
- package/dist/src/infrastructure/git-history.js +340 -0
- package/dist/src/infrastructure/git-history.js.map +1 -0
- package/dist/src/infrastructure/logger.d.ts +20 -0
- package/dist/src/infrastructure/logger.js +57 -0
- package/dist/src/infrastructure/logger.js.map +1 -0
- package/dist/src/infrastructure/scanner.d.ts +31 -0
- package/dist/src/infrastructure/scanner.js +334 -0
- package/dist/src/infrastructure/scanner.js.map +1 -0
- package/dist/tests/analyzers-integration.test.d.ts +7 -0
- package/dist/tests/analyzers-integration.test.js +140 -0
- package/dist/tests/analyzers-integration.test.js.map +1 -0
- package/dist/tests/anti-patterns.test.d.ts +1 -0
- package/dist/tests/anti-patterns.test.js +81 -0
- package/dist/tests/anti-patterns.test.js.map +1 -0
- package/dist/tests/ast-parser.test.d.ts +1 -0
- package/dist/tests/ast-parser.test.js +94 -0
- package/dist/tests/ast-parser.test.js.map +1 -0
- package/dist/tests/fixtures/monorepo/packages/app/src/index.d.ts +1 -0
- package/dist/tests/fixtures/monorepo/packages/app/src/index.js +9 -0
- package/dist/tests/fixtures/monorepo/packages/app/src/index.js.map +1 -0
- package/dist/tests/fixtures/monorepo/packages/core/src/index.d.ts +2 -0
- package/dist/tests/fixtures/monorepo/packages/core/src/index.js +11 -0
- package/dist/tests/fixtures/monorepo/packages/core/src/index.js.map +1 -0
- package/dist/tests/forecast.test.d.ts +7 -0
- package/dist/tests/forecast.test.js +380 -0
- package/dist/tests/forecast.test.js.map +1 -0
- package/dist/tests/git-history.test.d.ts +7 -0
- package/dist/tests/git-history.test.js +193 -0
- package/dist/tests/git-history.test.js.map +1 -0
- package/dist/tests/i18n.test.d.ts +1 -0
- package/dist/tests/i18n.test.js +39 -0
- package/dist/tests/i18n.test.js.map +1 -0
- package/dist/tests/monorepo-scan.test.d.ts +11 -0
- package/dist/tests/monorepo-scan.test.js +143 -0
- package/dist/tests/monorepo-scan.test.js.map +1 -0
- package/dist/tests/plugin-loader.test.d.ts +1 -0
- package/dist/tests/plugin-loader.test.js +31 -0
- package/dist/tests/plugin-loader.test.js.map +1 -0
- package/dist/tests/rules-engine.test.d.ts +1 -0
- package/dist/tests/rules-engine.test.js +112 -0
- package/dist/tests/rules-engine.test.js.map +1 -0
- package/dist/tests/scanner.test.d.ts +1 -0
- package/dist/tests/scanner.test.js +44 -0
- package/dist/tests/scanner.test.js.map +1 -0
- package/dist/tests/scorer.test.d.ts +1 -0
- package/dist/tests/scorer.test.js +610 -0
- package/dist/tests/scorer.test.js.map +1 -0
- package/dist/tests/temporal-scorer.test.d.ts +7 -0
- package/dist/tests/temporal-scorer.test.js +239 -0
- package/dist/tests/temporal-scorer.test.js.map +1 -0
- package/package.json +29 -0
- package/src/core/analyzer.ts +499 -0
- package/src/core/analyzers/forecast.ts +497 -0
- package/src/core/analyzers/index.ts +33 -0
- package/src/core/analyzers/temporal-scorer.ts +227 -0
- package/src/core/anti-patterns.ts +324 -0
- package/src/core/ast/ast-parser.interface.ts +21 -0
- package/src/core/ast/path-resolver.ts +61 -0
- package/src/core/ast/tree-sitter-parser.ts +158 -0
- package/src/core/config.ts +125 -0
- package/src/core/diagram.ts +129 -0
- package/src/core/i18n.ts +64 -0
- package/src/core/locales/en.ts +340 -0
- package/src/core/locales/pt-BR.ts +341 -0
- package/src/core/locales/types.ts +95 -0
- package/src/core/plugin-loader.ts +80 -0
- package/src/core/project-summarizer.ts +42 -0
- package/src/core/refactor-engine.ts +112 -0
- package/src/core/rules/barrel-optimizer.ts +99 -0
- package/src/core/rules/dead-code-detector.ts +134 -0
- package/src/core/rules/hub-splitter.ts +135 -0
- package/src/core/rules/import-organizer.ts +100 -0
- package/src/core/rules/module-grouper.ts +133 -0
- package/src/core/rules-engine.ts +100 -0
- package/src/core/scorer.ts +181 -0
- package/src/core/summarizer/keyword-extractor.ts +53 -0
- package/src/core/summarizer/module-inferrer.ts +194 -0
- package/src/core/summarizer/package-reader.ts +34 -0
- package/src/core/summarizer/purpose-inferrer.ts +197 -0
- package/src/core/summarizer/readme-reader.ts +24 -0
- package/src/core/types/architect-rules.ts +29 -0
- package/src/core/types/core.ts +94 -0
- package/src/core/types/infrastructure.ts +41 -0
- package/src/core/types/plugin.ts +19 -0
- package/src/core/types/rules.ts +51 -0
- package/src/core/types/summarizer.ts +8 -0
- package/src/infrastructure/git-cache.ts +52 -0
- package/src/infrastructure/git-history.ts +496 -0
- package/src/infrastructure/logger.ts +68 -0
- package/src/infrastructure/scanner.ts +349 -0
- package/tests/analyzers-integration.test.ts +174 -0
- package/tests/anti-patterns.test.ts +95 -0
- package/tests/ast-parser.test.ts +102 -0
- package/tests/fixtures/monorepo/package.json +6 -0
- package/tests/fixtures/monorepo/packages/app/package.json +12 -0
- package/tests/fixtures/monorepo/packages/app/src/index.ts +6 -0
- package/tests/fixtures/monorepo/packages/core/package.json +7 -0
- package/tests/fixtures/monorepo/packages/core/src/index.ts +7 -0
- package/tests/forecast.test.ts +504 -0
- package/tests/git-history.test.ts +254 -0
- package/tests/i18n.test.ts +47 -0
- package/tests/monorepo-scan.test.ts +170 -0
- package/tests/plugin-loader.test.ts +40 -0
- package/tests/rules-engine.test.ts +131 -0
- package/tests/scanner.test.ts +54 -0
- package/tests/scorer.test.ts +675 -0
- package/tests/temporal-scorer.test.ts +306 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { TreeSitterParser } from '../src/core/ast/tree-sitter-parser.js';
|
|
2
|
+
|
|
3
|
+
describe('TreeSitter AST Parser', () => {
|
|
4
|
+
let parser: TreeSitterParser;
|
|
5
|
+
|
|
6
|
+
beforeAll(async () => {
|
|
7
|
+
parser = new TreeSitterParser();
|
|
8
|
+
await parser.initialize();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe('TypeScript/JavaScript Parsing', () => {
|
|
12
|
+
it('should parse standard ES6 imports', () => {
|
|
13
|
+
const code = `
|
|
14
|
+
import { MyService } from './my.service';
|
|
15
|
+
import React from 'react';
|
|
16
|
+
import * as utils from '@/utils';
|
|
17
|
+
`;
|
|
18
|
+
const imports = parser.parseImports(code, 'foo.ts');
|
|
19
|
+
expect(imports).toContain('./my.service');
|
|
20
|
+
expect(imports).toContain('react');
|
|
21
|
+
expect(imports).toContain('@/utils');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should parse CommonJS require calls', () => {
|
|
25
|
+
const code = `
|
|
26
|
+
const fs = require('fs');
|
|
27
|
+
const custom = require('../custom/module');
|
|
28
|
+
`;
|
|
29
|
+
const imports = parser.parseImports(code, 'foo.js');
|
|
30
|
+
expect(imports).toContain('fs');
|
|
31
|
+
expect(imports).toContain('../custom/module');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should parse dynamic imports', () => {
|
|
35
|
+
const code = `
|
|
36
|
+
async function load() {
|
|
37
|
+
const mod = await import('./lazy-module');
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
const imports = parser.parseImports(code, 'foo.ts');
|
|
41
|
+
expect(imports).toContain('./lazy-module');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should parse re-exports', () => {
|
|
45
|
+
const code = `
|
|
46
|
+
export * from './domain/models';
|
|
47
|
+
export { User } from './domain/user';
|
|
48
|
+
`;
|
|
49
|
+
const imports = parser.parseImports(code, 'index.ts');
|
|
50
|
+
expect(imports).toContain('./domain/models');
|
|
51
|
+
expect(imports).toContain('./domain/user');
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('Python Parsing', () => {
|
|
56
|
+
it('should parse standard python imports', () => {
|
|
57
|
+
const code = `
|
|
58
|
+
from os import path
|
|
59
|
+
import sys
|
|
60
|
+
from my_module.submodule import MyClass
|
|
61
|
+
import internal_app as app
|
|
62
|
+
`;
|
|
63
|
+
const imports = parser.parseImports(code, 'main.py');
|
|
64
|
+
expect(imports).toContain('os'); // AST only extracts the module name or dotted name
|
|
65
|
+
expect(imports).toContain('sys');
|
|
66
|
+
expect(imports).toContain('my_module.submodule');
|
|
67
|
+
expect(imports).toContain('internal_app');
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('Go Parsing', () => {
|
|
72
|
+
it('should parse go imports', () => {
|
|
73
|
+
const code = `
|
|
74
|
+
package main
|
|
75
|
+
|
|
76
|
+
import (
|
|
77
|
+
"fmt"
|
|
78
|
+
"github.com/myorg/myproject/internal/utils"
|
|
79
|
+
)
|
|
80
|
+
import "os"
|
|
81
|
+
`;
|
|
82
|
+
const imports = parser.parseImports(code, 'main.go');
|
|
83
|
+
expect(imports).toContain('fmt');
|
|
84
|
+
expect(imports).toContain('github.com/myorg/myproject/internal/utils');
|
|
85
|
+
expect(imports).toContain('os');
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('Java Parsing', () => {
|
|
90
|
+
it('should parse java imports', () => {
|
|
91
|
+
const code = `
|
|
92
|
+
package com.example;
|
|
93
|
+
|
|
94
|
+
import java.util.List;
|
|
95
|
+
import com.example.internal.MyService;
|
|
96
|
+
`;
|
|
97
|
+
const imports = parser.parseImports(code, 'Main.java');
|
|
98
|
+
expect(imports).toContain('java.util.List');
|
|
99
|
+
expect(imports).toContain('com.example.internal.MyService');
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for ForecastEngine
|
|
3
|
+
*
|
|
4
|
+
* Validates pre-anti-pattern detection, module forecasts,
|
|
5
|
+
* outlook classification, and recommendation generation.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { ForecastEngine } from '../src/core/analyzers/forecast.js';
|
|
9
|
+
import type {
|
|
10
|
+
GitHistoryReport,
|
|
11
|
+
ModuleHistory,
|
|
12
|
+
VelocityVector,
|
|
13
|
+
FileHistory,
|
|
14
|
+
ChangeCoupling,
|
|
15
|
+
} from '../src/infrastructure/git-history.js';
|
|
16
|
+
import type { TemporalReport, TemporalScore } from '../src/core/analyzers/temporal-scorer.js';
|
|
17
|
+
|
|
18
|
+
// ═══════════════════════════════════════════════════════════════
|
|
19
|
+
// TEST HELPERS
|
|
20
|
+
// ═══════════════════════════════════════════════════════════════
|
|
21
|
+
|
|
22
|
+
function makeVelocity(overrides: Partial<VelocityVector> = {}): VelocityVector {
|
|
23
|
+
return {
|
|
24
|
+
commitAcceleration: 0,
|
|
25
|
+
churnTrend: 0,
|
|
26
|
+
direction: 'stable',
|
|
27
|
+
...overrides,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function makeFileHistory(overrides: Partial<FileHistory> = {}): FileHistory {
|
|
32
|
+
return {
|
|
33
|
+
path: 'src/test.ts',
|
|
34
|
+
commits: 10,
|
|
35
|
+
totalAdditions: 200,
|
|
36
|
+
totalDeletions: 50,
|
|
37
|
+
churnRate: 25,
|
|
38
|
+
authors: new Set(['alice']),
|
|
39
|
+
busFactor: 1,
|
|
40
|
+
lastModified: new Date(),
|
|
41
|
+
weeklyCommitRate: 2,
|
|
42
|
+
isHotspot: false,
|
|
43
|
+
...overrides,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function makeModule(
|
|
48
|
+
modulePath: string,
|
|
49
|
+
velocity: Partial<VelocityVector> = {},
|
|
50
|
+
overrides: Partial<ModuleHistory> = {},
|
|
51
|
+
): ModuleHistory {
|
|
52
|
+
const files = overrides.files ?? [makeFileHistory({ path: `${modulePath}/file.ts` })];
|
|
53
|
+
return {
|
|
54
|
+
modulePath,
|
|
55
|
+
files,
|
|
56
|
+
aggregateCommits: overrides.aggregateCommits ?? 20,
|
|
57
|
+
aggregateChurn: overrides.aggregateChurn ?? 500,
|
|
58
|
+
avgWeeklyRate: 2,
|
|
59
|
+
topHotspots: [],
|
|
60
|
+
velocityVector: makeVelocity(velocity),
|
|
61
|
+
busFactor: overrides.busFactor ?? 2,
|
|
62
|
+
...overrides,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function makeTemporalScore(
|
|
67
|
+
module: string,
|
|
68
|
+
overrides: Partial<TemporalScore> = {},
|
|
69
|
+
): TemporalScore {
|
|
70
|
+
return {
|
|
71
|
+
module,
|
|
72
|
+
staticScore: 70,
|
|
73
|
+
temporalScore: 65,
|
|
74
|
+
trend: 'stable',
|
|
75
|
+
projectedScore: 60,
|
|
76
|
+
projectionConfidence: 0.7,
|
|
77
|
+
projectionWeeks: 12,
|
|
78
|
+
riskLevel: 'medium',
|
|
79
|
+
velocity: makeVelocity(),
|
|
80
|
+
...overrides,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function makeGitReport(
|
|
85
|
+
modules: ModuleHistory[],
|
|
86
|
+
couplings: ChangeCoupling[] = [],
|
|
87
|
+
): GitHistoryReport {
|
|
88
|
+
return {
|
|
89
|
+
projectPath: '/test',
|
|
90
|
+
analyzedAt: new Date().toISOString(),
|
|
91
|
+
periodWeeks: 24,
|
|
92
|
+
totalCommits: 100,
|
|
93
|
+
totalAuthors: 5,
|
|
94
|
+
modules,
|
|
95
|
+
hotspots: [],
|
|
96
|
+
changeCouplings: couplings,
|
|
97
|
+
commitTimeline: [],
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function makeTemporalReport(
|
|
102
|
+
modules: TemporalScore[],
|
|
103
|
+
overrides: Partial<TemporalReport> = {},
|
|
104
|
+
): TemporalReport {
|
|
105
|
+
return {
|
|
106
|
+
projectPath: '/test',
|
|
107
|
+
analyzedAt: new Date().toISOString(),
|
|
108
|
+
overallTrend: 'stable',
|
|
109
|
+
overallTemporalScore: 70,
|
|
110
|
+
modules,
|
|
111
|
+
degradingModules: modules.filter(m => m.trend === 'degrading'),
|
|
112
|
+
improvingModules: modules.filter(m => m.trend === 'improving'),
|
|
113
|
+
...overrides,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// ═══════════════════════════════════════════════════════════════
|
|
118
|
+
// TESTS
|
|
119
|
+
// ═══════════════════════════════════════════════════════════════
|
|
120
|
+
|
|
121
|
+
describe('ForecastEngine', () => {
|
|
122
|
+
describe('forecast()', () => {
|
|
123
|
+
it('should return a well-formed forecast', () => {
|
|
124
|
+
const engine = new ForecastEngine();
|
|
125
|
+
const mod = makeModule('src');
|
|
126
|
+
const ts = makeTemporalScore('src');
|
|
127
|
+
const gitReport = makeGitReport([mod]);
|
|
128
|
+
const temporalReport = makeTemporalReport([ts]);
|
|
129
|
+
|
|
130
|
+
const forecast = engine.forecast(gitReport, temporalReport);
|
|
131
|
+
|
|
132
|
+
expect(forecast.projectPath).toBe('/test');
|
|
133
|
+
expect(forecast.generatedAt).toBeDefined();
|
|
134
|
+
expect(forecast.overallOutlook).toMatch(/^(sunny|cloudy|stormy)$/);
|
|
135
|
+
expect(forecast.headline).toBeDefined();
|
|
136
|
+
expect(forecast.modules).toHaveLength(1);
|
|
137
|
+
expect(forecast.topRisks).toBeDefined();
|
|
138
|
+
expect(forecast.recommendations).toBeDefined();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('should handle empty modules', () => {
|
|
142
|
+
const engine = new ForecastEngine();
|
|
143
|
+
const gitReport = makeGitReport([]);
|
|
144
|
+
const temporalReport = makeTemporalReport([]);
|
|
145
|
+
|
|
146
|
+
const forecast = engine.forecast(gitReport, temporalReport);
|
|
147
|
+
|
|
148
|
+
expect(forecast.modules).toHaveLength(0);
|
|
149
|
+
expect(forecast.overallOutlook).toBe('sunny');
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe('pre-anti-pattern: emerging-god-class', () => {
|
|
154
|
+
it('should detect god class when churn rate is high and growing', () => {
|
|
155
|
+
const engine = new ForecastEngine({ godClassChurnThreshold: 100 });
|
|
156
|
+
|
|
157
|
+
const file = makeFileHistory({
|
|
158
|
+
path: 'src/big.ts',
|
|
159
|
+
churnRate: 160, // above threshold
|
|
160
|
+
commits: 20,
|
|
161
|
+
});
|
|
162
|
+
const mod = makeModule('src', { churnTrend: 40, direction: 'accelerating' }, { files: [file] });
|
|
163
|
+
const ts = makeTemporalScore('src', {
|
|
164
|
+
velocity: makeVelocity({ churnTrend: 40, direction: 'accelerating' }),
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const gitReport = makeGitReport([mod]);
|
|
168
|
+
const temporalReport = makeTemporalReport([ts]);
|
|
169
|
+
|
|
170
|
+
const forecast = engine.forecast(gitReport, temporalReport);
|
|
171
|
+
|
|
172
|
+
const godClass = forecast.preAntiPatterns.filter(p => p.type === 'emerging-god-class');
|
|
173
|
+
expect(godClass.length).toBeGreaterThanOrEqual(1);
|
|
174
|
+
expect(godClass[0].module).toBe('src');
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('should NOT detect god class when churn is below threshold', () => {
|
|
178
|
+
const engine = new ForecastEngine({ godClassChurnThreshold: 200 });
|
|
179
|
+
|
|
180
|
+
const file = makeFileHistory({ path: 'src/small.ts', churnRate: 50 });
|
|
181
|
+
const mod = makeModule('src', { churnTrend: 10 }, { files: [file] });
|
|
182
|
+
const ts = makeTemporalScore('src', {
|
|
183
|
+
velocity: makeVelocity({ churnTrend: 10 }),
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const gitReport = makeGitReport([mod]);
|
|
187
|
+
const temporalReport = makeTemporalReport([ts]);
|
|
188
|
+
|
|
189
|
+
const forecast = engine.forecast(gitReport, temporalReport);
|
|
190
|
+
|
|
191
|
+
const godClass = forecast.preAntiPatterns.filter(p => p.type === 'emerging-god-class');
|
|
192
|
+
expect(godClass.length).toBe(0);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe('pre-anti-pattern: emerging-shotgun-surgery', () => {
|
|
197
|
+
it('should detect shotgun surgery when many files are coupled', () => {
|
|
198
|
+
const engine = new ForecastEngine({ shotgunCouplingThreshold: 3 });
|
|
199
|
+
|
|
200
|
+
const mod = makeModule('src');
|
|
201
|
+
const ts = makeTemporalScore('src');
|
|
202
|
+
|
|
203
|
+
// Create 5 couplings involving src/
|
|
204
|
+
const couplings: ChangeCoupling[] = [];
|
|
205
|
+
for (let i = 0; i < 5; i++) {
|
|
206
|
+
couplings.push({
|
|
207
|
+
fileA: `src/file${i}.ts`,
|
|
208
|
+
fileB: `lib/dep${i}.ts`,
|
|
209
|
+
cochangeCount: 5,
|
|
210
|
+
confidence: 0.7,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const gitReport = makeGitReport([mod], couplings);
|
|
215
|
+
const temporalReport = makeTemporalReport([ts]);
|
|
216
|
+
|
|
217
|
+
const forecast = engine.forecast(gitReport, temporalReport);
|
|
218
|
+
|
|
219
|
+
const shotgun = forecast.preAntiPatterns.filter(p => p.type === 'emerging-shotgun-surgery');
|
|
220
|
+
expect(shotgun.length).toBe(1);
|
|
221
|
+
expect(shotgun[0].module).toBe('src');
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('should NOT detect shotgun when coupling count is below threshold', () => {
|
|
225
|
+
const engine = new ForecastEngine({ shotgunCouplingThreshold: 10 });
|
|
226
|
+
|
|
227
|
+
const mod = makeModule('src');
|
|
228
|
+
const ts = makeTemporalScore('src');
|
|
229
|
+
const couplings: ChangeCoupling[] = [{
|
|
230
|
+
fileA: 'src/a.ts',
|
|
231
|
+
fileB: 'lib/b.ts',
|
|
232
|
+
cochangeCount: 3,
|
|
233
|
+
confidence: 0.5,
|
|
234
|
+
}];
|
|
235
|
+
|
|
236
|
+
const gitReport = makeGitReport([mod], couplings);
|
|
237
|
+
const temporalReport = makeTemporalReport([ts]);
|
|
238
|
+
|
|
239
|
+
const forecast = engine.forecast(gitReport, temporalReport);
|
|
240
|
+
|
|
241
|
+
const shotgun = forecast.preAntiPatterns.filter(p => p.type === 'emerging-shotgun-surgery');
|
|
242
|
+
expect(shotgun.length).toBe(0);
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
describe('pre-anti-pattern: bus-factor-risk', () => {
|
|
247
|
+
it('should detect bus factor risk for single-contributor modules', () => {
|
|
248
|
+
const engine = new ForecastEngine({ busFatorRiskThreshold: 1 });
|
|
249
|
+
|
|
250
|
+
const mod = makeModule('src', {}, { busFactor: 1, aggregateCommits: 10 });
|
|
251
|
+
const ts = makeTemporalScore('src');
|
|
252
|
+
|
|
253
|
+
const gitReport = makeGitReport([mod]);
|
|
254
|
+
const temporalReport = makeTemporalReport([ts]);
|
|
255
|
+
|
|
256
|
+
const forecast = engine.forecast(gitReport, temporalReport);
|
|
257
|
+
|
|
258
|
+
const busRisk = forecast.preAntiPatterns.filter(p => p.type === 'bus-factor-risk');
|
|
259
|
+
expect(busRisk.length).toBe(1);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('should NOT flag bus factor risk for multi-contributor modules', () => {
|
|
263
|
+
const engine = new ForecastEngine({ busFatorRiskThreshold: 1 });
|
|
264
|
+
|
|
265
|
+
const mod = makeModule('src', {}, { busFactor: 3, aggregateCommits: 10 });
|
|
266
|
+
const ts = makeTemporalScore('src');
|
|
267
|
+
|
|
268
|
+
const gitReport = makeGitReport([mod]);
|
|
269
|
+
const temporalReport = makeTemporalReport([ts]);
|
|
270
|
+
|
|
271
|
+
const forecast = engine.forecast(gitReport, temporalReport);
|
|
272
|
+
|
|
273
|
+
const busRisk = forecast.preAntiPatterns.filter(p => p.type === 'bus-factor-risk');
|
|
274
|
+
expect(busRisk.length).toBe(0);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('should NOT flag bus factor risk with too few commits', () => {
|
|
278
|
+
const engine = new ForecastEngine({ busFatorRiskThreshold: 1 });
|
|
279
|
+
|
|
280
|
+
const mod = makeModule('src', {}, { busFactor: 1, aggregateCommits: 3 });
|
|
281
|
+
const ts = makeTemporalScore('src');
|
|
282
|
+
|
|
283
|
+
const gitReport = makeGitReport([mod]);
|
|
284
|
+
const temporalReport = makeTemporalReport([ts]);
|
|
285
|
+
|
|
286
|
+
const forecast = engine.forecast(gitReport, temporalReport);
|
|
287
|
+
|
|
288
|
+
const busRisk = forecast.preAntiPatterns.filter(p => p.type === 'bus-factor-risk');
|
|
289
|
+
expect(busRisk.length).toBe(0);
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
describe('pre-anti-pattern: complexity-spiral', () => {
|
|
294
|
+
it('should detect complexity spiral with accelerating churn and velocity', () => {
|
|
295
|
+
const engine = new ForecastEngine({ antiPatternThreshold: 40 });
|
|
296
|
+
|
|
297
|
+
const mod = makeModule('src', {
|
|
298
|
+
churnTrend: 30,
|
|
299
|
+
commitAcceleration: 25,
|
|
300
|
+
direction: 'accelerating',
|
|
301
|
+
});
|
|
302
|
+
const ts = makeTemporalScore('src', {
|
|
303
|
+
temporalScore: 55,
|
|
304
|
+
projectedScore: 30,
|
|
305
|
+
projectionWeeks: 12,
|
|
306
|
+
velocity: makeVelocity({
|
|
307
|
+
churnTrend: 30,
|
|
308
|
+
commitAcceleration: 25,
|
|
309
|
+
direction: 'accelerating',
|
|
310
|
+
}),
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
const gitReport = makeGitReport([mod]);
|
|
314
|
+
const temporalReport = makeTemporalReport([ts]);
|
|
315
|
+
|
|
316
|
+
const forecast = engine.forecast(gitReport, temporalReport);
|
|
317
|
+
|
|
318
|
+
const spiral = forecast.preAntiPatterns.filter(p => p.type === 'complexity-spiral');
|
|
319
|
+
expect(spiral.length).toBe(1);
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
describe('pre-anti-pattern: coupling-magnet', () => {
|
|
324
|
+
it('should detect coupling magnet with high inbound couplings and acceleration', () => {
|
|
325
|
+
const engine = new ForecastEngine();
|
|
326
|
+
|
|
327
|
+
const mod = makeModule('src', { commitAcceleration: 20, direction: 'accelerating' });
|
|
328
|
+
const ts = makeTemporalScore('src', {
|
|
329
|
+
velocity: makeVelocity({ commitAcceleration: 20, direction: 'accelerating' }),
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
const couplings: ChangeCoupling[] = [
|
|
333
|
+
{ fileA: 'lib/a.ts', fileB: 'src/core.ts', cochangeCount: 5, confidence: 0.8 },
|
|
334
|
+
{ fileA: 'utils/b.ts', fileB: 'src/core.ts', cochangeCount: 4, confidence: 0.7 },
|
|
335
|
+
{ fileA: 'api/c.ts', fileB: 'src/core.ts', cochangeCount: 6, confidence: 0.9 },
|
|
336
|
+
];
|
|
337
|
+
|
|
338
|
+
const gitReport = makeGitReport([mod], couplings);
|
|
339
|
+
const temporalReport = makeTemporalReport([ts]);
|
|
340
|
+
|
|
341
|
+
const forecast = engine.forecast(gitReport, temporalReport);
|
|
342
|
+
|
|
343
|
+
const magnet = forecast.preAntiPatterns.filter(p => p.type === 'coupling-magnet');
|
|
344
|
+
expect(magnet.length).toBe(1);
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
describe('module forecast', () => {
|
|
349
|
+
it('should classify critical health for very low temporal score', () => {
|
|
350
|
+
const engine = new ForecastEngine();
|
|
351
|
+
|
|
352
|
+
const mod = makeModule('src');
|
|
353
|
+
const ts = makeTemporalScore('src', { temporalScore: 20 });
|
|
354
|
+
|
|
355
|
+
const gitReport = makeGitReport([mod]);
|
|
356
|
+
const temporalReport = makeTemporalReport([ts]);
|
|
357
|
+
|
|
358
|
+
const forecast = engine.forecast(gitReport, temporalReport);
|
|
359
|
+
|
|
360
|
+
expect(forecast.modules[0].currentHealth).toBe('critical');
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it('should classify healthy for high temporal score', () => {
|
|
364
|
+
const engine = new ForecastEngine();
|
|
365
|
+
|
|
366
|
+
const mod = makeModule('src');
|
|
367
|
+
const ts = makeTemporalScore('src', { temporalScore: 85, trend: 'stable' });
|
|
368
|
+
|
|
369
|
+
const gitReport = makeGitReport([mod]);
|
|
370
|
+
const temporalReport = makeTemporalReport([ts]);
|
|
371
|
+
|
|
372
|
+
const forecast = engine.forecast(gitReport, temporalReport);
|
|
373
|
+
|
|
374
|
+
expect(forecast.modules[0].currentHealth).toBe('healthy');
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it('should forecast breakdown for modules with alerts', () => {
|
|
378
|
+
const engine = new ForecastEngine({ antiPatternThreshold: 40 });
|
|
379
|
+
|
|
380
|
+
const mod = makeModule('src', {
|
|
381
|
+
churnTrend: 30,
|
|
382
|
+
commitAcceleration: 25,
|
|
383
|
+
direction: 'accelerating',
|
|
384
|
+
});
|
|
385
|
+
const ts = makeTemporalScore('src', {
|
|
386
|
+
temporalScore: 55,
|
|
387
|
+
projectedScore: 25, // below 30 → breakdown
|
|
388
|
+
trend: 'degrading',
|
|
389
|
+
projectionWeeks: 12,
|
|
390
|
+
velocity: makeVelocity({
|
|
391
|
+
churnTrend: 30,
|
|
392
|
+
commitAcceleration: 25,
|
|
393
|
+
direction: 'accelerating',
|
|
394
|
+
}),
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
const gitReport = makeGitReport([mod]);
|
|
398
|
+
const temporalReport = makeTemporalReport([ts], { overallTrend: 'degrading' });
|
|
399
|
+
|
|
400
|
+
const forecast = engine.forecast(gitReport, temporalReport);
|
|
401
|
+
|
|
402
|
+
// Either breakdown or declining due to degrading trend
|
|
403
|
+
expect(['breakdown', 'declining']).toContain(forecast.modules[0].forecast6Months);
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
describe('overall outlook', () => {
|
|
408
|
+
it('should be sunny for healthy projects', () => {
|
|
409
|
+
const engine = new ForecastEngine();
|
|
410
|
+
|
|
411
|
+
const mod = makeModule('src', {}, { busFactor: 5 });
|
|
412
|
+
const ts = makeTemporalScore('src', { temporalScore: 85, trend: 'stable' });
|
|
413
|
+
|
|
414
|
+
const gitReport = makeGitReport([mod]);
|
|
415
|
+
const temporalReport = makeTemporalReport([ts]);
|
|
416
|
+
|
|
417
|
+
const forecast = engine.forecast(gitReport, temporalReport);
|
|
418
|
+
|
|
419
|
+
expect(forecast.overallOutlook).toBe('sunny');
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
it('should be stormy when overall trend is degrading', () => {
|
|
423
|
+
const engine = new ForecastEngine();
|
|
424
|
+
|
|
425
|
+
const mod = makeModule('src', { churnTrend: 50, direction: 'accelerating' });
|
|
426
|
+
const ts = makeTemporalScore('src', {
|
|
427
|
+
temporalScore: 40,
|
|
428
|
+
trend: 'degrading',
|
|
429
|
+
velocity: makeVelocity({ churnTrend: 50 }),
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
const gitReport = makeGitReport([mod]);
|
|
433
|
+
const temporalReport = makeTemporalReport([ts], { overallTrend: 'degrading' });
|
|
434
|
+
|
|
435
|
+
const forecast = engine.forecast(gitReport, temporalReport);
|
|
436
|
+
|
|
437
|
+
expect(forecast.overallOutlook).toBe('stormy');
|
|
438
|
+
});
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
describe('recommendations', () => {
|
|
442
|
+
it('should generate recommendations for critical modules', () => {
|
|
443
|
+
const engine = new ForecastEngine();
|
|
444
|
+
|
|
445
|
+
const mod = makeModule('src');
|
|
446
|
+
const ts = makeTemporalScore('src', { temporalScore: 20 });
|
|
447
|
+
|
|
448
|
+
const gitReport = makeGitReport([mod]);
|
|
449
|
+
const temporalReport = makeTemporalReport([ts]);
|
|
450
|
+
|
|
451
|
+
const forecast = engine.forecast(gitReport, temporalReport);
|
|
452
|
+
|
|
453
|
+
expect(forecast.recommendations.length).toBeGreaterThan(0);
|
|
454
|
+
expect(forecast.recommendations[0]).toContain('src');
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
it('should return healthy message when no issues', () => {
|
|
458
|
+
const engine = new ForecastEngine();
|
|
459
|
+
|
|
460
|
+
const mod = makeModule('src', {}, { busFactor: 5 });
|
|
461
|
+
const ts = makeTemporalScore('src', {
|
|
462
|
+
temporalScore: 90,
|
|
463
|
+
trend: 'stable',
|
|
464
|
+
projectedScore: 88,
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
const gitReport = makeGitReport([mod]);
|
|
468
|
+
const temporalReport = makeTemporalReport([ts]);
|
|
469
|
+
|
|
470
|
+
const forecast = engine.forecast(gitReport, temporalReport);
|
|
471
|
+
|
|
472
|
+
expect(forecast.recommendations.length).toBeGreaterThan(0);
|
|
473
|
+
expect(forecast.recommendations[0].toLowerCase()).toContain('healthy');
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
describe('bottleneck probability', () => {
|
|
478
|
+
it('should be higher for degrading low-score modules', () => {
|
|
479
|
+
const engine = new ForecastEngine();
|
|
480
|
+
|
|
481
|
+
const goodMod = makeModule('good', {}, { busFactor: 5 });
|
|
482
|
+
const badMod = makeModule('bad', {
|
|
483
|
+
churnTrend: 50, direction: 'accelerating',
|
|
484
|
+
}, { busFactor: 1 });
|
|
485
|
+
|
|
486
|
+
const goodTs = makeTemporalScore('good', { temporalScore: 90, trend: 'stable' });
|
|
487
|
+
const badTs = makeTemporalScore('bad', {
|
|
488
|
+
temporalScore: 35,
|
|
489
|
+
trend: 'degrading',
|
|
490
|
+
velocity: makeVelocity({ churnTrend: 50 }),
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
const gitReport = makeGitReport([goodMod, badMod]);
|
|
494
|
+
const temporalReport = makeTemporalReport([goodTs, badTs]);
|
|
495
|
+
|
|
496
|
+
const forecast = engine.forecast(gitReport, temporalReport);
|
|
497
|
+
|
|
498
|
+
const good = forecast.modules.find(m => m.module === 'good')!;
|
|
499
|
+
const bad = forecast.modules.find(m => m.module === 'bad')!;
|
|
500
|
+
|
|
501
|
+
expect(bad.bottleneckProbability).toBeGreaterThan(good.bottleneckProbability);
|
|
502
|
+
});
|
|
503
|
+
});
|
|
504
|
+
});
|