prole/tests/test_network_scan_fix.sh

90 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
echo "========================================"
echo " Network Scan Fix Verification"
echo "========================================"
echo ""
# Test 1: Scan directory creation
echo "1. Testing scan directory creation..."
python3 << 'PYTEST'
from pathlib import Path
prole_home = Path.home() / ".prole"
scan_dir = prole_home / "scan"
scan_dir.mkdir(parents=True, exist_ok=True)
if scan_dir.exists() and scan_dir.is_dir():
print(" ✓ Scan directory created")
else:
print(" ✗ Failed to create scan directory")
exit(1)
PYTEST
if [ $? -ne 0 ]; then exit 1; fi
# Test 2: Scan directory is writable
echo "2. Testing scan directory is writable..."
python3 << 'PYTEST'
from pathlib import Path
scan_dir = Path.home() / ".prole" / "scan"
test_file = scan_dir / "test.txt"
try:
test_file.write_text("test")
test_file.unlink()
print(" ✓ Scan directory is writable")
except Exception as e:
print(f" ✗ Scan directory not writable: {e}")
exit(1)
PYTEST
if [ $? -ne 0 ]; then exit 1; fi
# Test 3: prole-scan binary exists
echo "3. Testing prole-scan binary..."
if [ -x "prole-net/prole-scan" ]; then
echo " ✓ prole-scan binary exists and is executable"
else
echo " ✗ prole-scan binary missing or not executable"
exit 1
fi
# Test 4: prole-scan can run from scan directory
echo "4. Testing prole-scan runs from writable directory..."
mkdir -p /tmp/scan-test
cd /tmp/scan-test
/Users/chrisfu/dev/prole/prole-net/prole-scan 2>&1 &
SCAN_PID=$!
sleep 2
if ps -p $SCAN_PID > /dev/null 2>&1; then
echo " ✓ prole-scan runs successfully"
kill $SCAN_PID 2>/dev/null
wait 2>/dev/null
else
echo " ✗ prole-scan failed to start"
exit 1
fi
cd /Users/chrisfu/dev/prole
# Test 5: Code uses scan directory
echo "5. Testing code uses scan directory..."
if grep -q "scan_dir = prole_home / \"scan\"" install.py && \
grep -q "cwd=str(scan_dir)" install.py; then
echo " ✓ Code properly uses scan directory"
else
echo " ✗ Code not updated to use scan directory"
exit 1
fi
# Cleanup test directories
rm -rf ~/.prole/scan 2>/dev/null
echo ""
echo "========================================"
echo " ✓ All Network Scan Fix Tests Passed"
echo "========================================"
echo ""
echo "Network scan will now work correctly:"
echo " • From source: Uses writable cwd"
echo " • From package: Uses ~/.prole/scan"
echo ""
echo "Scan directory: ~/.prole/scan"
echo "Purpose: Writable working directory for prole-scan"
echo ""