The `ask` tool asks and the answer -- or "nobody answered" -- becomes the observation. Read class: it changes nothing on the machine, and the authority is the operator, not a gate. Front ends: the chat draws a dialog (options to pick, typed words still count), the protocol carries it as an `ask` event and an `answer` command, MCP returns it from splinter_say and resumes with splinter_answer, the Telegram gateway sends it as a message and takes the next message from an allowed user. What the review of the WIP found, and what this fixes: - -p hung for the full 900 s ask wait: sp_engine_prompt installed engine_ask, but nobody polls events on the synchronous path. cfg.ask now stays NULL there, so the tool answers at once with "nobody can be asked here". Measured: 3 s instead of 900 s (was rc=124 after 20 s). - splinter_say over MCP hung the same way, because tool_say only looked at st.waiting. It now looks at st.asking and returns the question; the client timed out at 15 s before, and the turn was lost. - protocol.c read the question buffer uninitialized when sp_engine_ask returned 0. - turn_ask answered nothing when the window could not be opened, which parked the turn for the full wait. - pick_run computed the list height without the question's rows, so the highlighted row scrolled out of the window (reproduced: after nine Downs no ">" row was on the screen). pick_draw and pick_run now share pick_listtop(). - the Telegram gateway was dead for this tool: it runs its turns on a copy of e->base, where ask was never set, so the model was told "nobody can be asked" while the operator sat in the chat. New tg_ask, verified against a running daemon and covered in test_gateway.sh. - tests/test_ask_ui.sh was untracked and not in make check, so it never ran. A2A keeps no ask channel on purpose: there an approval pauses the task into INPUT_REQUIRED, and the ask signature cannot express a pause -- saying "nobody can be asked" is the honest answer there. Tests: make check green (327 s), including the new test_ask_mcp.sh and test_ask_ui.sh, both wired into make check. test_ask_mcp.sh was verified to fail against the unfixed code (client times out, no result written). make check-asan: 46 binaries clean. make check-tsan: 46 binaries, no races.
96 lines
3.2 KiB
Bash
Executable File
96 lines
3.2 KiB
Bash
Executable File
#!/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; }
|