/new (and /reset) opens a new session file in the same directory, drops the conversation back to the system prompt and, in the gateway, resets the interview/connect state so a half-finished flow does not survive the reset. The old session file stays: it is the record of what was said. In the TUI the history pane is cleared, because it shows the old conversation. The directory is read before the static session struct is cleared, or the second /new would start from an empty path. /connect exists in the TUI now: the same four questions, one answer per line, the same validation and presets, and connect.nodir when the run has no config file to write to (--no-config). conv.c grows sp_conv_reset(), which frees every message and puts the system prompt back. test_gateway checks /new (message and a new session file); test_ui checks /new in the pane and the /connect guard with --no-config.
135 lines
4.1 KiB
Bash
Executable File
135 lines
4.1 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# splinter -- the curses UI, driven through tmux against a fake model.
|
|
#
|
|
# What it guards, as found: a tool call is asked on the screen and runs after
|
|
# 'y'; Ctrl-C during that question cancels the turn (it used to be swallowed,
|
|
# leaving y or n as the only way out); Ctrl-L repaints instead of sending the
|
|
# half-typed line; Backspace edits the buffer, not only the screen; '!' and '/'
|
|
# lines are handled; a resize does not end the program; Ctrl-D quits with 0.
|
|
# Skipped, and says so, where tmux is not installed.
|
|
set -u
|
|
cd "$(dirname "$0")/.." || exit 1
|
|
if ! command -v tmux >/dev/null 2>&1; then
|
|
echo "test_ui: skipped (no tmux)"
|
|
exit 0
|
|
fi
|
|
D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-ui-XXXXXX") || exit 1
|
|
# Our own socket, never the user's. $TMUX wins over both -L and TMUX_TMPDIR
|
|
# (tmux.c: when $TMUX is set the client takes the socket path out of it), so a
|
|
# run started from inside the user's tmux would drive the user's server -- and
|
|
# the kill-server below would take every session in it down. Drop $TMUX, keep
|
|
# TMUX_TMPDIR pointed at $D, and never signal a server this test does not own.
|
|
unset TMUX TMUX_PANE
|
|
export TMUX_TMPDIR="$D"
|
|
own_server() {
|
|
if [ -n "${TMUX:-}" ] || [ "${TMUX_TMPDIR:-}" != "$D" ]; then
|
|
echo "test_ui: refusing to touch a tmux server this test does not own" >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
killserver() { own_server; tmux kill-server 2>/dev/null; }
|
|
S=splinter-ui-$$
|
|
fails=0
|
|
F=
|
|
cleanup() {
|
|
killserver
|
|
[ -n "$F" ] && kill "$F" 2>/dev/null
|
|
rm -rf "$D"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
check() { if "$@"; then :; else echo "FAIL $*"; fails=$((fails + 1)); fi; }
|
|
shows() { # wait until the screen contains $1
|
|
for i in $(seq 1 60); do
|
|
tmux capture-pane -t $S -p | grep -q -- "$1" && return 0
|
|
sleep 0.5
|
|
done
|
|
return 1
|
|
}
|
|
done_turn() { # wait until the turn label is gone
|
|
for i in $(seq 1 60); do
|
|
tmux capture-pane -t $S -p | grep -q 'working' || return 0
|
|
sleep 0.5
|
|
done
|
|
return 1
|
|
}
|
|
start() { # a fresh fake model and a fresh UI
|
|
[ -n "$F" ] && kill "$F" 2>/dev/null
|
|
killserver
|
|
P=$((20000 + ($$ + $1) % 30000))
|
|
rm -rf "$D/home" "$D/out.txt" "$D/rc"
|
|
mkdir -p "$D/home"
|
|
python3 -I tests/fake_telegram.py "$P" "$D/out.txt" "$D/sent.log" ok \
|
|
> "$D/fake.out" 2>&1 &
|
|
F=$!
|
|
ready=0
|
|
for i in $(seq 1 100); do
|
|
curl -s -o /dev/null "http://127.0.0.1:$P/x" && { ready=1; break; }
|
|
sleep 0.2
|
|
done
|
|
if [ "$ready" -ne 1 ] || ! kill -0 "$F" 2>/dev/null; then
|
|
echo "FAIL fake telegram did not start on $P"
|
|
cat "$D/fake.out" 2>/dev/null
|
|
exit 1
|
|
fi
|
|
tmux new-session -d -s $S -x 110 -y 30 "HOME=$D/home SPLINTER_LOCALE=en \
|
|
./splinter --no-config --endpoint http://127.0.0.1:$P/v1/chat/completions \
|
|
--model m --chat 2>/dev/null; echo \$? > $D/rc"
|
|
shows 'Enter sends'
|
|
}
|
|
typed() { tmux send-keys -t $S -l "$1"; }
|
|
key() { tmux send-keys -t $S "$@"; }
|
|
quit_code() {
|
|
key C-u C-d
|
|
for i in $(seq 1 20); do [ -s "$D/rc" ] && break; sleep 0.5; done
|
|
cat "$D/rc" 2>/dev/null
|
|
}
|
|
|
|
start 0
|
|
typed '!echo hallo-shell'; key Enter
|
|
check shows 'hallo-shell'
|
|
typed '/xyz'; key Enter
|
|
check shows 'unknown command: /xyz'
|
|
typed '/model'; key Enter
|
|
check shows 'main m'
|
|
check shows 'Choose a model'
|
|
typed '/model andere'; key Enter
|
|
check shows 'Model: andere (provider main'
|
|
typed '/new'; key Enter
|
|
check shows 'New conversation: sess-'
|
|
typed '/connect'; key Enter
|
|
check shows 'No configuration directory to write to.'
|
|
typed 'schreib die datei'; key Enter
|
|
check shows 'changes files'
|
|
key y
|
|
check shows 'fertig'
|
|
check grep -q 'vom gateway' "$D/out.txt"
|
|
typed 'halb'
|
|
check shows 'halb' # let the UI consume the keys
|
|
key C-l; sleep 1
|
|
check shows '^>halb'
|
|
key BSpace BSpace
|
|
check shows '^>ha *$' # the backspaces arrived
|
|
key C-l; sleep 1
|
|
check shows '^>ha *$'
|
|
typed 'zeig eine tabelle'; key Enter
|
|
check shows '| a | b |'
|
|
check shows '|---|----|'
|
|
check shows '| 1 | 22 |'
|
|
tmux resize-window -t $S -x 70 -y 20; sleep 1
|
|
check shows '^>'
|
|
check test "$(quit_code)" = 0
|
|
|
|
start 1
|
|
typed 'schreib die datei'; key Enter
|
|
check shows 'changes files'
|
|
key C-c; sleep 2
|
|
check test ! -e "$D/out.txt"
|
|
typed '!echo noch-da'; key Enter
|
|
check shows 'noch-da'
|
|
check test "$(quit_code)" = 0
|
|
|
|
if [ "$fails" -eq 0 ]; then echo "test_ui: ok"; exit 0; fi
|
|
exit 1
|