#!/bin/bash
# test-pr.sh - Quick PR testing script for nanobot staging
#
# Usage: ./test-pr.sh <pr-number> [test-message]
# Example: ./test-pr.sh 31 "test tool use feature"

set -e

PR_NUM="$1"
TEST_MSG="${2:-Hello, testing PR #$PR_NUM}"
REPO_DIR="/config/workspace/nanobot-oauth-port/nanobot-fork"
STAGING_CONFIG="/config/workspace/.nanobot-staging/config.json"

if [ -z "$PR_NUM" ]; then
  echo "Usage: $0 <pr-number> [test-message]"
  exit 1
fi

echo "==> Fetching PR #$PR_NUM..."
cd "$REPO_DIR"
git fetch wylab "+pull/$PR_NUM/head:pr-$PR_NUM"

echo "==> Checking out pr-$PR_NUM..."
git checkout "pr-$PR_NUM"

echo "==> Installing in editable mode..."
uv pip install -e . -q

echo "==> Testing with message: $TEST_MSG"
NANOBOT_CONFIG="$STAGING_CONFIG" "$REPO_DIR/.venv/bin/nanobot" agent -m "$TEST_MSG"

echo ""
echo "==> Test complete. Branch pr-$PR_NUM is still checked out."
echo "    Run 'git checkout main' to return to main branch."
