#!/bin/bash # Validation script for Homelab Action Queue System set -e BASE_DIR=$(pwd) export HOMELAB_WORLD_ROOT="$BASE_DIR/tmp/homelab/world" export HOMELAB_ACTIONS_ROOT="$BASE_DIR/tmp/homelab/actions" EVENT_LOG="/tmp/agent-events.log" echo "=== Starting Action Queue Validation ===" # 1. Setup drift scenarios echo "Setting up drift scenarios..." bash scripts/supervisor/test_scenarios.sh # 2. Run supervisor to generate action proposals echo "Running supervisor..." python3 scripts/supervisor/supervisor.py # 3. Check for pending actions echo "Checking pending actions..." ls -l "$HOMELAB_ACTIONS_ROOT/pending/" # Get an action ID from pending ACTION_FILE=$(ls "$HOMELAB_ACTIONS_ROOT/pending/" | head -n 1) if [ -z "$ACTION_FILE" ]; then echo "Error: No pending actions found!" exit 1 fi ACTION_ID="${ACTION_FILE%.json}" echo "Found action: $ACTION_ID" # 4. Approve the action echo "Approving action $ACTION_ID..." python3 scripts/executor/executor.py approve "$ACTION_ID" # 5. Run executor echo "Running executor..." python3 scripts/executor/executor.py run # 6. Verify completion if [ -f "$HOMELAB_ACTIONS_ROOT/completed/$ACTION_FILE" ]; then echo "SUCCESS: Action $ACTION_ID moved to completed." else echo "FAILURE: Action $ACTION_ID NOT found in completed." exit 1 fi # 7. Test rejection echo "Testing rejection..." NEXT_ACTION_FILE=$(ls "$HOMELAB_ACTIONS_ROOT/pending/" | head -n 1) if [ -n "$NEXT_ACTION_FILE" ]; then NEXT_ACTION_ID="${NEXT_ACTION_FILE%.json}" echo "Rejecting action $NEXT_ACTION_ID..." python3 scripts/executor/executor.py reject "$NEXT_ACTION_ID" if [ -f "$HOMELAB_ACTIONS_ROOT/rejected/$NEXT_ACTION_FILE" ]; then echo "SUCCESS: Action $NEXT_ACTION_ID moved to rejected." else echo "FAILURE: Action $NEXT_ACTION_ID NOT found in rejected." exit 1 fi fi # 8. Verify events echo "Verifying events in $EVENT_LOG..." grep "action_created" "$EVENT_LOG" | tail -n 1 grep "action_approved" "$EVENT_LOG" | tail -n 1 grep "action_started" "$EVENT_LOG" | tail -n 1 grep "action_completed" "$EVENT_LOG" | tail -n 1 grep "action_rejected" "$EVENT_LOG" | tail -n 1 echo "=== Validation Complete ==="