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
422 lines
14 KiB
Bash
Executable File
422 lines
14 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# splinter -- the line protocol: a served engine, driven without a screen.
|
|
#
|
|
# What it guards: the greeting names the protocol version and the session; a
|
|
# prompt produces submitted/stream/tool/tool_result/turn; a slash command
|
|
# answers with a reply and does not start a turn; an approval is a question the
|
|
# client answers (yes runs the tool, no denies it and nothing is written); the
|
|
# reference client speaks it; quit closes the server.
|
|
set -u
|
|
cd "$(dirname "$0")/.." || exit 1
|
|
. "$(dirname "$0")/sh/port.sh"
|
|
D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-proto-XXXXXX") || exit 1
|
|
# Two fakes, two ports out of one call (see free_ports): both are bound before
|
|
# either is released, so they cannot come back the same.
|
|
set -- $(free_ports 2)
|
|
P1=$1
|
|
P2=$2
|
|
F1=
|
|
F2=
|
|
S1=
|
|
S2=
|
|
fails=0
|
|
cleanup() {
|
|
[ -n "$S1" ] && kill "$S1" 2>/dev/null
|
|
[ -n "$S2" ] && kill "$S2" 2>/dev/null
|
|
[ -n "$F1" ] && kill "$F1" 2>/dev/null
|
|
[ -n "$F2" ] && kill "$F2" 2>/dev/null
|
|
rm -rf "$D"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
check() { if "$@"; then :; else echo "FAIL $*"; fails=$((fails + 1)); fi; }
|
|
checkgrep() { # pattern file
|
|
if grep -q -- "$1" "$2" 2>/dev/null; then :; else
|
|
echo "FAIL missing '$1' in $2"
|
|
[ -f "$2" ] && cat "$2"
|
|
fails=$((fails + 1))
|
|
fi
|
|
}
|
|
wait_for() { # path, tries
|
|
i=0
|
|
while [ "$i" -lt "$2" ]; do
|
|
[ -e "$1" ] && return 0
|
|
i=$((i + 1))
|
|
sleep 0.2
|
|
done
|
|
return 1
|
|
}
|
|
|
|
mkdir -p "$D/home"
|
|
python3 -I tests/fake_telegram.py "$P1" "$D/out.txt" "$D/sent.log" ok \
|
|
> "$D/fake.out" 2>&1 &
|
|
F1=$!
|
|
if ! wait_listen "$P1" "$F1"; then
|
|
echo "FAIL the first fake never listened"
|
|
cat "$D/fake.out"
|
|
exit 1
|
|
fi
|
|
HOME=$D/home SPLINTER_LOCALE=en ./splinter --no-config --autonomous \
|
|
--endpoint "http://127.0.0.1:$P1/v1/chat/completions" --model m \
|
|
--serve --socket "$D/sock" > "$D/serve.out" 2>&1 &
|
|
S1=$!
|
|
if ! wait_for "$D/sock" 20; then
|
|
echo "FAIL the server never created its socket"
|
|
cat "$D/serve.out"
|
|
exit 1
|
|
fi
|
|
|
|
# a second server on the same socket must refuse to start
|
|
HOME=$D/home SPLINTER_LOCALE=en ./splinter --no-config --autonomous \
|
|
--endpoint "http://127.0.0.1:$P1/v1/chat/completions" --model m \
|
|
--serve --socket "$D/sock" > "$D/second.out" 2>&1
|
|
if [ $? -eq 0 ]; then
|
|
echo "FAIL a second server on the same socket started"
|
|
fails=$((fails + 1))
|
|
fi
|
|
checkgrep 'already being served' "$D/second.out"
|
|
HOME=$D/home SPLINTER_LOCALE=en ./splinterctl --socket "$D/sock" \
|
|
--cmd /status > "$D/alive.out" 2>/dev/null
|
|
checkgrep 'session' "$D/alive.out"
|
|
|
|
# ---------------------------------------------- the events, as JSON lines
|
|
# The first turn of this conversation: the fake asks for a tool, runs it and
|
|
# answers. This is the shape a GUI draws.
|
|
python3 - "$D/sock" > "$D/events.out" 2> "$D/events.err" <<'PY'
|
|
import json, socket, sys
|
|
|
|
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
s.connect(sys.argv[1])
|
|
f = s.makefile("rw", encoding="utf-8")
|
|
seen = []
|
|
|
|
sessA = ""
|
|
while "state" not in seen:
|
|
ev = json.loads(f.readline())
|
|
seen.append(ev.get("ev"))
|
|
if ev.get("ev") == "state":
|
|
sessA = ev.get("session", "")
|
|
if ev.get("ev") == "ready" and ev.get("protocol") != 2:
|
|
print("bad protocol", ev, file=sys.stderr)
|
|
sys.exit(1)
|
|
if ev.get("ev") == "state" and not ev.get("session"):
|
|
print("state without a session", ev, file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
f.write(json.dumps({"cmd": "commands"}) + "\n")
|
|
f.flush()
|
|
while True:
|
|
ev = json.loads(f.readline())
|
|
if ev.get("ev") == "commands":
|
|
if "model" not in ev.get("names", []) or "status" not in ev.get("names", []):
|
|
print("commands incomplete", ev, file=sys.stderr)
|
|
sys.exit(1)
|
|
seen.append("commands")
|
|
break
|
|
|
|
f.write(json.dumps({"cmd": "models"}) + "\n")
|
|
f.flush()
|
|
while True:
|
|
ev = json.loads(f.readline())
|
|
if ev.get("ev") == "models":
|
|
sels = [it.get("sel") for it in ev.get("items", [])]
|
|
if "local/m" not in sels:
|
|
print("models incomplete", ev, file=sys.stderr)
|
|
sys.exit(1)
|
|
seen.append("models")
|
|
break
|
|
|
|
f.write(json.dumps({"cmd": "say", "text": "hallo"}) + "\n")
|
|
f.flush()
|
|
while True:
|
|
ev = json.loads(f.readline())
|
|
seen.append(ev.get("ev"))
|
|
if ev.get("ev") == "turn":
|
|
if not ev.get("ok"):
|
|
print("turn failed", ev, file=sys.stderr)
|
|
sys.exit(1)
|
|
answer = ev.get("answer", "")
|
|
break
|
|
print("events " + " ".join(seen))
|
|
print("answer " + answer)
|
|
|
|
f.write(json.dumps({"cmd": "history"}) + "\n")
|
|
f.flush()
|
|
while True:
|
|
ev = json.loads(f.readline())
|
|
if ev.get("ev") == "history":
|
|
texts = [it.get("text", "") for it in ev.get("items", [])]
|
|
print("history_ok" if "hallo" in texts else "history_missing")
|
|
break
|
|
|
|
# a shell entry bigger than any fixed 8 KiB line buffer: the client must
|
|
# receive the whole JSON line, not a truncated one it cannot parse
|
|
f.write(json.dumps({"cmd": "input", "line": "!seq 1 3000"}) + "\n")
|
|
f.flush()
|
|
big = 0
|
|
while True:
|
|
ev = json.loads(f.readline())
|
|
if ev.get("ev") == "entry" and ev.get("role") == "shell":
|
|
big = len(ev.get("text", ""))
|
|
if ev.get("ev") == "reply":
|
|
break
|
|
print("shell_bytes %d" % big)
|
|
|
|
# and a prompt longer than 8 KiB
|
|
f.write(json.dumps({"cmd": "say", "text": "x" * 9000}) + "\n")
|
|
f.flush()
|
|
while True:
|
|
ev = json.loads(f.readline())
|
|
if ev.get("ev") == "turn":
|
|
print("long_prompt_ok" if ev.get("ok") else "long_prompt_failed")
|
|
break
|
|
|
|
# ---- sessions: list, titles, rename, delete, switch back, errors ----
|
|
def command(text):
|
|
f.write(json.dumps({"cmd": "input", "line": text}) + "\n")
|
|
f.flush()
|
|
while True:
|
|
ev = json.loads(f.readline())
|
|
if ev.get("ev") == "reply":
|
|
return ev.get("text", "")
|
|
|
|
f.write(json.dumps({"cmd": "sessions"}) + "\n")
|
|
f.flush()
|
|
while True:
|
|
ev = json.loads(f.readline())
|
|
if ev.get("ev") == "sessions":
|
|
cur = [i.get("id") for i in ev.get("items", []) if i.get("current")]
|
|
titles = {i.get("id"): i.get("title") for i in ev.get("items", [])}
|
|
print("sessions_ok" if cur == [sessA] else "sessions_bad")
|
|
print("title_ok" if titles.get(sessA) == "hallo" else "title_bad")
|
|
break
|
|
reply = command("/rename Feiner Titel")
|
|
print("rename_ok" if "Feiner Titel" in reply else "rename_bad")
|
|
f.write(json.dumps({"cmd": "sessions"}) + "\n")
|
|
f.flush()
|
|
while True:
|
|
ev = json.loads(f.readline())
|
|
if ev.get("ev") == "sessions":
|
|
titles = {i.get("id"): i.get("title") for i in ev.get("items", [])}
|
|
print("rename_listed" if titles.get(sessA) == "Feiner Titel" else
|
|
"rename_not_listed")
|
|
break
|
|
f.write(json.dumps({"cmd": "open", "session": "new"}) + "\n")
|
|
f.flush()
|
|
sessB = ""
|
|
while True:
|
|
ev = json.loads(f.readline())
|
|
if ev.get("ev") == "opened":
|
|
sessB = ev.get("session", "")
|
|
break
|
|
print("open_new_ok" if sessB and sessB != sessA else "open_new_bad")
|
|
f.write(json.dumps({"cmd": "sessions"}) + "\n")
|
|
f.flush()
|
|
while True:
|
|
ev = json.loads(f.readline())
|
|
if ev.get("ev") == "sessions":
|
|
ids = [i.get("id") for i in ev.get("items", [])]
|
|
cur = [i.get("id") for i in ev.get("items", []) if i.get("current")]
|
|
print("sessions_two_ok" if sessA in ids and sessB in ids and
|
|
cur == [sessB] else "sessions_two_bad")
|
|
break
|
|
f.write(json.dumps({"cmd": "open", "session": sessA}) + "\n")
|
|
f.flush()
|
|
while True:
|
|
ev = json.loads(f.readline())
|
|
if ev.get("ev") == "opened":
|
|
print("open_back_ok" if ev.get("session") == sessA else
|
|
"open_back_bad")
|
|
break
|
|
f.write(json.dumps({"cmd": "history"}) + "\n")
|
|
f.flush()
|
|
while True:
|
|
ev = json.loads(f.readline())
|
|
if ev.get("ev") == "history":
|
|
texts = [it.get("text", "") for it in ev.get("items", [])]
|
|
print("history_restored" if "hallo" in texts else
|
|
"history_lost")
|
|
break
|
|
f.write(json.dumps({"cmd": "open", "session": "does-not-exist"}) + "\n")
|
|
f.flush()
|
|
ev = json.loads(f.readline())
|
|
print("open_missing" if ev.get("ev") == "error" else "open_missing_bad")
|
|
f.write(json.dumps({"cmd": "state"}) + "\n")
|
|
f.flush()
|
|
while True:
|
|
ev = json.loads(f.readline())
|
|
if ev.get("ev") == "state":
|
|
print("still_a" if ev.get("session") == sessA else "not_a")
|
|
break
|
|
# ---- the picker's two steps: sources, then the rows of one source ----
|
|
f.write(json.dumps({"cmd": "sources"}) + "\n")
|
|
f.flush()
|
|
while True:
|
|
ev = json.loads(f.readline())
|
|
if ev.get("ev") == "sources":
|
|
names = [i.get("name") for i in ev.get("items", [])]
|
|
counts = {i.get("name"): i.get("count") for i in ev.get("items", [])}
|
|
print("sources_ok" if names and names[0] == "splinter" and
|
|
counts.get("splinter", 0) >= 2 else "sources_bad")
|
|
break
|
|
f.write(json.dumps({"cmd": "sessions", "source": "splinter"}) + "\n")
|
|
f.flush()
|
|
while True:
|
|
ev = json.loads(f.readline())
|
|
if ev.get("ev") == "sessions":
|
|
ids = [i.get("id") for i in ev.get("items", [])]
|
|
cur = [i.get("id") for i in ev.get("items", []) if i.get("current")]
|
|
print("source_rows_ok" if sessA in ids and cur == [sessA] else
|
|
"source_rows_bad")
|
|
break
|
|
reply = command("/rm does-not-exist")
|
|
print("rm_missing_ok" if "No such session" in reply else "rm_missing_bad")
|
|
reply = command("/rm " + sessB)
|
|
print("rm_ok" if sessB in reply and "removed" in reply else "rm_bad")
|
|
f.write(json.dumps({"cmd": "sessions"}) + "\n")
|
|
f.flush()
|
|
while True:
|
|
ev = json.loads(f.readline())
|
|
if ev.get("ev") == "sessions":
|
|
ids = [i.get("id") for i in ev.get("items", [])]
|
|
print("rm_gone_ok" if sessB not in ids and sessA in ids else
|
|
"rm_gone_bad")
|
|
break
|
|
reply = command("/rm " + sessA)
|
|
print("rm_current_ok" if "Cannot remove" in reply else "rm_current_bad")
|
|
PY
|
|
checkgrep 'ready' "$D/events.out"
|
|
checkgrep 'state' "$D/events.out"
|
|
checkgrep 'submitted' "$D/events.out"
|
|
checkgrep 'tool ' "$D/events.out"
|
|
checkgrep 'tool_result' "$D/events.out"
|
|
checkgrep 'turn' "$D/events.out"
|
|
checkgrep 'commands' "$D/events.out"
|
|
checkgrep 'shell_bytes [0-9]\{4,\}' "$D/events.out"
|
|
checkgrep 'long_prompt_ok' "$D/events.out"
|
|
checkgrep 'history_ok' "$D/events.out"
|
|
checkgrep 'sessions_ok' "$D/events.out"
|
|
checkgrep 'open_new_ok' "$D/events.out"
|
|
checkgrep 'sessions_two_ok' "$D/events.out"
|
|
checkgrep 'open_back_ok' "$D/events.out"
|
|
checkgrep 'history_restored' "$D/events.out"
|
|
checkgrep 'open_missing$' "$D/events.out"
|
|
checkgrep 'still_a' "$D/events.out"
|
|
checkgrep 'sources_ok' "$D/events.out"
|
|
checkgrep 'source_rows_ok' "$D/events.out"
|
|
checkgrep 'title_ok' "$D/events.out"
|
|
checkgrep 'rename_ok' "$D/events.out"
|
|
checkgrep 'rename_listed' "$D/events.out"
|
|
checkgrep 'rm_missing_ok' "$D/events.out"
|
|
checkgrep 'rm_ok' "$D/events.out"
|
|
checkgrep 'rm_gone_ok' "$D/events.out"
|
|
checkgrep 'rm_current_ok' "$D/events.out"
|
|
checkgrep 'answer fertig' "$D/events.out"
|
|
check grep -q 'vom gateway' "$D/out.txt"
|
|
|
|
# --------------------------------------------------- the reference client
|
|
HOME=$D/home SPLINTER_LOCALE=en ./splinterctl --socket "$D/sock" \
|
|
--say "hallo" > "$D/say.out" 2> "$D/say.err"
|
|
check grep -q 'fertig' "$D/say.out"
|
|
|
|
HOME=$D/home SPLINTER_LOCALE=en ./splinterctl --socket "$D/sock" \
|
|
--cmd /status > "$D/status.out" 2>/dev/null
|
|
checkgrep 'session' "$D/status.out"
|
|
checkgrep 'model m' "$D/status.out"
|
|
|
|
HOME=$D/home SPLINTER_LOCALE=en ./splinterctl --socket "$D/sock" \
|
|
--cmd /model > "$D/model.out" 2>/dev/null
|
|
checkgrep 'local/m' "$D/model.out"
|
|
|
|
# --------------------------------------- a mutating tool runs without asking
|
|
[ -n "$S1" ] && kill "$S1" 2>/dev/null
|
|
S1=
|
|
sleep 0.3
|
|
rm -f "$D/sock"
|
|
mkdir -p "$D/home2"
|
|
python3 -I tests/fake_telegram.py "$P2" "$D/written2.txt" "$D/sent2.log" ok \
|
|
> "$D/fake2.out" 2>&1 &
|
|
F2=$!
|
|
if ! wait_listen "$P2" "$F2"; then
|
|
echo "FAIL the second fake never listened"
|
|
cat "$D/fake2.out"
|
|
exit 1
|
|
fi
|
|
HOME=$D/home2 SPLINTER_LOCALE=en ./splinter --no-config \
|
|
--endpoint "http://127.0.0.1:$P2/v1/chat/completions" --model m \
|
|
--serve --socket "$D/sock2" > "$D/serve2.out" 2>&1 &
|
|
S2=$!
|
|
if ! wait_for "$D/sock2" 20; then
|
|
echo "FAIL the second server never created its socket"
|
|
cat "$D/serve2.out"
|
|
exit 1
|
|
fi
|
|
python3 - "$D/sock2" > "$D/run.out" 2> "$D/run.err" <<'PYEOF'
|
|
import json, socket, sys
|
|
|
|
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
s.connect(sys.argv[1])
|
|
f = s.makefile("rw", encoding="utf-8")
|
|
while True:
|
|
ev = json.loads(f.readline())
|
|
if ev.get("ev") == "state":
|
|
break
|
|
f.write(json.dumps({"cmd": "say", "text": "schreib"}) + "\n")
|
|
f.flush()
|
|
asked = False
|
|
ran = False
|
|
while True:
|
|
ev = json.loads(f.readline())
|
|
if ev.get("ev") == "approval":
|
|
asked = True
|
|
if ev.get("ev") == "tool_result":
|
|
ran = True
|
|
if ev.get("ev") == "turn":
|
|
print("asked" if asked else "no question")
|
|
print("ran" if ran else "did not run")
|
|
print("ok" if ev.get("ok") else "failed")
|
|
break
|
|
PYEOF
|
|
checkgrep 'no question' "$D/run.out"
|
|
checkgrep 'ran' "$D/run.out"
|
|
checkgrep 'ok' "$D/run.out"
|
|
# the tool really ran: the file the model asked for is there
|
|
check test -e "$D/written2.txt"
|
|
|
|
# ------------------------------------------------------------------- quit
|
|
python3 - "$D/sock2" <<'PY'
|
|
import json, socket, sys
|
|
|
|
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
s.connect(sys.argv[1])
|
|
f = s.makefile("rw", encoding="utf-8")
|
|
while True:
|
|
ev = json.loads(f.readline())
|
|
if ev.get("ev") == "state":
|
|
break
|
|
f.write(json.dumps({"cmd": "quit"}) + "\n")
|
|
f.flush()
|
|
for line in f:
|
|
ev = json.loads(line)
|
|
if ev.get("ev") == "quit":
|
|
sys.exit(0)
|
|
sys.exit(1)
|
|
PY
|
|
if [ $? -ne 0 ]; then
|
|
echo "FAIL quit did not answer with a quit event"
|
|
fails=$((fails + 1))
|
|
fi
|
|
i=0
|
|
while kill -0 "$S2" 2>/dev/null && [ "$i" -lt 25 ]; do
|
|
i=$((i + 1))
|
|
sleep 0.2
|
|
done
|
|
check test ! -S "$D/sock2"
|
|
|
|
if [ "$fails" -eq 0 ]; then
|
|
echo "test_protocol: ok"
|
|
exit 0
|
|
fi
|
|
exit 1
|