Repository navigation
Expand file tree
/
Copy pathtest_install.sh
More file actions
executable file
·404 lines (341 loc) · 10.3 KB
/
Copy pathtest_install.sh
File metadata and controls
executable file
·404 lines (341 loc) · 10.3 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
#!/bin/bash
set -euo pipefail
# AIFlow - Installation Test Script
# This script validates the installation in a temporary environment
# Get the absolute path to the project root
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Source security library
source "$PROJECT_ROOT/scripts/common_security.sh" || {
echo "Error: Failed to load security library" >&2
exit 1
}
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Test configuration
TEST_DIR=$(secure_temp_dir "claude-pm-test") || {
echo "Error: Failed to create test directory" >&2
exit 1
}
TEST_HOME="$TEST_DIR/home"
TEST_LOG="$TEST_DIR/test.log"
# Test counters
TESTS_RUN=0
TESTS_PASSED=0
TESTS_FAILED=0
# Cleanup function
final_cleanup() {
if [[ -n "${TEST_DIR:-}" ]] && [[ -d "$TEST_DIR" ]]; then
echo ""
echo "Cleaning up test directory..."
rm -rf "$TEST_DIR"
fi
}
# Signal handler
handle_signal() {
local signal="$1"
print_status "warning" "Test interrupted by signal: $signal"
log_security_event "INTERRUPT" "Test interrupted" "Signal: $signal"
exit 130
}
# Set up cleanup and signal traps
setup_cleanup_trap final_cleanup
trap 'handle_signal INT' INT
trap 'handle_signal TERM' TERM
trap 'handle_signal HUP' HUP
echo "🧪 AI Software Project Management System - Installation Test"
echo "=========================================================="
echo ""
# Function to print colored output
print_status() {
local status=$1
local message=$2
case $status in
"success")
echo -e "${GREEN}✅ $message${NC}" | tee -a "$TEST_LOG"
;;
"error")
echo -e "${RED}❌ $message${NC}" | tee -a "$TEST_LOG"
;;
"warning")
echo -e "${YELLOW}⚠️ $message${NC}" | tee -a "$TEST_LOG"
;;
"info")
echo -e "${BLUE}ℹ️ $message${NC}" | tee -a "$TEST_LOG"
;;
"test")
echo -e "${CYAN}🧪 $message${NC}" | tee -a "$TEST_LOG"
;;
esac
}
# Function to run a test
run_test() {
local test_name=$1
local test_function=$2
((TESTS_RUN++))
print_status "test" "Running: $test_name"
if $test_function; then
((TESTS_PASSED++))
print_status "success" "$test_name"
else
((TESTS_FAILED++))
print_status "error" "$test_name"
fi
}
# Setup test environment
setup_test_env() {
print_status "info" "Setting up test environment at $TEST_DIR"
# Create test directory structure
mkdir -p "$TEST_HOME/.claude/commands" || return 1
mkdir -p "$TEST_DIR/logs" || return 1
# Initialize log
echo "Test started at $(date)" > "$TEST_LOG"
return 0
}
# Cleanup test environment
cleanup_test_env() {
print_status "info" "Cleaning up test environment"
if [[ -d "$TEST_DIR" ]]; then
rm -rf "$TEST_DIR"
fi
}
# Test: Prerequisites check
test_prerequisites() {
# Test Python detection
if command -v python3 >/dev/null 2>&1; then
local version=$(get_python_version "python3")
if [[ $? -eq 0 ]] && version_ge "$version" "3.7"; then
return 0
fi
fi
return 1
}
# Test: Fresh installation
test_fresh_install() {
# Run install script with test home
HOME="$TEST_HOME" bash "$PROJECT_ROOT/install.sh" >> "$TEST_LOG" 2>&1
# Check if installation succeeded
if [[ -d "$TEST_HOME/.claude/commands/project" ]]; then
return 0
fi
return 1
}
# Test: Command files installed
test_command_files() {
local expected_commands=(
"setup.md"
"start.md"
"status.md"
"pause.md"
"resume.md"
"stop.md"
"doctor.md"
)
local missing=0
for cmd in "${expected_commands[@]}"; do
if [[ ! -f "$TEST_HOME/.claude/commands/project/$cmd" ]]; then
echo "Missing command: $cmd" >> "$TEST_LOG"
((missing++))
fi
done
return $missing
}
# Test: Python modules installed
test_python_modules() {
local module_path="$TEST_HOME/.claude/commands/project/lib"
# Check key Python files
local key_modules=(
"src/state_manager.py"
"src/config.py"
"src/git_operations.py"
"src/project_builder.py"
)
local missing=0
for module in "${key_modules[@]}"; do
if [[ ! -f "$module_path/$module" ]]; then
echo "Missing module: $module" >> "$TEST_LOG"
((missing++))
fi
done
return $missing
}
# Test: Hooks installed
test_hooks_installed() {
local hooks_path="$TEST_HOME/.claude/commands/project/hooks"
# Check key hook files
local key_hooks=(
"pre_tool_use.py"
"post_tool_use.py"
"stop.py"
"workflow_rules.py"
"hook_utils.py"
)
local missing=0
for hook in "${key_hooks[@]}"; do
if [[ ! -f "$hooks_path/$hook" ]]; then
echo "Missing hook: $hook" >> "$TEST_LOG"
((missing++))
fi
done
# Check README exists
if [[ ! -f "$hooks_path/README.md" ]]; then
echo "Missing hooks README" >> "$TEST_LOG"
((missing++))
fi
return $missing
}
# Test: No test files included
test_no_test_files() {
# Ensure tests directory was not copied
if [[ -d "$TEST_HOME/.claude/commands/project/lib/tests" ]]; then
echo "Test files found in installation" >> "$TEST_LOG"
return 1
fi
# Check for test files in other locations
local test_files=$(find "$TEST_HOME/.claude/commands/project" -name "*test*.py" -o -name "test_*" | wc -l)
if [[ $test_files -gt 0 ]]; then
echo "Found $test_files test files in installation" >> "$TEST_LOG"
return 1
fi
return 0
}
# Test: Python import validation
test_python_imports() {
local module_path="$TEST_HOME/.claude/commands/project/lib"
# Test basic import
local import_test='import sys; sys.path.insert(0, "'"$module_path"'"); from src.state_manager import StateManager'
if safe_execute "python3" -c "$import_test" 2>/dev/null; then
return 0
fi
echo "Python import test failed" >> "$TEST_LOG"
return 1
}
# Test: Scripts are executable
test_scripts_executable() {
local errors=0
# Check if scripts were copied and made executable
for script in logged_secure_shell.py analyze_logs.sh; do
local script_path="$TEST_HOME/.claude/commands/$script"
if [[ -f "$script_path" ]]; then
if [[ ! -x "$script_path" ]]; then
echo "$script not executable" >> "$TEST_LOG"
((errors++))
fi
else
echo "$script not found" >> "$TEST_LOG"
((errors++))
fi
done
return $errors
}
# Test: Upgrade over existing installation
test_upgrade_install() {
# Create a fake old installation
mkdir -p "$TEST_HOME/.claude/commands/project/old_file"
echo "old version" > "$TEST_HOME/.claude/commands/project/version.txt"
# Run install again
HOME="$TEST_HOME" bash "$PROJECT_ROOT/install.sh" >> "$TEST_LOG" 2>&1
# Check if new files exist
if [[ -f "$TEST_HOME/.claude/commands/project/setup.md" ]]; then
return 0
fi
return 1
}
# Test: Installation validation
test_installation_validation() {
# The install script should validate itself
# Check if validation passed by looking for key indicators
if grep -q "Installation validation passed" "$TEST_LOG"; then
return 0
fi
return 1
}
# Test: Uninstall functionality
test_uninstall() {
# First ensure we have an installation
if [[ ! -d "$TEST_HOME/.claude/commands/project" ]]; then
test_fresh_install
fi
# Run uninstall with auto-confirm
echo "n" | HOME="$TEST_HOME" bash "$PROJECT_ROOT/uninstall.sh" >> "$TEST_LOG" 2>&1
echo "y" | HOME="$TEST_HOME" bash "$PROJECT_ROOT/uninstall.sh" >> "$TEST_LOG" 2>&1
# Check if files were removed
if [[ ! -d "$TEST_HOME/.claude/commands/project" ]]; then
return 0
fi
return 1
}
# Show test results
show_results() {
echo ""
echo "============================================="
echo "Test Results"
echo "============================================="
echo ""
echo "Tests run: $TESTS_RUN"
echo "Tests passed: $TESTS_PASSED"
echo "Tests failed: $TESTS_FAILED"
echo ""
if [[ $TESTS_FAILED -eq 0 ]]; then
print_status "success" "All tests passed! 🎉"
echo ""
echo "The installation script is working correctly."
else
print_status "error" "Some tests failed!"
echo ""
echo "Please check the test log for details:"
echo " $TEST_LOG"
echo ""
echo "Common issues:"
echo " • Missing files in the project"
echo " • Permission issues"
echo " • Script errors"
fi
echo ""
echo "Test directory: $TEST_DIR"
echo "(will be cleaned up automatically)"
}
# Main test flow
main() {
# Setup test environment
if ! setup_test_env; then
print_status "error" "Failed to setup test environment"
exit 1
fi
# Run tests
print_status "info" "Running installation tests..."
echo ""
run_test "Prerequisites Check" test_prerequisites
run_test "Fresh Installation" test_fresh_install
run_test "Command Files" test_command_files
run_test "Python Modules" test_python_modules
run_test "Hook Scripts" test_hooks_installed
run_test "No Test Files" test_no_test_files
run_test "Python Imports" test_python_imports
run_test "Scripts Executable" test_scripts_executable
run_test "Upgrade Installation" test_upgrade_install
run_test "Installation Validation" test_installation_validation
run_test "Uninstall Script" test_uninstall
# Show results
show_results
# Cleanup (optional - comment out to inspect test directory)
read -p "Clean up test directory? (Y/n): " cleanup_choice
validate_yes_no "$cleanup_choice"
local response=$?
if [[ $response -eq 0 ]] || [[ $response -eq 2 ]]; then
# Yes or invalid (default to yes)
cleanup_test_env
fi
# Exit with appropriate code
if [[ $TESTS_FAILED -eq 0 ]]; then
exit 0
else
exit 1
fi
}
# Run main test
main