The /sessions rows and the /model rows share one list struct, and the list was
sized with SP_MODEL_CHOICES (96) because /model was its first user. The session
side answers with up to 100 rows (FOREIGN_ROW_MAX in foreignopen.c, the v[100]
in sp_session_list's callers), so the source line said "claude (100)" while the
last four rows were dropped by pick_add without a word. SP_PICK_ROWS (128)
sizes the list on its own.
Evidence: tests/test_ui.sh builds a directory with 100 sessions, filters to the
oldest one and expects its row. With SP_PICK_ROWS 96 the check FAILs
("FAIL shows sess-1795000001-1-1"), with 128 it passes. make check: all tests
passed.
310 lines
11 KiB
Bash
Executable File
310 lines
11 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
|
|
. "$(dirname "$0")/sh/port.sh"
|
|
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
|
|
SPLINTER_SESSION_DIR="$D/home/.splinter"
|
|
export SPLINTER_SESSION_DIR
|
|
# 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
|
|
}
|
|
not_shows() { # the screen must never show $1 - the model's JSON is not the reader's business
|
|
if tmux capture-pane -t $S -p | grep -q -- "$1"; then
|
|
echo "screen shows: $(tmux capture-pane -t $S -p | grep -- "$1" | head -1)"
|
|
return 1
|
|
fi
|
|
return 0
|
|
}
|
|
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 ($2: retry wait in ms)
|
|
[ -n "$F" ] && kill "$F" 2>/dev/null
|
|
killserver
|
|
P=$(free_port)
|
|
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
|
|
RW=${2:+SPLINTER_RETRY_WAIT_MS=$2}
|
|
tmux new-session -d -s $S -x 110 -y 30 "HOME=$D/home SPLINTER_LOCALE=en \
|
|
$RW SPLINTER_CTX_MAX=131072 \
|
|
./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'
|
|
# in tmux the window and pane say which tree this chat belongs to
|
|
check test "$(tmux display-message -p -t $S '#{window_name}')" = \
|
|
"S: splinter"
|
|
check test "$(tmux display-message -p -t $S '#{pane_title}')" = \
|
|
"S: splinter"
|
|
# the ready entry is drawn before ui_read_line() owns the keyboard; a
|
|
# byte typed in that window can be lost
|
|
sleep 1
|
|
}
|
|
typed() { sleep 0.3; 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'
|
|
# /model alone opens the picker: it lists the providers, typing filters,
|
|
# Enter takes the highlighted one and runs the ordinary /model <id>
|
|
typed '/model'; key Enter
|
|
check shows 'type to filter'
|
|
check shows 'local/m'
|
|
typed 'local/'; key Enter
|
|
check shows 'Model: m (provider local'
|
|
# an argument still switches directly, without the picker
|
|
typed '/model andere'; key Enter
|
|
check shows 'Model: andere (provider local'
|
|
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'
|
|
# the question names the call - verb, path, class - and never the arguments
|
|
# as the model sent them ("write /tmp/x/out.txt", not write {"path": ...})
|
|
check shows 'write '
|
|
check not_shows '{"path"'
|
|
key y
|
|
check shows 'fertig'
|
|
check shows '>> write '
|
|
# the status bar above the prompt: context gauge, cache share, speed
|
|
check shows 'ctx 1290/131072'
|
|
check shows 'cache 62%'
|
|
check shows 'tok/s'
|
|
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 '^build> halb'
|
|
key BSpace BSpace
|
|
check shows '^build> ha *$' # the backspaces arrived
|
|
key C-l; sleep 1
|
|
check shows '^build> ha *$'
|
|
# Ctrl-A and Ctrl-E move the caret, not only the text: a prompt that only
|
|
# appends makes you retype a sentence to fix its first word. The keys are
|
|
# checked mid-text, where appending shows up as a wrong string.
|
|
key C-a; typed 'x'; check shows '^build> xha *$'
|
|
key C-e; typed 'y'; check shows '^build> xhay *$'
|
|
key C-a C-f; key BSpace; check shows '^build> hay *$'
|
|
key C-a C-k; check shows '^build> *$'
|
|
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 '^build>'
|
|
check test "$(quit_code)" = 0
|
|
|
|
# ---- an API failure is a status row, then a retry ----
|
|
start 1 100
|
|
typed 'bitte wiederholen'; key Enter
|
|
check shows 'retrying in'
|
|
check shows 'antwort nach dem retry'
|
|
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
|
|
|
|
# ---- Ctrl-C during a running request ----
|
|
# The cli transport had no way to stop its child: Ctrl-C set the flag, the
|
|
# worker stayed in popen(), and the join froze the screen until the program
|
|
# finished by itself. The prompt must come back within a couple of seconds.
|
|
[ -n "$F" ] && kill "$F" 2>/dev/null
|
|
F=
|
|
killserver
|
|
rm -f "$D/rc"
|
|
tmux new-session -d -s $S -x 110 -y 30 "HOME=$D/home SPLINTER_LOCALE=en \
|
|
SPLINTER_CLI_CMD='sleep 60' ./splinter --no-config --transport cli \
|
|
--plugin plugins/cli/cli.so --chat 2>/dev/null; echo \$? > $D/rc"
|
|
check shows 'Enter sends'
|
|
sleep 1
|
|
typed 'tu was'; key Enter
|
|
check shows 'steer>'
|
|
# the elapsed seconds are the first meter in the status bar, not part of
|
|
# the prompt; the prompt line is only "steer> " and what was typed
|
|
check shows 's | ctx'
|
|
# the steering line takes the same editing keys as the prompt (Ctrl-A/E,
|
|
# Left, Delete); it used to append every key, so a typo mid-sentence meant
|
|
# cancelling the turn to fix it
|
|
typed 'eins zwei'
|
|
key C-a; typed 'A'
|
|
check shows 'steer> Aeins zwei'
|
|
key C-e; typed 'Z'
|
|
check shows 'steer> Aeins zweiZ'
|
|
key C-a C-e C-u
|
|
check shows '^steer> *$'
|
|
sleep 0.5
|
|
key C-c
|
|
check shows 'cancelled'
|
|
check shows '^build>'
|
|
check test "$(quit_code)" = 0
|
|
|
|
# ---- sessions in the local UI ----
|
|
# /open used to answer "needs --attach". The engine can switch in process too:
|
|
# list the directory, open a fresh session (clear the pane), then go back to the
|
|
# first one and get its transcript again.
|
|
start 2
|
|
typed 'single word ok'; key Enter
|
|
check shows '<m> ok'
|
|
old=$(basename "$(ls "$D/home/.splinter/"*.jsonl | head -1)" .jsonl)
|
|
# /sessions is a picker, not a printout: the sources first (this folder is
|
|
# always one), Enter opens that source's rows, Enter again opens the session,
|
|
# Esc steps back and a second Esc cancels.
|
|
typed '/sessions'; key Enter
|
|
check shows 'sessions: source'
|
|
check shows 'Enter opens a source' # the picker is open, not just drawn
|
|
key Enter
|
|
check shows 'Enter opens the session'
|
|
check shows "$old"
|
|
check shows 'single word ok' # the first user line is the title
|
|
key Escape # back to the sources
|
|
sleep 0.3
|
|
key Escape # and out
|
|
sleep 0.5
|
|
check not_shows 'Enter opens the session'
|
|
typed '/rename Lokale Sitzung'; key Enter
|
|
check shows 'Lokale Sitzung'
|
|
typed '/sessions'; key Enter
|
|
check shows 'Enter opens a source'
|
|
key Enter
|
|
check shows 'Enter opens the session'
|
|
check shows 'Lokale Sitzung'
|
|
key Escape; sleep 0.3; key Escape
|
|
sleep 0.5
|
|
check not_shows 'Enter opens the session'
|
|
typed '/open new'; key Enter
|
|
check shows 'session opened'
|
|
sleep 1
|
|
check not_shows '<m> ok'
|
|
typed 'single word ok'; key Enter
|
|
check shows '<m> ok'
|
|
new=$(ls "$D/home/.splinter/"*.jsonl | xargs -n1 basename | \
|
|
sed 's/\.jsonl$//' | grep -v "^$old$" | head -1)
|
|
check test -n "$new"
|
|
typed "/open $old"; key Enter
|
|
check shows 'session opened'
|
|
check shows '<m> ok'
|
|
sleep 1
|
|
typed "/rm $new"; key Enter
|
|
check shows 'removed'
|
|
check test ! -e "$D/home/.splinter/$new.jsonl"
|
|
check test "$(quit_code)" = 0
|
|
|
|
# ---- scrolling: reaching the top must not break PgDn ----
|
|
# The old keep-position check compared maxscroll with the first visible line;
|
|
# at the top that line was 0, so every later frame added the whole scrollback
|
|
# again and one PgDn jumped straight back. PgDn after the top must move down.
|
|
start 3
|
|
typed 'viele zeilen'; key Enter
|
|
check shows 'Zeile 120'
|
|
for i in $(seq 1 30); do key PPage; done
|
|
sleep 1
|
|
check shows 'ready. Enter sends' # at the very top
|
|
key NPage
|
|
sleep 1
|
|
check not_shows 'ready. Enter sends' # and PgDn leaves it again
|
|
check test "$(quit_code)" = 0
|
|
|
|
# ---- the picker holds every row the backend lists ----
|
|
# The session side can answer with 100 rows (sp_session_list's cap). The picker
|
|
# used to size its list with SP_MODEL_CHOICES (96, /model's cap), so a source
|
|
# that said "100" had four rows nobody could reach - pick_add dropped them
|
|
# silently. 99 files plus this run's own session is exactly 100, and the one
|
|
# with the oldest mtime sorts last: it is the row the cap would have cut.
|
|
start 4
|
|
typed 'single word ok'; key Enter
|
|
check shows '<m> ok'
|
|
for i in $(seq 1 99); do
|
|
printf '{"role":"user","text":"session %s"}\n' "$i" \
|
|
> "$D/home/.splinter/sess-17940000$(printf %02d "$i")-1-1.jsonl"
|
|
done
|
|
printf '{"role":"user","text":"die aelteste zeile"}\n' \
|
|
> "$D/home/.splinter/sess-1795000001-1-1.jsonl"
|
|
touch -t 202001010000 "$D/home/.splinter/sess-1795000001-1-1.jsonl"
|
|
typed '/sessions'; key Enter
|
|
check shows 'splinter ('
|
|
key Enter
|
|
check shows 'Enter opens the session'
|
|
# the id is the selector, so filtering by it reaches exactly that row
|
|
typed '1795000001'
|
|
check shows 'sess-1795000001-1-1'
|
|
key Escape; sleep 0.3; key Escape
|
|
sleep 0.5
|
|
check test "$(quit_code)" = 0
|
|
|
|
if [ "$fails" -eq 0 ]; then echo "test_ui: ok"; exit 0; fi
|
|
exit 1
|