Files
splinter/tests/test_agents_ui.sh
T
lotherkandClaude Opus 5.5 a32c591572 tests: drive a tmux server of their own, never the user's
test_agents_ui.sh ran on whatever server $TMUX pointed at, so a run inside
somebody's tmux created and typed into sessions there -- keys went into the
session the person was working in. It now drops $TMUX, points TMUX_TMPDIR at
its temp dir and refuses to signal a server it did not start, the way
test_ui.sh already did. test_a2a_ui.sh gets the same guard for its
kill-server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 21:21:55 +00:00

102 lines
4.0 KiB
Bash

#!/bin/sh
#
# splinter -- Tab switches the agent profile; plan cannot run commands.
set -u
cd "$(dirname "$0")/.." || exit 1
command -v tmux >/dev/null 2>&1 || { echo "test_agents_ui: skipped (no tmux)"; exit 0; }
D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-ag-XXXXXX") || exit 1
# Our own socket, never the user's. $TMUX (set when this runs inside somebody's
# tmux) wins over TMUX_TMPDIR, so drop it and point the server at $D: a key
# this test sends can then not land in a real session, and the kill-session
# below cannot touch one.
unset TMUX TMUX_PANE
export TMUX_TMPDIR="$D"
own_server() {
if [ -n "${TMUX:-}" ] || [ "${TMUX_TMPDIR:-}" != "$D" ]; then
echo "test_agents_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; }
P=$((20000 + $$ % 30000))
S=sp-agents-$$
F=
trap 'killserver; kill $F 2>/dev/null; rm -rf "$D"' EXIT
fails=0
check() { d=$1; shift; if "$@"; then :; else echo "FAIL $d"; fails=$((fails + 1)); fi; }
shows() {
for i in $(seq 1 40); do
tmux capture-pane -t $S -p | grep -q -- "$1" && return 0
sleep 0.25
done
return 1
}
mkdir -p "$D/home/.splinter/agents" "$D/proj"
printf -- '---\ndescription: only reads\ntools: read\n---\nBe careful.\n' \
> "$D/home/.splinter/agents/careful.md"
python3 -I tests/fake_openai_tool.py "$P" "$D/made" &
F=$!
for i in $(seq 1 50); do
curl -s -o /dev/null "http://127.0.0.1:$P/x" && break
sleep 0.2
done
# --agent-list names the profiles and where a file came from
HOME="$D/home" ./splinter --no-config --agent-list </dev/null > "$D/list.txt" 2>&1
check "build is listed" grep -q '^build ' "$D/list.txt"
check "plan is listed read-only" grep -q '^plan .*read-only' "$D/list.txt"
check "a file profile is listed" grep -q '^careful ' "$D/list.txt"
tmux new-session -d -s $S -x 120 -y 30 -c "$D/proj" \
"HOME=$D/home SPLINTER_LOCALE=en SPLINTER_USAGE_DIR=$D/u SPLINTER_COOLDOWN_DIR=$D/c \
$PWD/splinter --no-config --endpoint http://127.0.0.1:$P/v1/chat/completions \
--model m --chat 2>/dev/null"
check "starts as build" shows '^build>'
tmux send-keys -t $S Tab
check "Tab goes to plan" shows 'agent: plan'
tmux send-keys -t $S Tab
check "Tab goes on to a file profile" shows 'agent: careful'
tmux send-keys -t $S Tab
check "and wraps to build" shows '^build>'
tmux send-keys -t $S BTab
check "Shift-Tab goes back" shows 'agent: careful'
tmux send-keys -t $S BTab
check "back to plan" shows 'agent: plan'
# in plan, the command is refused with the reason; nothing is created
tmux send-keys -t $S -l 'mach etwas'
tmux send-keys -t $S Enter
check "plan refuses the command" shows "not available in the 'plan' agent"
check "nothing was created" test ! -e "$D/made"
# in build the same request goes through (autonomous is off, so it asks)
tmux send-keys -t $S Tab
tmux send-keys -t $S Tab
sleep 1
tmux send-keys -t $S -l 'nochmal'
tmux send-keys -t $S Enter
check "build asks for consent" shows 'y/n\|allow\|approve\|Allow\|Approve'
# the language follows LANG (de_DE -> de), and no catalogue key shows through.
# A fresh session name: reusing one right after kill-session races, and a lost
# keystroke looked like a rendering bug.
tmux kill-session -t $S 2>/dev/null
S=sp-agents-de-$$
tmux new-session -d -s $S -x 120 -y 30 -c "$D/proj" \
"env -u SPLINTER_LOCALE LANG=de_DE.UTF-8 HOME=$D/home SPLINTER_USAGE_DIR=$D/u \
SPLINTER_COOLDOWN_DIR=$D/c $PWD/splinter --no-config \
--endpoint http://127.0.0.1:$P/v1/chat/completions --model m --chat 2>/dev/null"
check "German UI from LANG=de_DE" shows 'bereit'
# an asterisk in code is an asterisk; real emphasis loses its markers
tmux send-keys -t $S -l 'pointers bitte'
tmux send-keys -t $S Enter
check "pointers keep their asterisks" shows 'void \*ctx, const char \*name'
check "bold loses its markers" shows -- '-- bold and it'
check "no raw catalogue keys on the screen" sh -c \
"! tmux capture-pane -t $S -p | grep -Eq '(^|[ >])(ui|sidebar|status|widget|agent|usage|role)\.[a-z_]+'"
if [ "$fails" -eq 0 ]; then echo "test_agents_ui: ok"; exit 0; fi
tmux capture-pane -t $S -p | tail -15
exit 1