#!/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 . "$(dirname "$0")/sh/port.sh" D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-pool-XXXXXX") || exit 1 # Two fakes: one call, both bound before either is released (see free_ports). set -- $(free_ports 2) PA=$1 PB=$2 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 if ! wait_listen "$PA" "$FA"; then echo "FAIL the first fake never listened"; exit 1; fi if ! wait_listen "$PB" "$FB"; then echo "FAIL the second fake never listened"; exit 1; fi curl -s -o /dev/null -X POST -d '{}' "http://127.0.0.1:$PB/prime" cat > "$D/home/splinter.conf" < "$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 "$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 "$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 "$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