aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/ux-check.sh
blob: 019f63d573ff01154a87af566f7f4ad4914b2c26 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
# 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

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)"