a2a_send posts SendMessage with a text part and, when a path is given, a file part: base64 bytes, a name (the path's last component) and a media type guessed from the name, at most 8 MiB -- the same cap the server enforces on the way in. The answer is text; a file the other side sends back is saved by collect_parts and named by path, which the tool returns. sp_b64_encode is the missing direction of the base64 helper, with vectors of its own in test_b64: empty input, one and two trailing bytes, a NUL. test_a2a: a real PNG is attached, the request carries name, mimeType and the base64 bytes, and the other side names it in the answer; a missing path is an error, not a silent empty message.
201 lines
7.3 KiB
Bash
Executable File
201 lines
7.3 KiB
Bash
Executable File
#!/bin/sh
|
|
# splinter -- the A2A client transport, against a fake A2A agent.
|
|
#
|
|
# What it guards: SendMessage as JSON-RPC (--no-stream), SendStreamingMessage
|
|
# with SSE (the default one-shot path), the message shape, a Task result
|
|
# (status message plus artifact text), a direct Message, the bearer token, and
|
|
# a JSON-RPC error that must fail the turn instead of becoming an empty answer.
|
|
set -u
|
|
cd "$(dirname "$0")/.." || exit 1
|
|
D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-a2a-XXXXXX") || exit 1
|
|
P=$((20000 + ($$ % 20000)))
|
|
F=
|
|
cleanup() { [ -n "$F" ] && kill "$F" 2>/dev/null; rm -rf "$D"; }
|
|
trap cleanup EXIT
|
|
export SPLINTER_A2A_INBOX="$D/inbox"
|
|
python3 -I tests/fake_a2a.py "$P" "$D/req.log" &
|
|
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
|
|
|
|
fails=0
|
|
check() { if "$@"; then :; else echo "FAIL $*"; fails=$((fails + 1)); fi; }
|
|
blocking() { # the plain send path
|
|
SPLINTER_A2A_URL="http://127.0.0.1:$P/rpc" SPLINTER_A2A_TIMEOUT=20 \
|
|
./splinter --no-config --plugin plugins/a2a/a2a.so \
|
|
--transport a2a --no-stream -p "$1"
|
|
}
|
|
streaming() { # the one-shot default: stream when the transport can
|
|
SPLINTER_A2A_URL="http://127.0.0.1:$P/rpc" SPLINTER_A2A_TIMEOUT=20 \
|
|
./splinter --no-config --plugin plugins/a2a/a2a.so \
|
|
--transport a2a -p "$1"
|
|
}
|
|
discovered() { # <card-path> <text>: no URL, only the agent card
|
|
SPLINTER_A2A_CARD="http://127.0.0.1:$P/$1" SPLINTER_A2A_TIMEOUT=20 \
|
|
./splinter --no-config --plugin plugins/a2a/a2a.so \
|
|
--transport a2a --no-stream -p "$2"
|
|
}
|
|
|
|
# ---- blocking: a Task, status message and artifact text ----
|
|
out=$(blocking "hallo" 2>&1)
|
|
echo "$out" | grep -q 'a2a sagt hallo'
|
|
check test $? -eq 0
|
|
echo "$out" | grep -q 'und tschuess'
|
|
check test $? -eq 0
|
|
|
|
# the wire shape of the blocking call
|
|
grep -q '"method":"SendMessage"' "$D/req.log"
|
|
check test $? -eq 0
|
|
grep -q '"role":"ROLE_USER"' "$D/req.log"
|
|
check test $? -eq 0
|
|
grep -q '"parts":\[{"text":"hallo"}\]' "$D/req.log"
|
|
check test $? -eq 0
|
|
|
|
# a direct Message is an answer, not a task
|
|
out=$(blocking "direkt" 2>&1)
|
|
echo "$out" | grep -q 'direkt vom agenten'
|
|
check test $? -eq 0
|
|
|
|
# a binary part is not dropped: it is saved and the path is in the answer
|
|
out=$(blocking "schick eine datei" 2>&1)
|
|
echo "$out" | grep -q 'hier ist die datei'
|
|
check test $? -eq 0
|
|
echo "$out" | grep -q '\[file bild.png at'
|
|
check test $? -eq 0
|
|
found=$(ls "$SPLINTER_A2A_INBOX"/*bild.png 2>/dev/null | head -1)
|
|
check test -n "$found"
|
|
check sh -c "printf PNGDATA | cmp - '$found'"
|
|
|
|
# raw (text/plain base64) and string data parts are read
|
|
out=$(blocking "raw" 2>&1)
|
|
echo "$out" | grep -q 'hallo'
|
|
check test $? -eq 0
|
|
echo "$out" | grep -q 'struktur'
|
|
check test $? -eq 0
|
|
|
|
# the token goes out as a bearer header, and is required when the agent asks
|
|
out=$(SPLINTER_A2A_TOKEN=tok blocking "auth bitte" 2>&1)
|
|
echo "$out" | grep -q 'a2a sagt hallo'
|
|
check test $? -eq 0
|
|
out=$(blocking "auth ohne token" 2>&1)
|
|
echo "$out" | grep -q 'unauthorized'
|
|
check test $? -eq 0
|
|
|
|
# a JSON-RPC error fails the turn with the agent's message
|
|
blocking "fehler" >/dev/null 2>"$D/err"
|
|
check test $? -ne 0
|
|
grep -q 'boom from a2a' "$D/err"
|
|
check test $? -eq 0
|
|
|
|
# ---- streaming: artifact chunks arrive as the answer ----
|
|
out=$(streaming "stream bitte" 2>&1)
|
|
echo "$out" | grep -q 'teil eins teil zwei'
|
|
check test $? -eq 0
|
|
if echo "$out" | grep -q 'fertig'; then
|
|
echo "FAIL the final status note leaked into the streamed answer"
|
|
fails=$((fails + 1))
|
|
fi
|
|
|
|
# no artifact: the final status message is the answer
|
|
out=$(streaming "streamstatus" 2>&1)
|
|
echo "$out" | grep -q 'nur status'
|
|
check test $? -eq 0
|
|
|
|
# a direct Message also streams
|
|
out=$(streaming "direkt" 2>&1)
|
|
echo "$out" | grep -q 'direkt vom agenten'
|
|
check test $? -eq 0
|
|
|
|
# the wire method, not the blocking one
|
|
grep -q '"method":"SendStreamingMessage"' "$D/req.log"
|
|
check test $? -eq 0
|
|
|
|
# ---- discovery: the card names the JSON-RPC endpoint ----
|
|
out=$(discovered ".well-known/agent-card.json" "hallo" 2>&1)
|
|
echo "$out" | grep -q 'a2a sagt hallo'
|
|
check test $? -eq 0
|
|
out=$(discovered "old-card.json" "hallo" 2>&1)
|
|
echo "$out" | grep -q 'a2a sagt hallo'
|
|
check test $? -eq 0
|
|
|
|
# ---- the plugin's GetTask/CancelTask tools against the same agent ----
|
|
mkdir -p "$D/home"
|
|
printf 'tool a2a_get_task {"id":"task-1"}\nanswer done\n' > "$D/tool-get.txt"
|
|
out=$(HOME="$D/home" SPLINTER_A2A_URL="http://127.0.0.1:$P/rpc" \
|
|
SPLINTER_A2A_TIMEOUT=20 ./splinter --no-config \
|
|
--plugin plugins/a2a/a2a.so --script "$D/tool-get.txt" \
|
|
-p "tool" --autonomous 2>&1)
|
|
echo "$out" | grep -q '^done'
|
|
check test $? -eq 0
|
|
sess=$(ls -t "$D/home/.splinter"/sess-*.jsonl 2>/dev/null | head -1)
|
|
check test -n "$sess"
|
|
check grep -q 'TASK_STATE_COMPLETED' "$sess"
|
|
|
|
printf 'tool a2a_cancel_task {"id":"task-1"}\nanswer done\n' \
|
|
> "$D/tool-cancel.txt"
|
|
out=$(HOME="$D/home" SPLINTER_A2A_URL="http://127.0.0.1:$P/rpc" \
|
|
SPLINTER_A2A_TIMEOUT=20 ./splinter --no-config \
|
|
--plugin plugins/a2a/a2a.so --script "$D/tool-cancel.txt" \
|
|
-p "tool" --autonomous 2>&1)
|
|
echo "$out" | grep -q '^done'
|
|
check test $? -eq 0
|
|
sess=$(ls -t "$D/home/.splinter"/sess-*.jsonl 2>/dev/null | head -1)
|
|
check grep -q -- '-32002' "$sess"
|
|
|
|
# ---- SubscribeToTask: the events of a subscription as one observation ----
|
|
printf 'tool a2a_subscribe {"id":"task-1"}\nanswer done\n' \
|
|
> "$D/tool-sub.txt"
|
|
out=$(HOME="$D/home" SPLINTER_A2A_URL="http://127.0.0.1:$P/rpc" \
|
|
SPLINTER_A2A_TIMEOUT=20 ./splinter --no-config \
|
|
--plugin plugins/a2a/a2a.so --script "$D/tool-sub.txt" \
|
|
-p "tool" --autonomous 2>&1)
|
|
echo "$out" | grep -q '^done'
|
|
check test $? -eq 0
|
|
sess=$(ls -t "$D/home/.splinter"/sess-*.jsonl 2>/dev/null | head -1)
|
|
check test -n "$sess"
|
|
check grep -q 'TASK_STATE_COMPLETED' "$sess"
|
|
check grep -q 'abo text' "$sess"
|
|
check grep -q 'abo teil' "$sess"
|
|
|
|
printf 'tool a2a_subscribe {"id":"nope"}\nanswer done\n' \
|
|
> "$D/tool-sub2.txt"
|
|
out=$(HOME="$D/home" SPLINTER_A2A_URL="http://127.0.0.1:$P/rpc" \
|
|
SPLINTER_A2A_TIMEOUT=20 ./splinter --no-config \
|
|
--plugin plugins/a2a/a2a.so --script "$D/tool-sub2.txt" \
|
|
-p "tool" --autonomous 2>&1)
|
|
echo "$out" | grep -q '^done'
|
|
check test $? -eq 0
|
|
sess=$(ls -t "$D/home/.splinter"/sess-*.jsonl 2>/dev/null | head -1)
|
|
check grep -q -- '-32001' "$sess"
|
|
|
|
# ---- a2a_send: a message with a file attached ----
|
|
printf 'PNGDATA' > "$D/att.png"
|
|
printf 'tool a2a_send {"text":"hier ist eine datei","file":"%s"}\nanswer done\n' \
|
|
"$D/att.png" > "$D/tool-send.txt"
|
|
out=$(HOME="$D/home" SPLINTER_A2A_URL="http://127.0.0.1:$P/rpc" \
|
|
SPLINTER_A2A_TIMEOUT=20 ./splinter --no-config \
|
|
--plugin plugins/a2a/a2a.so --script "$D/tool-send.txt" \
|
|
-p "tool" --autonomous 2>&1)
|
|
echo "$out" | grep -q '^done'
|
|
check test $? -eq 0
|
|
sess=$(ls -t "$D/home/.splinter"/sess-*.jsonl 2>/dev/null | head -1)
|
|
check grep -q 'datei empfangen: att.png 7' "$sess"
|
|
check grep -q '"file":{"name":"att.png","mimeType":"image/png"' "$D/req.log"
|
|
check grep -q '"bytes":"UE5HREFUQQ=="' "$D/req.log"
|
|
|
|
printf 'tool a2a_send {"text":"x","file":"%s/%s"}\nanswer done\n' \
|
|
"$D" "gibtsnicht.png" > "$D/tool-send2.txt"
|
|
out=$(HOME="$D/home" SPLINTER_A2A_URL="http://127.0.0.1:$P/rpc" \
|
|
SPLINTER_A2A_TIMEOUT=20 ./splinter --no-config \
|
|
--plugin plugins/a2a/a2a.so --script "$D/tool-send2.txt" \
|
|
-p "tool" --autonomous 2>&1)
|
|
echo "$out" | grep -q '^done'
|
|
check test $? -eq 0
|
|
sess=$(ls -t "$D/home/.splinter"/sess-*.jsonl 2>/dev/null | head -1)
|
|
check grep -q 'cannot read' "$sess"
|
|
|
|
if [ "$fails" -eq 0 ]; then echo "test_a2a: ok"; exit 0; fi
|
|
exit 1
|