The user's rule: what the config says is the default, -m overrides it for one run, /model overrides it for the running process - and nothing is written to the config or to the session. The session sidecar from the previous change made /model persistent, which is exactly the harness behaviour this rejects. - removed <session>.model writing and restoring; a reopened session starts on the config default or -m, not on the last /model choice. - /new no longer copies the current model into the new session. - Telegram's /model and probe buttons no longer write 90-model.conf; the switch lasts for the gateway process. - existing .model sidecars were moved out of ~/.splinter; the stale 90-model drop-in was moved aside earlier. - test_engine asserts that /model leaves no sidecar and that reopening uses test-model, not test-model-2; test_gateway asserts that no 90-model.conf is written. - docs: "choice lasts for this run and is not saved". Verified with the real config: default is junction/qwen3.6-35b-judged, -m junction/qwen3.6-35b uses qwen3.6-35b for that run, /model switches to claude-haiku for that run and the next start is judged again. make check: all tests passed.
218 lines
9.5 KiB
Bash
Executable File
218 lines
9.5 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# splinter -- the Telegram gateway asks for approval in its own chat.
|
|
#
|
|
# Before: a tool call that needed consent either was denied (no approval
|
|
# stream in a daemon) or waited for an "ok <id>" that only the blocked gateway
|
|
# could have read. And a refused sendMessage crashed it (NULL err). Run against
|
|
# a fake Bot API and a fake model, once with "ok" and once with "no".
|
|
set -u
|
|
cd "$(dirname "$0")/.." || exit 1
|
|
D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-gw-XXXXXX") || exit 1
|
|
SPLINTER_SESSION_DIR="$D/home/.splinter"; export SPLINTER_SESSION_DIR
|
|
trap 'rm -rf "$D"' EXIT
|
|
fails=0
|
|
|
|
wait_fake() { # $1 = port; 0 when something accepts a connection
|
|
for i in $(seq 1 100); do
|
|
curl -s -o /dev/null "http://127.0.0.1:$1/x" && return 0
|
|
sleep 0.2
|
|
done
|
|
return 1
|
|
}
|
|
|
|
run() { # $1 = answer word; leaves $D/sent.log and maybe $D/out.txt
|
|
P=$((20000 + ($$ + ${2:-0}) % 30000))
|
|
rm -rf "$D/home" "$D/out.txt" "$D/sent.log"
|
|
mkdir -p "$D/home/.splinter/commands"
|
|
printf '#!/bin/sh\necho hallo\n' > "$D/home/.splinter/commands/hello"
|
|
chmod +x "$D/home/.splinter/commands/hello"
|
|
printf 'endpoint = http://127.0.0.1:%s/v1/chat/completions\nmodel = m\ntelegram_allow = 7\nplugin = plugins/focus/focus.so\n' \
|
|
"$P" > "$D/home/splinter.conf"
|
|
python3 -I tests/fake_telegram.py "$P" "$D/out.txt" "$D/sent.log" "$1" \
|
|
> "$D/fake.out" 2>&1 &
|
|
S=$!
|
|
if ! wait_fake "$P" || ! kill -0 "$S" 2>/dev/null; then
|
|
echo "FAIL fake telegram did not start on $P"
|
|
cat "$D/fake.out" 2>/dev/null
|
|
fails=$((fails + 1))
|
|
return 1
|
|
fi
|
|
HOME="$D/home" SPLINTER_LOCALE=de SPLINTER_TELEGRAM_TOKEN=tok \
|
|
SPLINTER_TELEGRAM_API="http://127.0.0.1:$P" \
|
|
SPLINTER_ACK_DIR="$D/home/ack" SPLINTER_ACK_TTL=20 \
|
|
./splinter --config "$D/home/splinter.conf" --daemon \
|
|
> "$D/gw.out" 2>&1 &
|
|
G=$!
|
|
for i in $(seq 1 120); do
|
|
grep -q '^fertig' "$D/sent.log" 2>/dev/null && break
|
|
sleep 0.5
|
|
done
|
|
kill "$G" "$S" 2>/dev/null
|
|
wait "$G" "$S" 2>/dev/null
|
|
}
|
|
|
|
check() { # $1 = description, $2.. = command
|
|
d=$1; shift
|
|
if "$@"; then :; else echo "FAIL $d"; fails=$((fails + 1)); fi
|
|
}
|
|
|
|
run ok 0
|
|
check "the command menu is registered" grep -q '^cmd: start' "$D/sent.log"
|
|
check "the menu carries plugin commands" grep -q '^cmd: goal' "$D/sent.log"
|
|
check "the menu carries command scripts" grep -q '^cmd: hello' "$D/sent.log"
|
|
check "approval is asked in the chat, with the tool" \
|
|
grep -q '^Zustimmung [0-9]*: write ' "$D/sent.log"
|
|
check "approval carries inline buttons" \
|
|
grep -q '"callback_data":"ack:' "$D/sent.log"
|
|
check "a question meanwhile is told to wait" \
|
|
grep -q '^Ich warte noch' "$D/sent.log"
|
|
check "the yes is acknowledged" grep -q '^Zustimmung erteilt' "$D/sent.log"
|
|
check "the tool ran after the yes" grep -q 'vom gateway' "$D/out.txt"
|
|
check "the turn ends with the answer" grep -q '^fertig' "$D/sent.log"
|
|
|
|
run no 1
|
|
check "the no is acknowledged" grep -q '^Abgelehnt' "$D/sent.log"
|
|
check "the tool did not run after the no" test ! -e "$D/out.txt"
|
|
|
|
# a program in commands/ answers in the chat, without a model turn
|
|
run_text() { # $1 = first message, $2 = line to wait for, $3 = port offset,
|
|
# $4 = a line that must appear too before the fake is killed
|
|
P=$((20000 + ($$ + ${3:-0}) % 30000))
|
|
rm -rf "$D/home" "$D/out.txt" "$D/sent.log"
|
|
mkdir -p "$D/home/.splinter/commands"
|
|
printf '#!/bin/sh\necho "script sagt hallo"\n' \
|
|
> "$D/home/.splinter/commands/hello"
|
|
chmod +x "$D/home/.splinter/commands/hello"
|
|
printf 'endpoint = http://127.0.0.1:%s/v1/chat/completions\nmodel = m\ntelegram_allow = 7\ndelegate = far | test | endpoint=http://127.0.0.1:9/v1/chat/completions | model=other\n' \
|
|
"$P" > "$D/home/splinter.conf"
|
|
python3 -I tests/fake_telegram.py "$P" "$D/out.txt" "$D/sent.log" ok "$1" \
|
|
> "$D/fake.out" 2>&1 &
|
|
S=$!
|
|
if ! wait_fake "$P" || ! kill -0 "$S" 2>/dev/null; then
|
|
echo "FAIL fake telegram did not start on $P"
|
|
cat "$D/fake.out" 2>/dev/null
|
|
fails=$((fails + 1))
|
|
return 1
|
|
fi
|
|
HOME="$D/home" SPLINTER_LOCALE=de SPLINTER_TELEGRAM_TOKEN=tok \
|
|
SPLINTER_TELEGRAM_API="http://127.0.0.1:$P" \
|
|
./splinter --config "$D/home/splinter.conf" --daemon \
|
|
> "$D/gw.out" 2>&1 &
|
|
G=$!
|
|
# The fake is killed once the marker showed up - so a check that reads a
|
|
# line sent *after* it has to name that line here, or the kill wins the
|
|
# race (/model: the switch is confirmed, then the next turn's error is
|
|
# sent; killing at the confirmation dropped it).
|
|
for i in $(seq 1 120); do
|
|
if grep -q "$2" "$D/sent.log" 2>/dev/null; then
|
|
if [ -z "${4:-}" ] ||
|
|
grep -q "$4" "$D/sent.log" 2>/dev/null; then
|
|
break
|
|
fi
|
|
fi
|
|
sleep 0.5
|
|
done
|
|
kill "$G" "$S" 2>/dev/null
|
|
wait "$G" "$S" 2>/dev/null
|
|
}
|
|
|
|
run_text "/hello" 'script sagt hallo' 10
|
|
check "a command script answers in the chat" \
|
|
grep -q 'script sagt hallo' "$D/sent.log"
|
|
check "a command script does not start a model turn" test ! -e "$D/out.txt"
|
|
|
|
run_text "/nosuch" '^unbekanntes Kommando: /nosuch' 20
|
|
check "an unknown command is an error" \
|
|
grep -q '^unbekanntes Kommando: /nosuch' "$D/sent.log"
|
|
check "an unknown command does not start a model turn" test ! -e "$D/out.txt"
|
|
|
|
# the model's markdown is rendered: Telegram draws HTML, not asterisks
|
|
run_text "zeig markdown" '<b>fett</b>' 40
|
|
check "an answer is sent with parse_mode=HTML" grep -q '^mode: HTML' "$D/sent.log"
|
|
check "bold markdown becomes a tag" grep -q '<b>fett</b>' "$D/sent.log"
|
|
check "inline code becomes a tag" grep -q '<code>code</code>' "$D/sent.log"
|
|
check "the raw markers do not reach the chat" \
|
|
sh -c "! grep -q '\*\*fett\*\*' '$D/sent.log'"
|
|
|
|
# a table is for the eye: columns in a monospace block, not a row of pipes
|
|
run_text "zeig eine tabelle" '<pre>' 50
|
|
check "a table is drawn in a monospace block" grep -q '<pre>' "$D/sent.log"
|
|
check "a table keeps its columns" grep -q '| a | b |' "$D/sent.log"
|
|
|
|
# an image in the answer is a photo, not a link, and the text keeps its order
|
|
run_text "zeig ein bild" 'Ende' 80
|
|
check "the image is sent as a photo" \
|
|
grep -q '^photo: https://example.org/b.png caption=Ein Bild' "$D/sent.log"
|
|
check "the text before the image arrives" grep -q '^Hier:' "$D/sent.log"
|
|
check "the text after the image arrives" grep -q 'Ende' "$D/sent.log"
|
|
check "no markdown image reaches the chat" \
|
|
sh -c "! grep -q '!\\[Ein Bild\\]' '$D/sent.log'"
|
|
run_text "zeig ein codebild" '<code>!\[x\]' 90
|
|
check "an image inside code stays text" \
|
|
grep -q '<code>!\[x\](https://example.org/x.png)</code>' "$D/sent.log"
|
|
check "an image inside code is not a photo" \
|
|
sh -c "! grep -q '^photo: https://example.org/x.png' '$D/sent.log'"
|
|
|
|
# a local image is uploaded as a photo; a non-image stays a reference
|
|
run_text "zeig ein lokales bild" 'photo-file: pic.png' 100
|
|
check "a local image is uploaded" \
|
|
grep -q '^photo-file: pic.png caption=Lokal' "$D/sent.log"
|
|
check "the local image does not show up as markdown" \
|
|
sh -c "! grep -q '!\\[Lokal\\]' '$D/sent.log'"
|
|
run_text "zeig kein bild" 'document-file: notimg.txt' 110
|
|
check "a non-image file goes as a document" \
|
|
grep -q '^document-file: notimg.txt caption=Kein Bild' "$D/sent.log"
|
|
check "it is not sent as a photo" \
|
|
sh -c "! grep -q '^photo-file: notimg.txt' '$D/sent.log'"
|
|
check "the reference does not stay in the chat" \
|
|
sh -c "! grep -q '!\\[Kein Bild\\]' '$D/sent.log'"
|
|
|
|
# /new starts a fresh conversation and a fresh session file
|
|
run_text "/new" 'Neue Konversation: sess-' 45
|
|
check "the bot says the new session" grep -q '^Neue Konversation: sess-' "$D/sent.log"
|
|
check "a session file was opened" sh -c "ls '$D'/home/.splinter/sess-*.jsonl | tail -1 | grep -q sess-"
|
|
|
|
# /model offers the configured models and switches on the button
|
|
run_text "/model" 'Provider far' 60 '^openai:'
|
|
check "the model menu lists the configured providers" \
|
|
grep -q '"callback_data":"model:far"' "$D/sent.log"
|
|
check "the model menu shows the models" grep -q 'far/other' "$D/sent.log"
|
|
check "the button switches the model" \
|
|
grep -q '^Modell: other (Provider far' "$D/sent.log"
|
|
# the next turn really uses the new endpoint (the test one is dead: port 9)
|
|
check "the next turn goes to the new endpoint" \
|
|
grep -q '^openai:' "$D/sent.log"
|
|
|
|
# /model probe asks the endpoint what it serves and switches to one of them
|
|
run_text "/model probe" 'Provider local' 55
|
|
check "the probe lists served models" grep -q '"callback_data":"mm:0"' "$D/sent.log"
|
|
check "a probed model is used" grep -q '^Modell: m (Provider local' "$D/sent.log"
|
|
check "the choice is not saved" \
|
|
test ! -f "$D/home/splinter.conf.d/90-model.conf"
|
|
|
|
# /connect writes a provider to the config drop-in
|
|
run_text "/connect" 'Provider testprov gespeichert' 70
|
|
drop="$D/home/splinter.conf.d/20-connect.conf"
|
|
check "connect writes the drop-in" test -f "$drop"
|
|
check "the line names the provider" grep -q '^delegate = testprov |' "$drop"
|
|
check "the line names the endpoint" \
|
|
grep -q "endpoint=http://127.0.0.1:$P/v1/chat/completions" "$drop"
|
|
check "the line names the model" grep -q 'model=llama3' "$drop"
|
|
check "connect offers to use it now" \
|
|
grep -q '"callback_data":"model:testprov"' "$D/sent.log"
|
|
check "connect tested the provider" grep -q 'Test bestanden: ok' "$D/sent.log"
|
|
|
|
# /interview: the model interviews; the summary before INTERVIEW_COMPLETE
|
|
# becomes USER.txt (the fake answers with the marker once the interview
|
|
# prompt is in the request)
|
|
run_text "/interview" 'Interview gestartet' 30 'Interview in USER.txt gespeichert'
|
|
check "the interview saved USER.txt" test -s "$D/home/.splinter/USER.txt"
|
|
check "the summary is in USER.txt" grep -q 'mag C99' "$D/home/.splinter/USER.txt"
|
|
check "the marker is not in USER.txt" \
|
|
sh -c "! grep -q INTERVIEW_COMPLETE '$D/home/.splinter/USER.txt'"
|
|
|
|
if [ "$fails" -eq 0 ]; then echo "test_gateway: ok"; exit 0; fi
|
|
cat "$D/gw.out"
|
|
exit 1
|