Files
splinter/tests/test_pools.sh
lotherkandClaude Sonnet 5.5 0b7a91e3b7 config blocks, pools, -m/--model-list, waiting out usage limits
Config: { } blocks (core, telegram, provider, pool, exit) translated to the flat
reader with source line numbers; flat form still loads; delegate/plugin limits
raised. Pools: failover/balance, used by delegation (tag-safe), by -m and for
the conversation when its provider hits a limit. -m SEL picks a pool, provider,
provider/model or model name; --model-list lists them with served models.
Usage limits: the agent finds the reset and waits (UI: Ctrl-C stops, /resume
goes on; on_limit=fail turns it off).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-11 22:12:26 +00:00

68 lines
2.7 KiB
Bash

#!/bin/sh
#
# splinter -- pools, -m and --model-list.
#
# Two fake providers in a failover pool: the first refuses everything with 429,
# the second answers. The run must end up on the second without waiting.
set -u
cd "$(dirname "$0")/.." || exit 1
D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-pool-XXXXXX") || exit 1
PA=$((20000 + $$ % 20000)); PB=$((PA + 1))
trap 'kill $FA $FB 2>/dev/null; rm -rf "$D"' EXIT
fails=0
check() { d=$1; shift; if "$@"; then :; else echo "FAIL $d"; fails=$((fails + 1)); fi; }
mkdir -p "$D/home"
python3 -I tests/fake_openai_limit.py "$PA" "$D/a.log" always &
FA=$!
python3 -I tests/fake_openai_limit.py "$PB" "$D/b.log" &
FB=$!
# B refuses its first request too: make it answer at once by priming it
for p in $PA $PB; do
for i in $(seq 1 50); do
curl -s -o /dev/null "http://127.0.0.1:$p/x" && break
sleep 0.2
done
done
curl -s -o /dev/null -X POST -d '{}' "http://127.0.0.1:$PB/prime"
cat > "$D/home/splinter.conf" <<CONF
core { default = duo }
provider first {
endpoint = http://127.0.0.1:$PA/v1/chat/completions
model = ma
tags = [t]
}
provider second {
endpoint = http://127.0.0.1:$PB/v1/chat/completions
model = mb
tags = [t]
}
pool duo { members = [first, second] strategy = failover }
CONF
export HOME="$D/home" SPLINTER_USAGE_DIR="$D/usage" SPLINTER_COOLDOWN_DIR="$D/cd"
# the model list names pools and providers
./splinter --config "$D/home/splinter.conf" --model-list --no-probe </dev/null > "$D/list.txt" 2>&1
check "the list names the pool" grep -q '^duo .*pool, failover: first second' "$D/list.txt"
check "the list names a provider" grep -q '^second ' "$D/list.txt"
check "the list names the default" grep -q '^# default: duo' "$D/list.txt"
# -m picks a provider, provider/model overrides the model, unknown is refused
./splinter --config "$D/home/splinter.conf" -m second --no-stream -p hallo </dev/null > "$D/o1.txt" 2>&1
check "-m second reaches second" grep -q 'weiter gemacht' "$D/o1.txt"
check "-m second did not touch first" test ! -s "$D/a.log"
./splinter --config "$D/home/splinter.conf" -m nope -p x </dev/null > "$D/o2.txt" 2>&1
check "-m with an unknown name is refused" grep -q "no provider, pool or model 'nope'" "$D/o2.txt"
# the pool's first member is at its limit: the run moves on to the second
rm -f "$D/b.log"; rm -rf "$D/cd" "$D/usage"
./splinter --config "$D/home/splinter.conf" --no-stream -p hallo </dev/null > "$D/o3.txt" 2>&1
check "the pool run ends on the second provider" grep -q 'weiter gemacht' "$D/o3.txt"
check "the first provider was asked" test -s "$D/a.log"
check "the second provider was asked" test -s "$D/b.log"
if [ "$fails" -eq 0 ]; then echo "test_pools: ok"; exit 0; fi
cat "$D/o1.txt" "$D/o3.txt"
exit 1