#!/usr/bin/env bash # This file is part of agent686 # Copyright (C) 2026 Salmonik # SPDX-License-Identifier: GPL-3.0-or-later # https://git.2137697.xyz/agent686 # Drives the editor on a real terminal (tmux) and checks the things byte-level # tests cannot see: that a multi-line prompt is drawn where it belongs, and that # moving the caret inside it does not erase the output above. set -uo pipefail here=$(cd "$(dirname "$0")/.." && pwd) port=${PORT:-8791} session=agent686-ux work=$(mktemp -d) mock_pid= fail=0 cleanup() { tmux kill-session -t "$session" 2>/dev/null [ -n "$mock_pid" ] && kill "$mock_pid" 2>/dev/null rm -rf "$work" } trap cleanup EXIT fail_msg() { echo "FAIL: $*" >&2 fail=1 } python3 "$here/scripts/mock-provider.py" --port "$port" --quiet --delay 0 >/dev/null 2>&1 & mock_pid=$! sleep 0.6 tmux kill-session -t "$session" 2>/dev/null tmux new-session -d -s "$session" -x 80 -y 24 tmux send-keys -t "$session" \ "clear; cd $work && AGENT686_DATA=$work/.data OPENCODE_API_KEY=test \ $here/target/debug/agent686 --yolo --base-url http://127.0.0.1:$port/v1" Enter sleep 1.5 # One turn so there is output above the prompt that must survive. tmux send-keys -t "$session" "hi" Enter sleep 1.2 screen=$(tmux capture-pane -p -t "$session") echo "$screen" | grep -q "Hello from the mock provider" || fail_msg "the turn produced no answer" grep_line=$(echo "$screen" | grep -n "Hello from the mock provider" | head -1 | cut -d: -f1) # Two-line prompt, no trailing newline. printf 'line one\nline two' | tmux load-buffer -b uxcheck - tmux paste-buffer -p -b uxcheck -t "$session" sleep 0.5 paste_y=$(tmux display-message -p -t "$session" '#{cursor_y}') tmux send-keys -t "$session" Home sleep 0.4 home_y=$(tmux display-message -p -t "$session" '#{cursor_y}') [ "$home_y" -eq $((paste_y - 1)) ] || fail_msg "Home put the caret on row $home_y, expected $((paste_y - 1))" tmux send-keys -t "$session" Right sleep 0.4 right_y=$(tmux display-message -p -t "$session" '#{cursor_y}') [ "$right_y" -eq "$home_y" ] || fail_msg "Right moved the caret to row $right_y, expected $home_y" screen=$(tmux capture-pane -p -t "$session") if ! echo "$screen" | grep -q "Hello from the mock provider"; then fail_msg "moving the caret inside a two-line prompt erased the output above it" fi if ! echo "$screen" | grep -q "line two"; then fail_msg "the second prompt line disappeared" fi if ! echo "$screen" | grep -q "^> line one"; then fail_msg "the first prompt line is not drawn with its prompt" fi # Submitting must not duplicate the block or leave the answer mid-line. tmux send-keys -t "$session" Enter sleep 1.0 screen=$(tmux capture-pane -p -t "$session") [ "$(echo "$screen" | grep -c '^line two$')" -eq 1 ] \ || fail_msg "the submitted prompt should appear exactly once" if echo "$screen" | grep -q 'line two.*Hello from the mock'; then fail_msg "the answer was written on the same line as the prompt" fi # Resizing while typing must not duplicate the prompt or erase what is above it. printf 'ZEBRA alpha beta gamma delta epsilon zeta eta theta iota kappa lambda mu' \ | tmux load-buffer -b uxresize - tmux paste-buffer -p -b uxresize -t "$session" sleep 0.5 tmux resize-window -t "$session" -x 40 -y 24 sleep 0.6 screen=$(tmux capture-pane -p -t "$session") [ "$(echo "$screen" | grep -c ZEBRA)" -eq 1 ] \ || fail_msg "resizing to 40 columns duplicated the prompt" echo "$screen" | grep -q "Hello from the mock provider" \ || fail_msg "resizing erased the output above the prompt" # Typing after the resize must redraw in the right place. tmux send-keys -t "$session" End sleep 0.3 tmux send-keys -t "$session" -l "!" sleep 0.4 screen=$(tmux capture-pane -p -t "$session") [ "$(echo "$screen" | grep -c ZEBRA)" -eq 1 ] \ || fail_msg "redrawing after a resize duplicated the prompt" echo "$screen" | grep -q "Hello from the mock provider" \ || fail_msg "redrawing after a resize erased output above" if [ "$fail" -ne 0 ]; then echo "--- final screen ---" >&2 echo "$screen" >&2 exit 1 fi echo "ux-check: ok (two-line prompt, caret movement, output above intact)"