98 lines
2.2 KiB
Bash
Executable File
98 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
PASS=0
|
|
FAIL=0
|
|
TUI_LOG="/tmp/passepartout-tui-test.log"
|
|
> "$TUI_LOG"
|
|
|
|
cleanup() {
|
|
tmux kill-session -t tui-test 2>/dev/null || true
|
|
kill %1 2>/dev/null || true
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
run_test() {
|
|
local name="$1"; shift
|
|
echo -n " $name ... "
|
|
if "$@" > /dev/null 2>&1; then
|
|
echo "PASS"
|
|
PASS=$((PASS + 1))
|
|
else
|
|
echo "FAIL"
|
|
FAIL=$((FAIL + 1))
|
|
fi
|
|
}
|
|
|
|
# ---- Setup ----
|
|
echo "Starting daemon..."
|
|
passepartout daemon &
|
|
DAEMON_PID=$!
|
|
sleep 3
|
|
|
|
echo "Starting TUI in tmux..."
|
|
tmux new-session -d -s tui-test "passepartout tui 2>&1 | tee $TUI_LOG"
|
|
sleep 4
|
|
|
|
# ---- Tests ----
|
|
|
|
test_handshake() {
|
|
# The TUI receives a handshake from the daemon on connect
|
|
# and renders "Connected v<version>" in the log/chat area.
|
|
grep -q 'Connected v[0-9]' "$TUI_LOG"
|
|
}
|
|
|
|
test_agent_responds() {
|
|
# Send text to the TUI and wait for an agent (⬇) response.
|
|
# This proves the full round-trip: TUI → daemon → pipeline → TUI.
|
|
# The response may be a cascade failure message (no API key)
|
|
# or a real LLM reply — either way, ⬇ proves the daemon responded.
|
|
local before_ts
|
|
before_ts=$(date +%s)
|
|
|
|
tmux send-keys -t tui-test "hello" Enter
|
|
|
|
# Wait up to 20 seconds for ⬇ to appear
|
|
while true; do
|
|
if grep -q '⬇.*[a-zA-Z]\{3,\}' "$TUI_LOG"; then
|
|
return 0
|
|
fi
|
|
local now_ts
|
|
now_ts=$(date +%s)
|
|
if (( now_ts - before_ts > 20 )); then
|
|
echo "TIMEOUT: no agent response in log" >&2
|
|
return 1
|
|
fi
|
|
sleep 1
|
|
done
|
|
}
|
|
|
|
test_eval_command() {
|
|
tmux send-keys -t tui-test "/eval (+ 1 2)" Enter
|
|
sleep 2
|
|
grep -q '=> 3' "$TUI_LOG"
|
|
}
|
|
|
|
test_status_bar() {
|
|
local pane
|
|
pane=$(tmux capture-pane -t tui-test -p -S -20)
|
|
echo "$pane" | grep -q 'msgs:'
|
|
}
|
|
|
|
test_connection_drop() {
|
|
kill $DAEMON_PID 2>/dev/null || true
|
|
sleep 3
|
|
grep -qi 'connection.*lost\|ERROR.*Connection' "$TUI_LOG"
|
|
}
|
|
|
|
run_test "handshake" test_handshake
|
|
run_test "agent-responds" test_agent_responds
|
|
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 ====="
|
|
exit $(( FAIL > 0 ? 1 : 0 ))
|