#!/usr/bin/env bash set -euo pipefail # Single-run integration test for merged-repl-plugin # Usage: ./tests/run_single.sh # Requirements: bash, git, nvim (headless) available in PATH ROOT="$(cd "$(dirname "$0")/.." && pwd)" MAIN="$ROOT/test_main_repo" REPL="$ROOT/test_repl_repo" LUA_TEST="$ROOT/tests/_headless_single.lua" SYNC_OUT="$ROOT/tests/sync_result.txt" REPL_OUT="$ROOT/tests/repl_output_captured.log" TMP_CLEANUP=() fail() { echo "ERROR: $*" >&2; exit 1; } # ensure nvim not running (we'll be conservative) if pgrep -a nvim > /dev/null; then echo "Warning: nvim process found. Please close running nvim instances to avoid interference." fi echo "Preparing test repos in: $ROOT" rm -rf "$MAIN" "$REPL" "$SYNC_OUT" "$REPL_OUT" "$LUA_TEST" mkdir -p "$MAIN" "$REPL" "$ROOT/tests" # init main git -C "$MAIN" init >/dev/null 2>&1 || true if [ -z "$(git -C "$MAIN" rev-parse --verify HEAD 2>/dev/null || true)" ]; then touch "$MAIN/README" git -C "$MAIN" add README git -C "$MAIN" -c user.name='CI' -c user.email='ci@example.com' commit -m "init" >/dev/null fi # init repl git -C "$REPL" init >/dev/null 2>&1 || true if [ -z "$(git -C "$REPL" rev-parse --verify HEAD 2>/dev/null || true)" ]; then touch "$REPL/README" git -C "$REPL" add README git -C "$REPL" -c user.name='CI' -c user.email='ci@example.com' commit -m "init" >/dev/null fi # ensure template branch exists in repl git -C "$REPL" checkout -B template >/dev/null 2>&1 || true # create a simple repl.pl and commit cat > "$REPL/repl.pl" <<'EOF' print "Hello from REPL\n"; EOF git -C "$REPL" add repl.pl >/dev/null 2>&1 || true git -C "$REPL" -c user.name='CI' -c user.email='ci@example.com' commit -m "add repl" >/dev/null 2>&1 || true # headless lua script that triggers sync_once and run_repl and dumps file output to a file cat > "$LUA_TEST" <&2 exit 2 fi if ! grep -q "Hello from REPL" "$REPL/repl_output.log"; then echo "ERROR: expected REPL output missing" >&2 cat "$REPL/repl_output.log" || true exit 3 fi # verify branch mirroring (create branch in main and run sync_once again) git -C "$MAIN" checkout -B feature-single || fail "failed to create test branch in main" nvim --headless -u NONE -c "lua package.path = package.path .. ';./lua/?.lua;./lua/?/init.lua'" -c "lua require('merged-repl-plugin').setup{ main_repo_path='${MAIN}', repl_repo_path='${REPL}', repl_file='${REPL}/repl.pl', auto_start=false } require('merged-repl-plugin').sync_once()" -c "qa!" echo "=== repl branches ===" git -C "$REPL" branch --list # test auto-commit: append to repl.pl and run sync_once; then show latest commit message echo 'print "Modified for single test\\n";' >> "$REPL/repl.pl" nvim --headless -u NONE -c "lua package.path = package.path .. ';./lua/?.lua;./lua/?/init.lua'" -c "lua require('merged-repl-plugin').setup{ main_repo_path='${MAIN}', repl_repo_path='${REPL}', repl_file='${REPL}/repl.pl', auto_start=false } require('merged-repl-plugin').sync_once()" -c "qa!" echo "=== latest repl commit message ===" git -C "$REPL" log -1 --pretty=%B || true echo "Single run complete."