#!/bin/sh # splinter -- the `ask` tool's dialog on the screen. # # What it guards: the model asks a question and the turn PARKED. The whole # point of the tool is that the answer is the operator's, so the test checks # both shapes -- an option taken from the list, and a line typed that matches # no option -- and that the answer really reaches the model, because a dialog # that draws and then answers nothing is the bug this test exists for. # # The fake endpoint asks once and then echoes what the tool returned. set -u cd "$(dirname "$0")/.." || exit 1 . tests/sh/port.sh SP=${SPLINTER:-./splinter} D=$(mktemp -d "${TMPDIR:-/tmp}/uia-XXXXXX") || exit 1 S=uia-$$ # Our own tmux server: $TMUX wins over -L and TMUX_TMPDIR, so a run started # inside the user's tmux would drive the user's server and the kill at the end # would take every session in it down (see tests/test_ui.sh). unset TMUX TMUX_PANE TMUX_TMPDIR="$D" export TMUX_TMPDIR trap 'tmux kill-server 2>/dev/null; [ -n "${F:-}" ] && kill $F 2>/dev/null; rm -rf "$D"' EXIT P=$(free_port) python3 tests/fake_openai_ask.py "$P" "green,blue,red" > "$D/fake.out" 2>&1 & F=$! wait_listen "$P" "$F" || { echo "FAIL fake did not start"; cat "$D/fake.out"; exit 1; } mkdir -p "$D/home" tmux new-session -d -s $S -x 100 -y 32 "HOME=$D/home SPLINTER_LOCALE=en \ SPLINTER_SESSION_DIR=$D/home/.splinter $SP --no-config \ --endpoint http://127.0.0.1:$P/v1/chat/completions --model m --chat" || exit 1 # the ready entry is drawn before the input line owns the keyboard for i in $(seq 1 40); do tmux capture-pane -t $S -p | grep -q 'Enter sends' && break sleep 0.3 done fail=0 check() { # $1 = what, then grep patterns _w=$1; shift for _p in "$@"; do if ! tmux capture-pane -t $S -p | grep -qF -- "$_p"; then echo "FAIL $_w: no '$_p'" sed -n '1,32p' /dev/null fail=1 fi done } check_shows() { check "$1" "$2"; } typed() { sleep 0.4; tmux send-keys -t $S -l "$1"; } key() { tmux send-keys -t $S "$@"; } sleep 2 typed 'farbe'; key Enter # the question and its options must be on the screen for i in $(seq 1 30); do tmux capture-pane -t $S -p | grep -qF 'Which colour' && break sleep 0.3 done check 'dialog shows the question' 'Which colour should the login page be?' check 'dialog shows an option' 'green' check 'dialog shows the title' 'the model asks' check 'dialog shows a hint' 'Enter' # pick the second row key Down; sleep 0.2; key Enter for i in $(seq 1 40); do tmux capture-pane -t $S -p | grep -qF 'answer was:' && break sleep 0.3 done check 'the picked option reached the model' 'answer was: blue' # the second turn: type an answer that is no option typed 'nochmal'; key Enter for i in $(seq 1 30); do tmux capture-pane -t $S -p | grep -qF 'Which colour' && break sleep 0.3 done typed 'purple' sleep 0.3 key Enter for i in $(seq 1 40); do tmux capture-pane -t $S -p | grep -qF 'answer was: purple' && break sleep 0.3 done check 'the typed answer reached the model' 'answer was: purple' key C-u C-d sleep 0.5 [ "$fail" -eq 0 ] && echo "test_ask_ui: ok" [ -n "${VERBOSE:-}" ] && tmux capture-pane -t $S -p | tail -32 [ "$fail" -eq 0 ] || { tmux capture-pane -t $S -p | tail -32; exit 1; }