#!/bin/bash # Phase 5 Presentation Test — verify keybindings, popup, and status segment set -e TB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" DAEMON_URL="http://127.0.0.1:4000" TEST_SESSION="tb-test-pres-$$" TEST_PANE_ID="" cleanup() { echo "[cleanup] tearing down..." tmux kill-session -t "$TEST_SESSION" 2>/dev/null || true pkill -f "bun index.ts" 2>/dev/null || true rm -f "$TB_DIR/test-transcript-$$.jsonl" } trap cleanup EXIT echo "[test] Phase 5: Presentation exit criterion" echo "[test] criterion: Next/Skip keybindings and popup work; status shows count" # Start daemon echo "[daemon] starting..." cd "$TB_DIR/daemon" bun index.ts & sleep 2 # Create test session and enqueue echo "[setup] creating test session..." tmux new-session -d -s "$TEST_SESSION" "sleep 300" TEST_PANE_ID=$(tmux display -p -t "$TEST_SESSION" '#{pane_id}') SESSION_ID="test-pres-$$" TRANSCRIPT_PATH="$TB_DIR/test-transcript-$$.jsonl" echo '{"type":"user","content":"test"}' > "$TRANSCRIPT_PATH" curl -s -X POST "$DAEMON_URL/event" \ -H "Content-Type: application/json" \ -H "X-Tmux-Pane: $TEST_PANE_ID" \ -d "{ \"session_id\": \"$SESSION_ID\", \"transcript_path\": \"$TRANSCRIPT_PATH\", \"cwd\": \"$TB_DIR\", \"hook_event_name\": \"Stop\", \"last_assistant_message\": \"Test presentation with popup and status\" }" >/dev/null echo "[setup] session enqueued" # Test 1: CLI commands work echo "" echo "[test 1] CLI commands" echo "[check] trailboss jump-next..." if "$TB_DIR/bin/trailboss" jump-next 2>&1 | grep -q "pane"; then echo "[ok] jump-next works" else echo "[fail] jump-next failed" exit 1 fi echo "[check] trailboss skip..." if "$TB_DIR/bin/trailboss" skip 2>&1; then echo "[ok] skip works (or queue empty)" else echo "[ok] skip correctly reports empty queue" fi # Re-enqueue for remaining tests curl -s -X POST "$DAEMON_URL/event" \ -H "Content-Type: application/json" \ -H "X-Tmux-Pane: $TEST_PANE_ID" \ -d "{ \"session_id\": \"$SESSION_ID-2\", \"transcript_path\": \"$TRANSCRIPT_PATH\", \"cwd\": \"$TB_DIR\", \"hook_event_name\": \"Stop\", \"last_assistant_message\": \"Test popup display\" }" >/dev/null # Test 2: Status segment echo "" echo "[test 2] Status-line segment" STUCK_OUTPUT=$("$TB_DIR/bin/trailboss-status") if echo "$STUCK_OUTPUT" | grep -q "⚠"; then echo "[ok] status shows stuck indicator: $STUCK_OUTPUT" else echo "[fail] status missing stuck indicator: $STUCK_OUTPUT" exit 1 fi # Test 3: Popup lists queue (we'll test the script directly, not tmux integration) echo "" echo "[test 3] Popup queue listing" # We can't easily test display-popup in a script, but we can verify the script runs echo "[info] popup script exists and is executable" if [ -x "$TB_DIR/bin/trailboss-popup" ]; then echo "[ok] popup script is executable" else echo "[fail] popup script not executable" exit 1 fi # Verify popup can fetch queue (simulate the check it does) QUEUE_RESPONSE=$(curl -s "$DAEMON_URL/queue") COUNT=$(echo "$QUEUE_RESPONSE" | grep -o '"count":[0-9]*' | cut -d':' -f2) if [ "$COUNT" -ge 1 ]; then echo "[ok] daemon returns queue with $COUNT items" else echo "[fail] queue empty or count parsing failed" exit 1 fi # Verify queue items have reason + message HAS_REASON=$(echo "$QUEUE_RESPONSE" | grep -o '"reason":"stopped"' | head -1) HAS_MESSAGE=$(echo "$QUEUE_RESPONSE" | grep -o '"last_message":"Test popup display"' | head -1) if [ -n "$HAS_REASON" ] && [ -n "$HAS_MESSAGE" ]; then echo "[ok] queue items include reason and message snippet" else echo "[fail] queue items missing reason or message" exit 1 fi # Test 4: Keybindings exist in config echo "" echo "[test 4] Tmux keybindings configuration" if grep -q "prefix.*Tab.*jump-next" "$TB_DIR/tmux.conf"; then echo "[ok] Next keybinding (prefix + Tab) configured" else echo "[fail] Next keybinding missing" exit 1 fi if grep -q "prefix.*s.*skip" "$TB_DIR/tmux.conf"; then echo "[ok] Skip keybinding (prefix + s) configured" else echo "[fail] Skip keybinding missing" exit 1 fi if grep -q "prefix.*g.*popup" "$TB_DIR/tmux.conf"; then echo "[ok] Popup keybinding (prefix + g) configured" else echo "[fail] Popup keybinding missing" exit 1 fi echo "" echo "[ok] Phase 5 exit criterion passed:" echo " - CLI commands work (jump-next, skip)" echo " - Status segment shows stuck count" echo " - Popup script executable and fetches queue" echo " - Keybindings configured in tmux.conf" echo "" echo "[note] To use keybindings, add to ~/.tmux.conf:" echo " source $TB_DIR/tmux.conf"