#!/bin/bash
# Run all VHS e2e tests

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
cd "$REPO_ROOT"

echo "Running lazygitclj VHS e2e tests..."
echo "================================="

# List of test tapes (relative to repo root)
TESTS=(
    "test/e2e/navigation.tape"
    "test/e2e/cursor-navigation.tape"
    "test/e2e/staging.tape"
    "test/e2e/commit.tape"
    "test/e2e/commit-verify.tape"
    "test/e2e/branches.tape"
    "test/e2e/branch-operations.tape"
    "test/e2e/branches-tabs.tape"
    "test/e2e/commits-tabs.tape"
    "test/e2e/stash-operations.tape"
    "test/e2e/stash-menu.tape"
    "test/e2e/help-panel.tape"
    "test/e2e/reset-menu.tape"
    "test/e2e/undo-redo.tape"
)

PASSED=0
FAILED=0

for tape in "${TESTS[@]}"; do
    echo ""
    echo "Running: $tape"
    echo "---"

    if timeout 60 vhs "$tape" 2>&1; then
        echo "PASSED: $tape"
        ((PASSED++))
    else
        echo "FAILED: $tape"
        ((FAILED++))
    fi
done

echo ""
echo "================================="
echo "Results: $PASSED passed, $FAILED failed"
echo "================================="

if [ $FAILED -gt 0 ]; then
    exit 1
fi
