Repository navigation
Expand file tree
/
Copy pathvalidate_modular_architecture.py
More file actions
208 lines (156 loc) · 6.37 KB
/
Copy pathvalidate_modular_architecture.py
File metadata and controls
208 lines (156 loc) · 6.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env python3
"""
Validation script for HexStrike AI modular architecture.
Tests that all modules can be imported and core functionality works.
"""
import sys
import os
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent / "src"))
def test_core_imports():
"""Test that all core modules can be imported"""
print("Testing core module imports...")
try:
from hexstrike.platform.constants import API_HOST, API_PORT, COLORS
print("✅ Platform constants imported")
from hexstrike.platform.errors import ErrorHandler, ErrorType
print("✅ Platform errors imported")
from hexstrike.platform.logging import configure_logging, LogConfig
print("✅ Platform logging imported")
from hexstrike.services.decision_service import DecisionService
print("✅ Decision service imported")
from hexstrike.services.tool_execution_service import ToolExecutionService
print("✅ Tool execution service imported")
from hexstrike.services.process_service import ProcessService
print("✅ Process service imported")
from hexstrike.adapters.tool_registry import ToolRegistry
print("✅ Tool registry imported")
from hexstrike.adapters.flask_adapter import FlaskAdapter
print("✅ Flask adapter imported")
from hexstrike.interfaces.visual_engine import VisualEngine
print("✅ Visual engine imported")
from hexstrike.legacy.compatibility_shims import IntelligentDecisionEngine
print("✅ Compatibility shims imported")
return True
except ImportError as e:
print(f"❌ Import error: {e}")
return False
def test_tool_registry():
"""Test tool registry functionality"""
print("\nTesting tool registry functionality...")
try:
from hexstrike.adapters.tool_registry import ToolRegistry
registry = ToolRegistry()
tools = registry.get_all_tools()
print(f"✅ Tool registry loaded with {len(tools)} tools")
nmap_tool = registry.get_tool('nmap')
if nmap_tool:
print("✅ Nmap tool found in registry")
else:
print("❌ Nmap tool not found")
return False
nuclei_tool = registry.get_tool('nuclei')
if nuclei_tool:
print("✅ Nuclei tool found in registry")
else:
print("❌ Nuclei tool not found")
return False
gobuster_tool = registry.get_tool('gobuster')
if gobuster_tool:
print("✅ Gobuster tool found in registry")
else:
print("❌ Gobuster tool not found")
return False
return True
except Exception as e:
print(f"❌ Tool registry error: {e}")
return False
def test_service_instantiation():
"""Test that services can be instantiated"""
print("\nTesting service instantiation...")
try:
from hexstrike.services.decision_service import DecisionService
from hexstrike.services.tool_execution_service import ToolExecutionService
from hexstrike.services.process_service import ProcessService
from hexstrike.platform.errors import ErrorHandler
decision_service = DecisionService()
print("✅ Decision service instantiated")
execution_service = ToolExecutionService()
print("✅ Tool execution service instantiated")
process_service = ProcessService()
print("✅ Process service instantiated")
error_handler = ErrorHandler()
print("✅ Error handler instantiated")
return True
except Exception as e:
print(f"❌ Service instantiation error: {e}")
return False
def test_compatibility_layer():
"""Test backward compatibility layer"""
print("\nTesting compatibility layer...")
try:
from hexstrike.legacy.compatibility_shims import (
IntelligentDecisionEngine,
ModernVisualEngine,
IntelligentErrorHandler
)
decision_engine = IntelligentDecisionEngine()
print("✅ Compatibility decision engine instantiated")
visual_engine = ModernVisualEngine()
print("✅ Compatibility visual engine instantiated")
error_handler = IntelligentErrorHandler()
print("✅ Compatibility error handler instantiated")
return True
except Exception as e:
print(f"❌ Compatibility layer error: {e}")
return False
def check_line_limits():
"""Check that all modules are ≤300 lines"""
print("\nChecking line limits...")
src_path = Path(__file__).parent / "src" / "hexstrike"
violations = []
for py_file in src_path.rglob("*.py"):
if "legacy" in str(py_file) or "__pycache__" in str(py_file):
continue
with open(py_file, 'r') as f:
line_count = len(f.readlines())
if line_count > 300:
violations.append(f"{py_file.relative_to(src_path)}: {line_count} lines")
else:
print(f"✅ {py_file.relative_to(src_path)}: {line_count} lines")
if violations:
print(f"❌ Modules exceeding 300 lines: {violations}")
return False
print("✅ All modules are ≤300 lines")
return True
def main():
"""Run all validation tests"""
print("🚀 HexStrike AI Modular Architecture Validation")
print("=" * 50)
tests = [
test_core_imports,
test_tool_registry,
test_service_instantiation,
test_compatibility_layer,
check_line_limits
]
passed = 0
total = len(tests)
for test in tests:
try:
if test():
passed += 1
else:
print(f"❌ Test {test.__name__} failed")
except Exception as e:
print(f"❌ Test {test.__name__} crashed: {e}")
print("\n" + "=" * 50)
print(f"Results: {passed}/{total} tests passed")
if passed == total:
print("✅ All validation tests passed!")
return 0
else:
print("❌ Some validation tests failed!")
return 1
if __name__ == "__main__":
sys.exit(main())