prole/tests/test_network_scan_fix.sh

91 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
knoe_home = Path.home() / ".knoe"
scan_dir = knoe_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() / ".knoe" / "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: network-agent binary exists
echo "3. Testing network-agent binary..."
if [ -x "scan/network-agent" ]; then
echo " ✓ network-agent binary exists and is executable"
else
echo " ✗ network-agent binary missing or not executable"
exit 1
fi
# Test 4: network-agent can run from scan directory
echo "4. Testing network-agent runs from writable directory..."
PROLE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
mkdir -p /tmp/scan-test
cd /tmp/scan-test
"$PROLE_ROOT/scan/network-agent" 2>&1 &
SCAN_PID=$!
sleep 2
if ps -p $SCAN_PID > /dev/null 2>&1; then
echo " ✓ network-agent runs successfully"
kill $SCAN_PID 2>/dev/null
wait 2>/dev/null
else
echo " ✗ network-agent failed to start"
exit 1
fi
cd "$PROLE_ROOT"
# Test 5: Code uses scan directory
echo "5. Testing code uses scan directory..."
if grep -rq "scan_dir = knoe_home / \"scan\"" knoe/ && \
grep -rq "cwd=str(scan_dir)" knoe/; then
echo " ✓ Code properly uses scan directory"
else
echo " ✗ Code not updated to use scan directory"
exit 1
fi
# Cleanup test directories
rm -rf ~/.knoe/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 ~/.knoe/scan"
echo ""
echo "Scan directory: ~/.knoe/scan"
echo "Purpose: Writable working directory for knoe-agent"
echo ""