#!/bin/sh # # splinter -- Tab switches the agent profile; plan cannot run commands, and # build runs them without a question in front of the tool. set -u cd "$(dirname "$0")/.." || exit 1 . "$(dirname "$0")/sh/port.sh" 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 SPLINTER_SESSION_DIR="$D/home/.splinter"; export SPLINTER_SESSION_DIR # 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=$(free_port) 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 } # a condition that becomes true a moment later. A screen check is not enough # here: the text of the refused turn is still on the pane, so "obs: " appears # before the build turn has even started. waitfor() { for i in $(seq 1 40); do "$@" && 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 "$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 - no question in front of the tool, # the profile's policy is the only thing that decides what the agent may reach 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 runs the command" waitfor test -e "$D/made" check "and the model read the observation" shows 'exit status 0' # The language is English unless a config or SPLINTER_LOCALE says otherwise; # the desktop's LANG must not change it behind the operator's back. # 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 "English UI despite LANG=de_DE" shows 'ready' # 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