#!/bin/sh # splinter -- A2A runs a mutating tool without asking anyone. # # This test used to guard the opposite: the first SendMessage returned # TASK_STATE_INPUT_REQUIRED before a write ran, and a follow-up with taskId # "yes"/"no" resumed it. That gate is gone -- an A2A caller is not sitting in # front of a prompt, and splinter does not decide for the operator. What is # guarded here: # # - a write call runs in the first SendMessage and the task completes; # - the answer the model gives after the tool round is the task's answer; # - no TASK_STATE_INPUT_REQUIRED is produced; # - CancelTask still works on a task that exists. set -u cd "$(dirname "$0")/.." || exit 1 . "$(dirname "$0")/sh/port.sh" D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-a2a-ir-XXXXXX") || exit 1 P=$(free_port) P2=$((P + 1)) S1= S2= cleanup() { [ -n "$S1" ] && kill "$S1" 2>/dev/null [ -n "$S2" ] && kill "$S2" 2>/dev/null rm -rf "$D" } trap cleanup EXIT mkdir -p "$D/home" "$D/home2" fails=0 check() { if "$@"; then :; else echo "FAIL $*"; fails=$((fails + 1)); fi; } wait_port() { for i in $(seq 1 100); do curl -s -o /dev/null "http://127.0.0.1:$1/" && return 0 sleep 0.2 done return 1 } post() { # post curl -s -H 'Content-Type: application/json' --data "$2" \ "http://127.0.0.1:$1/a2a" } first() { # first post "$1" '{"jsonrpc":"2.0","id":"1","method":"SendMessage","params":{"message":{"messageId":"m","role":"ROLE_USER","parts":[{"text":"please write"}]}}}' } state_of() { printf '%s' "$1" | python3 -c \ 'import json,sys; print(json.load(sys.stdin)["result"]["task"]["status"]["state"])' } task_of() { printf '%s' "$1" | python3 -c \ 'import json,sys; print(json.load(sys.stdin)["result"]["task"]["id"])' } # ---- a write runs at once, no pause, no question ---- printf 'tool write {"path":"%s/written.txt","content":"yes"}\nanswer done\n' \ "$D" > "$D/model.txt" HOME="$D/home" ./splinter --no-config --script "$D/model.txt" \ --a2a-server-listen 127.0.0.1 --a2a-listen-port "$P" \ > "$D/gw1.out" 2>&1 & S1=$! check wait_port "$P" r=$(first "$P") check test "$(state_of "$r")" = "TASK_STATE_COMPLETED" check test -e "$D/written.txt" check grep -q 'yes' "$D/written.txt" check sh -c "! printf '%s' '$r' | grep -q INPUT_REQUIRED" check sh -c "printf '%s' '$r' | grep -q 'done'" # ---- CancelTask on a finished task is refused, not silently accepted ---- tid=$(task_of "$r") check test -n "$tid" r=$(post "$P" "{\"jsonrpc\":\"2.0\",\"id\":\"3\",\"method\":\"CancelTask\",\"params\":{\"id\":\"$tid\"}}") check sh -c "printf '%s' '$r' | grep -q 'error'" # ---- a destructive call (run) also runs through ---- printf 'tool run {"command":"touch %s/rm-me.txt"}\nanswer removed\n' \ "$D" > "$D/model2.txt" HOME="$D/home2" ./splinter --no-config --script "$D/model2.txt" \ --a2a-server-listen 127.0.0.1 --a2a-listen-port "$P2" \ > "$D/gw2.out" 2>&1 & S2=$! check wait_port "$P2" r=$(first "$P2") check test "$(state_of "$r")" = "TASK_STATE_COMPLETED" check test -e "$D/rm-me.txt" if [ "$fails" -eq 0 ]; then echo "test_a2a_input: ok"; exit 0; fi echo "--- gw1 ---"; tail -5 "$D/gw1.out" 2>/dev/null echo "--- gw2 ---"; tail -5 "$D/gw2.out" 2>/dev/null exit 1