#!/bin/bash
# Run the Rocinante comparison test inside the miku-bot container
# (which has aiohttp, docker access, and network connectivity to Cat)
set -e

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
TEST_FILE="$SCRIPT_DIR/test_rocinante_comparison.py"
CONTAINER="miku-bot"
LOG_FILE="/tmp/test_rocinante_comparison.log"

echo "=== Rocinante-X 12B Comparison Test ==="
echo ""

# 1. Copy test script into the container
echo "[1/4] Copying test script into $CONTAINER..."
docker cp "$TEST_FILE" "$CONTAINER:/tmp/test_rocinante_comparison.py"

# 2. Restart llama-swap-amd to pick up the new rocinante config
echo "[2/4] Restarting llama-swap-amd to load new config..."
docker restart llama-swap-amd
echo "  Waiting 10s for llama-swap-amd to be ready..."
sleep 10

# 3. Run the test inside the container (interactive for live output)
echo "[3/4] Running test inside $CONTAINER (this will take a while)..."
echo ""
docker exec -t "$CONTAINER" python3 /tmp/test_rocinante_comparison.py

# 4. Copy log back to host
echo ""
echo "[4/4] Copying log file to host..."
docker cp "$CONTAINER:$LOG_FILE" "$LOG_FILE"

echo ""
echo "✓ Done! Log file: $LOG_FILE"
echo "  Compare with: diff <(cat /tmp/test_comparison_live.log) <(cat $LOG_FILE)"
