This commit is contained in:
Your Name 2025-05-10 13:14:11 +12:00
parent a3914f8167
commit 4087b6e596

View File

@ -73,13 +73,15 @@ JSON=$(cat <<'EOF'
{"command":"false"} {"command":"false"}
EOF EOF
) )
BASE64=$(echo -n "$JSON" | base64) BASE64=$(echo -n "$JSON" | base64 -w0)
echo "JSON: $JSON" echo "JSON: $JSON"
echo "Running command (should fail)..." echo "Running command (should fail)..."
build/runner "$BASE64" || true set +e # Temporarily disable exiting on error
build/runner "$BASE64"
RC=$? RC=$?
set -e # Re-enable exiting on error
if [ $RC -ne 0 ]; then if [ $RC -ne 0 ]; then
echo "✅ Test 4 passed (command correctly reported failure)" echo "✅ Test 4 passed (command correctly reported failure, exit code: $RC)"
else else
echo "❌ Test 4 failed (command should have returned non-zero)" echo "❌ Test 4 failed (command should have returned non-zero)"
exit 1 exit 1
@ -92,7 +94,7 @@ JSON=$(cat <<'EOF'
{"command":"pwd","working_directory":"/tmp"} {"command":"pwd","working_directory":"/tmp"}
EOF EOF
) )
BASE64=$(echo -n "$JSON" | base64) BASE64=$(echo -n "$JSON" | base64 -w0)
echo "JSON: $JSON" echo "JSON: $JSON"
echo "Running command (should show /tmp)..." echo "Running command (should show /tmp)..."
OUTPUT=$(build/runner "$BASE64") OUTPUT=$(build/runner "$BASE64")
@ -105,10 +107,8 @@ fi
echo echo
# Optional SSH test (disabled by default) # Optional SSH test (disabled by default)
# Set ENABLE_SSH_TEST=1 to enable this test echo "Test 6: SSH to localhost (make sure SSH server is running and you can connect to localhost)"
if [ "${ENABLE_SSH_TEST}" = "1" ]; then if [ -f "examples/local_ssh.json" ]; then
echo "Test 6: SSH to localhost (make sure SSH server is running and you can connect to localhost)"
if [ -f "examples/local_ssh.json" ]; then
echo "Using examples/local_ssh.json for the test..." echo "Using examples/local_ssh.json for the test..."
./run.sh examples/local_ssh.json || { ./run.sh examples/local_ssh.json || {
echo "❌ Test 6 failed" echo "❌ Test 6 failed"
@ -117,16 +117,21 @@ if [ "${ENABLE_SSH_TEST}" = "1" ]; then
exit 1 exit 1
} }
echo "✅ Test 6 passed" echo "✅ Test 6 passed"
else else
echo "❌ Test 6 failed: examples/local_ssh.json not found" echo "❌ Test 6 failed: examples/local_ssh.json not found"
exit 1 exit 1
fi fi
echo echo
echo "Test 7: SSH with working directory (make sure SSH server is running and you can connect to localhost)" echo "Test 7: SSH with working directory (make sure SSH server is running and you can connect to localhost)"
if [ -f "examples/ssh_working_dir.json" ]; then if [ -f "examples/ssh_working_dir.json" ]; then
echo "Using examples/ssh_working_dir.json for the test..." echo "Using examples/ssh_working_dir.json for the test..."
OUTPUT=$(./run.sh examples/ssh_working_dir.json | grep "/tmp") OUTPUT=$(./run.sh examples/ssh_working_dir.json | grep "/tmp")
if [ $? -ne 0 ]; then
echo "❌ Test 7 failed, command did not run"
exit 1
fi
if [[ "$OUTPUT" == *"/tmp"* ]]; then if [[ "$OUTPUT" == *"/tmp"* ]]; then
echo "✅ Test 7 passed (SSH command ran in the correct directory)" echo "✅ Test 7 passed (SSH command ran in the correct directory)"
else else
@ -134,14 +139,10 @@ if [ "${ENABLE_SSH_TEST}" = "1" ]; then
echo "Note: This test requires SSH server running on localhost and proper key-based authentication." echo "Note: This test requires SSH server running on localhost and proper key-based authentication."
exit 1 exit 1
fi fi
else else
echo "❌ Test 7 failed: examples/ssh_working_dir.json not found" echo "❌ Test 7 failed: examples/ssh_working_dir.json not found"
exit 1 exit 1
fi
echo
else
echo "Test 6-7: SSH tests disabled (set ENABLE_SSH_TEST=1 to enable)"
echo
fi fi
echo
echo "All tests passed! 🎉" echo "All tests passed! 🎉"