Files
splinter/tests/test_a2a_input.sh
lotherk 74df75d438 no approval gate: splinter runs what the operator's registry offers
Konrad, 24.11.: "v1 geht durch ohne irgendwas. ich will auch keine approvals
generell. ich will nur das der user mit ask nach sachen gefragt werden kann."

Removed the whole approval apparatus, not just the prompt:

- agent.c: the decision point (sp_host_gate/approve callbacks), the
  pause/resume path (has_pending, pending_from, sp_agent_resume), ack_approval,
  ask_operator and the ack stdin thread are gone. A tool runs; its exit status
  is the observation. sp_tool_policy (allow/deny per profile) stays - that is
  the operator's own configuration, not a question to the operator.
- engine.c: SP_EV_APPROVAL, sp_engine_approve, the approve_pending condition
  variable and the `approval`/`approve` protocol commands are gone.
- openai_server.c: the v1 endpoint runs gw_* tools without a gate; the
  autonomous flag is no longer part of sp_gateway_opts.
- a2aserver.c: INPUT_REQUIRED and the resume-by-taskId path are gone; CancelTask
  stays. An A2A caller has no operator sitting in front of a prompt.
- mcpserver.c: --autonomous no longer gates mutating tools; the flag and the
  config key are accepted for compatibility and documented as changing
  nothing.
- telegram.c: tg_approve and the approval callback are gone; ask is the only
  dialog, and /cancel inside it still ends the turn.
- front ends: protocol.c, curses.c, ui_local.c, ui_remote.c, client.c lose the
  approval event and the waiting flag.
- ack.c stays: it is a plugin API (plugins/kids asks its parent through it),
  not splinter's own gate. --ack is documented as such.

Tests: test_pause.c guarded the pause and now guards the opposite (a mutate and
a destructive tool run, nothing is asked). test_a2a_input.sh, test_protocol.sh,
test_ui.sh, test_agents_ui.sh, test_gateway.sh, test_gateway_openai.sh,
test_agent.c and test_mcpsession.sh were rewritten the same way;
splinter_approve must now be absent from the MCP tool list. Every rewritten
test was run red against the old behaviour where that was possible.

make check: all tests passed (428 s)
make check-asan: all 47 test binaries clean
make check-tsan: all 47 test binaries free of data races
2026-11-24 11:46:10 +00:00

94 lines
3.2 KiB
Bash
Executable File

#!/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 <port> <json>
curl -s -H 'Content-Type: application/json' --data "$2" \
"http://127.0.0.1:$1/a2a"
}
first() { # first <port>
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