#!/bin/bash set -euo pipefail PASS=0 FAIL=0 WARN=0 TUI_LOG="/tmp/passepartout-tui-test.log" > "$TUI_LOG" cleanup() { tmux kill-session -t tui-test 2>/dev/null || true } trap cleanup EXIT run_test() { local name="$1"; shift echo -n " $name ... " if "$@" 2>/dev/null; then echo "PASS" PASS=$((PASS + 1)) else echo "FAIL" FAIL=$((FAIL + 1)) fi } # ---- Setup ---- echo "Starting TUI in tmux (daemon must already be running on port 9105)..." tmux new-session -d -s tui-test "passepartout tui 2>&1 | tee $TUI_LOG" for i in $(seq 1 40); do sleep 3 if tmux capture-pane -t tui-test -p 2>/dev/null | grep -q 'Connected v[0-9]'; then echo " TUI ready after $((i*3))s" break fi if [ "$i" -eq 40 ]; then echo " WARNING: TUI did not render after 120s" fi done # ---- Tests ---- test_agent_responds() { # Full round-trip: TUI → daemon → pipeline → TUI. # Uses tmux capture-pane to read the rendered screen. local before_ts before_ts=$(date +%s) tmux send-keys -t tui-test "hello" Enter while true; do if tmux capture-pane -t tui-test -p -S -50 2>/dev/null | grep -q '⬇.*[a-zA-Z]\{3,\}'; then return 0 fi local now_ts now_ts=$(date +%s) if (( now_ts - before_ts > 60 )); then echo "TIMEOUT: no agent response after 60s" >&2 return 1 fi sleep 2 done } test_agent_not_cascade_failure() { if tmux capture-pane -t tui-test -p -S -50 2>/dev/null | grep '⬇' | grep -qi 'cascade.*fail\|exhausted\|neural cascade'; then echo "NOTE: LLM cascade failure — no API key configured (warning only)" >&2 WARN=$((WARN + 1)) fi return 0 } test_eval_command() { tmux send-keys -t tui-test "/eval (+ 1 2)" Enter sleep 3 tmux capture-pane -t tui-test -p -S -10 2>/dev/null | grep -q '=> 3' } test_status_bar() { tmux capture-pane -t tui-test -p -S -20 2>/dev/null | grep -q 'msgs:' } test_connection_drop() { sleep 1 tmux capture-pane -t tui-test -p -S -10 2>/dev/null | grep -qi 'connection.*lost\|ERROR.*Connection\|error.*connect' || true return 0 } run_test "agent-responds" test_agent_responds run_test "agent-not-cascade-fail" test_agent_not_cascade_failure run_test "eval-command" test_eval_command run_test "status-bar" test_status_bar run_test "connection-drop" test_connection_drop # ---- Summary ---- echo "" echo "===== $PASS passed, $FAIL failed, $WARN warnings =====" exit $(( FAIL > 0 ? 1 : 0 ))