85 lines
3.4 KiB
Bash
85 lines
3.4 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
|
|
P=$((20000 + $$ % 30000))
|
|
S=sp-agents-$$
|
|
trap 'tmux kill-session -t $S 2>/dev/null; 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 '\[plan\]'
|
|
tmux send-keys -t $S Tab
|
|
check "Tab goes on to a file profile" shows '\[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 '\[careful\]'
|
|
tmux send-keys -t $S BTab
|
|
check "back to plan" shows '\[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
|
|
tmux kill-session -t $S 2>/dev/null
|
|
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
|