@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.
Files changed (217) hide show
  1. package/dist/src/core/analyzer.d.ts +42 -0
  2. package/dist/src/core/analyzer.js +431 -0
  3. package/dist/src/core/analyzer.js.map +1 -0
  4. package/dist/src/core/analyzers/forecast.d.ts +84 -0
  5. package/dist/src/core/analyzers/forecast.js +338 -0
  6. package/dist/src/core/analyzers/forecast.js.map +1 -0
  7. package/dist/src/core/analyzers/index.d.ts +9 -0
  8. package/dist/src/core/analyzers/index.js +7 -0
  9. package/dist/src/core/analyzers/index.js.map +1 -0
  10. package/dist/src/core/analyzers/temporal-scorer.d.ts +71 -0
  11. package/dist/src/core/analyzers/temporal-scorer.js +141 -0
  12. package/dist/src/core/analyzers/temporal-scorer.js.map +1 -0
  13. package/dist/src/core/anti-patterns.d.ts +28 -0
  14. package/dist/src/core/anti-patterns.js +264 -0
  15. package/dist/src/core/anti-patterns.js.map +1 -0
  16. package/dist/src/core/ast/ast-parser.interface.d.ts +20 -0
  17. package/dist/src/core/ast/ast-parser.interface.js +2 -0
  18. package/dist/src/core/ast/ast-parser.interface.js.map +1 -0
  19. package/dist/src/core/ast/path-resolver.d.ts +13 -0
  20. package/dist/src/core/ast/path-resolver.js +54 -0
  21. package/dist/src/core/ast/path-resolver.js.map +1 -0
  22. package/dist/src/core/ast/tree-sitter-parser.d.ts +10 -0
  23. package/dist/src/core/ast/tree-sitter-parser.js +142 -0
  24. package/dist/src/core/ast/tree-sitter-parser.js.map +1 -0
  25. package/dist/src/core/config.d.ts +11 -0
  26. package/dist/src/core/config.js +112 -0
  27. package/dist/src/core/config.js.map +1 -0
  28. package/dist/src/core/diagram.d.ts +9 -0
  29. package/dist/src/core/diagram.js +101 -0
  30. package/dist/src/core/diagram.js.map +1 -0
  31. package/dist/src/core/i18n.d.ts +14 -0
  32. package/dist/src/core/i18n.js +54 -0
  33. package/dist/src/core/i18n.js.map +1 -0
  34. package/dist/src/core/locales/en.d.ts +2 -0
  35. package/dist/src/core/locales/en.js +337 -0
  36. package/dist/src/core/locales/en.js.map +1 -0
  37. package/dist/src/core/locales/pt-BR.d.ts +172 -0
  38. package/dist/src/core/locales/pt-BR.js +337 -0
  39. package/dist/src/core/locales/pt-BR.js.map +1 -0
  40. package/dist/src/core/locales/types.d.ts +86 -0
  41. package/dist/src/core/locales/types.js +2 -0
  42. package/dist/src/core/locales/types.js.map +1 -0
  43. package/dist/src/core/plugin-loader.d.ts +11 -0
  44. package/dist/src/core/plugin-loader.js +67 -0
  45. package/dist/src/core/plugin-loader.js.map +1 -0
  46. package/dist/src/core/project-summarizer.d.ts +16 -0
  47. package/dist/src/core/project-summarizer.js +37 -0
  48. package/dist/src/core/project-summarizer.js.map +1 -0
  49. package/dist/src/core/refactor-engine.d.ts +18 -0
  50. package/dist/src/core/refactor-engine.js +87 -0
  51. package/dist/src/core/refactor-engine.js.map +1 -0
  52. package/dist/src/core/rules/barrel-optimizer.d.ts +13 -0
  53. package/dist/src/core/rules/barrel-optimizer.js +76 -0
  54. package/dist/src/core/rules/barrel-optimizer.js.map +1 -0
  55. package/dist/src/core/rules/dead-code-detector.d.ts +21 -0
  56. package/dist/src/core/rules/dead-code-detector.js +116 -0
  57. package/dist/src/core/rules/dead-code-detector.js.map +1 -0
  58. package/dist/src/core/rules/hub-splitter.d.ts +13 -0
  59. package/dist/src/core/rules/hub-splitter.js +117 -0
  60. package/dist/src/core/rules/hub-splitter.js.map +1 -0
  61. package/dist/src/core/rules/import-organizer.d.ts +13 -0
  62. package/dist/src/core/rules/import-organizer.js +84 -0
  63. package/dist/src/core/rules/import-organizer.js.map +1 -0
  64. package/dist/src/core/rules/module-grouper.d.ts +13 -0
  65. package/dist/src/core/rules/module-grouper.js +116 -0
  66. package/dist/src/core/rules/module-grouper.js.map +1 -0
  67. package/dist/src/core/rules-engine.d.ts +7 -0
  68. package/dist/src/core/rules-engine.js +89 -0
  69. package/dist/src/core/rules-engine.js.map +1 -0
  70. package/dist/src/core/scorer.d.ts +15 -0
  71. package/dist/src/core/scorer.js +165 -0
  72. package/dist/src/core/scorer.js.map +1 -0
  73. package/dist/src/core/summarizer/keyword-extractor.d.ts +6 -0
  74. package/dist/src/core/summarizer/keyword-extractor.js +38 -0
  75. package/dist/src/core/summarizer/keyword-extractor.js.map +1 -0
  76. package/dist/src/core/summarizer/module-inferrer.d.ts +11 -0
  77. package/dist/src/core/summarizer/module-inferrer.js +171 -0
  78. package/dist/src/core/summarizer/module-inferrer.js.map +1 -0
  79. package/dist/src/core/summarizer/package-reader.d.ts +3 -0
  80. package/dist/src/core/summarizer/package-reader.js +33 -0
  81. package/dist/src/core/summarizer/package-reader.js.map +1 -0
  82. package/dist/src/core/summarizer/purpose-inferrer.d.ts +8 -0
  83. package/dist/src/core/summarizer/purpose-inferrer.js +179 -0
  84. package/dist/src/core/summarizer/purpose-inferrer.js.map +1 -0
  85. package/dist/src/core/summarizer/readme-reader.d.ts +3 -0
  86. package/dist/src/core/summarizer/readme-reader.js +24 -0
  87. package/dist/src/core/summarizer/readme-reader.js.map +1 -0
  88. package/dist/src/core/types/architect-rules.d.ts +27 -0
  89. package/dist/src/core/types/architect-rules.js +2 -0
  90. package/dist/src/core/types/architect-rules.js.map +1 -0
  91. package/dist/src/core/types/core.d.ts +87 -0
  92. package/dist/src/core/types/core.js +2 -0
  93. package/dist/src/core/types/core.js.map +1 -0
  94. package/dist/src/core/types/infrastructure.d.ts +38 -0
  95. package/dist/src/core/types/infrastructure.js +2 -0
  96. package/dist/src/core/types/infrastructure.js.map +1 -0
  97. package/dist/src/core/types/plugin.d.ts +12 -0
  98. package/dist/src/core/types/plugin.js +2 -0
  99. package/dist/src/core/types/plugin.js.map +1 -0
  100. package/dist/src/core/types/rules.d.ts +53 -0
  101. package/dist/src/core/types/rules.js +2 -0
  102. package/dist/src/core/types/rules.js.map +1 -0
  103. package/dist/src/core/types/summarizer.d.ts +12 -0
  104. package/dist/src/core/types/summarizer.js +2 -0
  105. package/dist/src/core/types/summarizer.js.map +1 -0
  106. package/dist/src/infrastructure/git-cache.d.ts +6 -0
  107. package/dist/src/infrastructure/git-cache.js +41 -0
  108. package/dist/src/infrastructure/git-cache.js.map +1 -0
  109. package/dist/src/infrastructure/git-history.d.ts +112 -0
  110. package/dist/src/infrastructure/git-history.js +340 -0
  111. package/dist/src/infrastructure/git-history.js.map +1 -0
  112. package/dist/src/infrastructure/logger.d.ts +20 -0
  113. package/dist/src/infrastructure/logger.js +57 -0
  114. package/dist/src/infrastructure/logger.js.map +1 -0
  115. package/dist/src/infrastructure/scanner.d.ts +31 -0
  116. package/dist/src/infrastructure/scanner.js +334 -0
  117. package/dist/src/infrastructure/scanner.js.map +1 -0
  118. package/dist/tests/analyzers-integration.test.d.ts +7 -0
  119. package/dist/tests/analyzers-integration.test.js +140 -0
  120. package/dist/tests/analyzers-integration.test.js.map +1 -0
  121. package/dist/tests/anti-patterns.test.d.ts +1 -0
  122. package/dist/tests/anti-patterns.test.js +81 -0
  123. package/dist/tests/anti-patterns.test.js.map +1 -0
  124. package/dist/tests/ast-parser.test.d.ts +1 -0
  125. package/dist/tests/ast-parser.test.js +94 -0
  126. package/dist/tests/ast-parser.test.js.map +1 -0
  127. package/dist/tests/fixtures/monorepo/packages/app/src/index.d.ts +1 -0
  128. package/dist/tests/fixtures/monorepo/packages/app/src/index.js +9 -0
  129. package/dist/tests/fixtures/monorepo/packages/app/src/index.js.map +1 -0
  130. package/dist/tests/fixtures/monorepo/packages/core/src/index.d.ts +2 -0
  131. package/dist/tests/fixtures/monorepo/packages/core/src/index.js +11 -0
  132. package/dist/tests/fixtures/monorepo/packages/core/src/index.js.map +1 -0
  133. package/dist/tests/forecast.test.d.ts +7 -0
  134. package/dist/tests/forecast.test.js +380 -0
  135. package/dist/tests/forecast.test.js.map +1 -0
  136. package/dist/tests/git-history.test.d.ts +7 -0
  137. package/dist/tests/git-history.test.js +193 -0
  138. package/dist/tests/git-history.test.js.map +1 -0
  139. package/dist/tests/i18n.test.d.ts +1 -0
  140. package/dist/tests/i18n.test.js +39 -0
  141. package/dist/tests/i18n.test.js.map +1 -0
  142. package/dist/tests/monorepo-scan.test.d.ts +11 -0
  143. package/dist/tests/monorepo-scan.test.js +143 -0
  144. package/dist/tests/monorepo-scan.test.js.map +1 -0
  145. package/dist/tests/plugin-loader.test.d.ts +1 -0
  146. package/dist/tests/plugin-loader.test.js +31 -0
  147. package/dist/tests/plugin-loader.test.js.map +1 -0
  148. package/dist/tests/rules-engine.test.d.ts +1 -0
  149. package/dist/tests/rules-engine.test.js +112 -0
  150. package/dist/tests/rules-engine.test.js.map +1 -0
  151. package/dist/tests/scanner.test.d.ts +1 -0
  152. package/dist/tests/scanner.test.js +44 -0
  153. package/dist/tests/scanner.test.js.map +1 -0
  154. package/dist/tests/scorer.test.d.ts +1 -0
  155. package/dist/tests/scorer.test.js +610 -0
  156. package/dist/tests/scorer.test.js.map +1 -0
  157. package/dist/tests/temporal-scorer.test.d.ts +7 -0
  158. package/dist/tests/temporal-scorer.test.js +239 -0
  159. package/dist/tests/temporal-scorer.test.js.map +1 -0
  160. package/package.json +29 -0
  161. package/src/core/analyzer.ts +499 -0
  162. package/src/core/analyzers/forecast.ts +497 -0
  163. package/src/core/analyzers/index.ts +33 -0
  164. package/src/core/analyzers/temporal-scorer.ts +227 -0
  165. package/src/core/anti-patterns.ts +324 -0
  166. package/src/core/ast/ast-parser.interface.ts +21 -0
  167. package/src/core/ast/path-resolver.ts +61 -0
  168. package/src/core/ast/tree-sitter-parser.ts +158 -0
  169. package/src/core/config.ts +125 -0
  170. package/src/core/diagram.ts +129 -0
  171. package/src/core/i18n.ts +64 -0
  172. package/src/core/locales/en.ts +340 -0
  173. package/src/core/locales/pt-BR.ts +341 -0
  174. package/src/core/locales/types.ts +95 -0
  175. package/src/core/plugin-loader.ts +80 -0
  176. package/src/core/project-summarizer.ts +42 -0
  177. package/src/core/refactor-engine.ts +112 -0
  178. package/src/core/rules/barrel-optimizer.ts +99 -0
  179. package/src/core/rules/dead-code-detector.ts +134 -0
  180. package/src/core/rules/hub-splitter.ts +135 -0
  181. package/src/core/rules/import-organizer.ts +100 -0
  182. package/src/core/rules/module-grouper.ts +133 -0
  183. package/src/core/rules-engine.ts +100 -0
  184. package/src/core/scorer.ts +181 -0
  185. package/src/core/summarizer/keyword-extractor.ts +53 -0
  186. package/src/core/summarizer/module-inferrer.ts +194 -0
  187. package/src/core/summarizer/package-reader.ts +34 -0
  188. package/src/core/summarizer/purpose-inferrer.ts +197 -0
  189. package/src/core/summarizer/readme-reader.ts +24 -0
  190. package/src/core/types/architect-rules.ts +29 -0
  191. package/src/core/types/core.ts +94 -0
  192. package/src/core/types/infrastructure.ts +41 -0
  193. package/src/core/types/plugin.ts +19 -0
  194. package/src/core/types/rules.ts +51 -0
  195. package/src/core/types/summarizer.ts +8 -0
  196. package/src/infrastructure/git-cache.ts +52 -0
  197. package/src/infrastructure/git-history.ts +496 -0
  198. package/src/infrastructure/logger.ts +68 -0
  199. package/src/infrastructure/scanner.ts +349 -0
  200. package/tests/analyzers-integration.test.ts +174 -0
  201. package/tests/anti-patterns.test.ts +95 -0
  202. package/tests/ast-parser.test.ts +102 -0
  203. package/tests/fixtures/monorepo/package.json +6 -0
  204. package/tests/fixtures/monorepo/packages/app/package.json +12 -0
  205. package/tests/fixtures/monorepo/packages/app/src/index.ts +6 -0
  206. package/tests/fixtures/monorepo/packages/core/package.json +7 -0
  207. package/tests/fixtures/monorepo/packages/core/src/index.ts +7 -0
  208. package/tests/forecast.test.ts +504 -0
  209. package/tests/git-history.test.ts +254 -0
  210. package/tests/i18n.test.ts +47 -0
  211. package/tests/monorepo-scan.test.ts +170 -0
  212. package/tests/plugin-loader.test.ts +40 -0
  213. package/tests/rules-engine.test.ts +131 -0
  214. package/tests/scanner.test.ts +54 -0
  215. package/tests/scorer.test.ts +675 -0
  216. package/tests/temporal-scorer.test.ts +306 -0
  217. 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,6 @@
1
+ {
2
+ "name": "@test/monorepo",
3
+ "version": "1.0.0",
4
+ "description": "Test monorepo for E2E scanner validation",
5
+ "workspaces": ["packages/*"]
6
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@test/app",
3
+ "version": "1.0.0",
4
+ "description": "Express application server",
5
+ "main": "src/index.ts",
6
+ "bin": {
7
+ "app-server": "./src/index.ts"
8
+ },
9
+ "dependencies": {
10
+ "express": "^4.18.0"
11
+ }
12
+ }
@@ -0,0 +1,6 @@
1
+ import { greet } from '../../core/src/index';
2
+
3
+ export function startServer(port: number): void {
4
+ const message = greet('World');
5
+ console.log(`Server on port ${port}: ${message}`);
6
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@test/core",
3
+ "version": "1.0.0",
4
+ "description": "Core business logic module",
5
+ "main": "src/index.ts",
6
+ "dependencies": {}
7
+ }
@@ -0,0 +1,7 @@
1
+ export function greet(name: string): string {
2
+ return `Hello, ${name}`;
3
+ }
4
+
5
+ export function calculate(a: number, b: number): number {
6
+ return a + b;
7
+ }
@@ -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
+ });