#!/bin/sh # # splinter -- the Anthropic transport against a fake Messages API. # # The fake is as strict as the real endpoint: an OAuth token must arrive as a # Bearer token with the oauth beta, the system prompt must be the top-level # `system` field starting with Claude Code's block, and tools must carry # input_schema. So a run that answers here has a request shape the real API # accepts -- not just a socket that says 200. # # Also checked: streaming and non-streaming give the same answer, a 429 keeps # the provider's own message (instead of "no answer"), and -m picks the pool. set -u cd "$(dirname "$0")/.." || exit 1 . "$(dirname "$0")/sh/port.sh" D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-as-XXXXXX") || exit 1 P=$(free_port) trap 'kill $FP 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_anthropic.py "$P" "$D/req.log" & FP=$! for i in $(seq 1 50); do curl -s -o /dev/null "http://127.0.0.1:$P/" && break sleep 0.2 done cat > "$D/home/splinter.conf" < "$D/o1.txt" 2>&1 check "a streamed anthropic answer arrives" grep -q 'weiter gemacht' "$D/o1.txt" ./splinter --config "$D/home/splinter.conf" -m api0 --no-stream -p hallo \ "$D/o2.txt" 2>&1 check "a whole anthropic reply arrives" grep -q 'weiter gemacht' "$D/o2.txt" # -m with the pool name reaches the same provider ./splinter --config "$D/home/splinter.conf" -m duo --no-stream -p hallo \ "$D/o3.txt" 2>&1 check "the pool name selects the member" grep -q 'weiter gemacht' "$D/o3.txt" # the request says anthropic, not openai check "the endpoint was addressed" grep -q '^/v1/messages' "$D/req.log" check "the system prompt is top level" grep -q '"system":\[{"type":"text"' \ "$D/req.log" check "tools carry input_schema" grep -q '"input_schema"' "$D/req.log" check "no chat/completions shape leaked in" \ test "$(grep -c 'tool_calls' "$D/req.log")" -eq 0 # a limit keeps the provider's own sentence and the HTTP status; on_limit=fail # so the run says it now instead of waiting for the window to move cat > "$D/home/limit.conf" < "$D/o4.txt" 2>&1 rc=$? check "a 429 is not reported as an empty answer" grep -q 'rate limit' \ "$D/o4.txt" check "a 429 fails the turn" test "$rc" -ne 0 if [ "$fails" -eq 0 ]; then echo "test_anthropic: ok"; exit 0; fi cat "$D/o1.txt" "$D/o2.txt" "$D/o3.txt" "$D/o4.txt" exit 1