diff options
Diffstat (limited to 'scripts/ux-check.sh')
| -rwxr-xr-x | scripts/ux-check.sh | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/scripts/ux-check.sh b/scripts/ux-check.sh new file mode 100755 index 0000000..019f63d --- /dev/null +++ b/scripts/ux-check.sh | |||
| @@ -0,0 +1,86 @@ | |||
| 1 | #!/usr/bin/env bash | ||
| 2 | # Drives the editor on a real terminal (tmux) and checks the things byte-level | ||
| 3 | # tests cannot see: that a multi-line prompt is drawn where it belongs, and that | ||
| 4 | # moving the caret inside it does not erase the output above. | ||
| 5 | set -uo pipefail | ||
| 6 | |||
| 7 | here=$(cd "$(dirname "$0")/.." && pwd) | ||
| 8 | port=${PORT:-8791} | ||
| 9 | session=agent686-ux | ||
| 10 | work=$(mktemp -d) | ||
| 11 | mock_pid= | ||
| 12 | fail=0 | ||
| 13 | |||
| 14 | cleanup() { | ||
| 15 | tmux kill-session -t "$session" 2>/dev/null | ||
| 16 | [ -n "$mock_pid" ] && kill "$mock_pid" 2>/dev/null | ||
| 17 | rm -rf "$work" | ||
| 18 | } | ||
| 19 | trap cleanup EXIT | ||
| 20 | |||
| 21 | fail_msg() { | ||
| 22 | echo "FAIL: $*" >&2 | ||
| 23 | fail=1 | ||
| 24 | } | ||
| 25 | |||
| 26 | python3 "$here/scripts/mock-provider.py" --port "$port" --quiet --delay 0 >/dev/null 2>&1 & | ||
| 27 | mock_pid=$! | ||
| 28 | sleep 0.6 | ||
| 29 | |||
| 30 | tmux kill-session -t "$session" 2>/dev/null | ||
| 31 | tmux new-session -d -s "$session" -x 80 -y 24 | ||
| 32 | tmux send-keys -t "$session" \ | ||
| 33 | "clear; cd $work && AGENT686_DATA=$work/.data OPENCODE_API_KEY=test \ | ||
| 34 | $here/target/debug/agent686 --yolo --base-url http://127.0.0.1:$port/v1" Enter | ||
| 35 | sleep 1.5 | ||
| 36 | |||
| 37 | # One turn so there is output above the prompt that must survive. | ||
| 38 | tmux send-keys -t "$session" "hi" Enter | ||
| 39 | sleep 1.2 | ||
| 40 | screen=$(tmux capture-pane -p -t "$session") | ||
| 41 | echo "$screen" | grep -q "Hello from the mock provider" || fail_msg "the turn produced no answer" | ||
| 42 | grep_line=$(echo "$screen" | grep -n "Hello from the mock provider" | head -1 | cut -d: -f1) | ||
| 43 | |||
| 44 | # Two-line prompt, no trailing newline. | ||
| 45 | printf 'line one\nline two' | tmux load-buffer -b uxcheck - | ||
| 46 | tmux paste-buffer -p -b uxcheck -t "$session" | ||
| 47 | sleep 0.5 | ||
| 48 | paste_y=$(tmux display-message -p -t "$session" '#{cursor_y}') | ||
| 49 | |||
| 50 | tmux send-keys -t "$session" Home | ||
| 51 | sleep 0.4 | ||
| 52 | home_y=$(tmux display-message -p -t "$session" '#{cursor_y}') | ||
| 53 | [ "$home_y" -eq $((paste_y - 1)) ] || fail_msg "Home put the caret on row $home_y, expected $((paste_y - 1))" | ||
| 54 | |||
| 55 | tmux send-keys -t "$session" Right | ||
| 56 | sleep 0.4 | ||
| 57 | right_y=$(tmux display-message -p -t "$session" '#{cursor_y}') | ||
| 58 | [ "$right_y" -eq "$home_y" ] || fail_msg "Right moved the caret to row $right_y, expected $home_y" | ||
| 59 | |||
| 60 | screen=$(tmux capture-pane -p -t "$session") | ||
| 61 | if ! echo "$screen" | grep -q "Hello from the mock provider"; then | ||
| 62 | fail_msg "moving the caret inside a two-line prompt erased the output above it" | ||
| 63 | fi | ||
| 64 | if ! echo "$screen" | grep -q "line two"; then | ||
| 65 | fail_msg "the second prompt line disappeared" | ||
| 66 | fi | ||
| 67 | if ! echo "$screen" | grep -q "^> line one"; then | ||
| 68 | fail_msg "the first prompt line is not drawn with its prompt" | ||
| 69 | fi | ||
| 70 | |||
| 71 | # Submitting must not duplicate the block or leave the answer mid-line. | ||
| 72 | tmux send-keys -t "$session" Enter | ||
| 73 | sleep 1.0 | ||
| 74 | screen=$(tmux capture-pane -p -t "$session") | ||
| 75 | [ "$(echo "$screen" | grep -c '^line two$')" -eq 1 ] \ | ||
| 76 | || fail_msg "the submitted prompt should appear exactly once" | ||
| 77 | if echo "$screen" | grep -q 'line two.*Hello from the mock'; then | ||
| 78 | fail_msg "the answer was written on the same line as the prompt" | ||
| 79 | fi | ||
| 80 | |||
| 81 | if [ "$fail" -ne 0 ]; then | ||
| 82 | echo "--- final screen ---" >&2 | ||
| 83 | echo "$screen" >&2 | ||
| 84 | exit 1 | ||
| 85 | fi | ||
| 86 | echo "ux-check: ok (two-line prompt, caret movement, output above intact)" | ||
