- /model in the curses chat opens a picker: Up/Down, typing filters by
provider/model, Enter takes the selector, Esc cancels. The list comes from
the backend (sp_engine_models -> sp_provider_choices), not from a text
scrape; the socket has a `models` command, so --attach gets the same picker,
and the switch is still the ordinary "/model <selector>" input.
- steering: Enter during a turn now says so twice - a "steering queued: ..."
row in the transcript and "Ns steering queued (n) steer>" in the input line
until the step boundary picks it up; a rejected steer is an error entry.
- input lag: typing during a turn is echoed immediately (the input line is
redrawn per key, not at the next 100 ms frame), and the history is only
repainted when its generation changed, so a streaming turn no longer
repaints the whole transcript on every clock tick.
- sidebar: the first line of every widget is bold, like its heading, so a
plugin block has a title instead of a wall of small print.
- junction plugin: keeps every response header from /mcp, the status route and
/v1/models; the widget shows the X-Junction-* routing stats, /junction lists
all headers per source. It reads the status aliases (/status, /v1/status,
/queue, /v1/queue) and remembers the one that answered, parses queue,
endpoint p95/exhausted counts, and counts the models (/v1/models, probed on
its own slower interval because it goes upstream).
- SSE: blank lines no longer abort a pretty-printed object, a truncated tail
is dropped instead of failing the turn ("incomplete data line" is gone), and
a [DONE] with a fragment clears it.
- retries: a request that fails before anything streamed (connection, missing
status, 5xx) is tried three more times, 5 s apart; 4xx is not retried, and
after the first chunk the error is reported instead of printing the answer
twice. Ctrl-C ends a wait at once; SPLINTER_RETRY_WAIT_MS overrides the wait.
- tests: test_sse (split object across events, truncated tail), test_agent
(four 500s = four requests; two 500s then an answer), test_engine and
test_protocol (models list), test_junction (headers, aliases, models),
test_ui (/model picker), test_focus (status keys).
make check: all tests passed.
384 lines
12 KiB
Bash
Executable File
384 lines
12 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
|
|
D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-proto-XXXXXX") || exit 1
|
|
P1=$((20000 + $$ % 20000))
|
|
P2=$((40000 + $$ % 20000))
|
|
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=$!
|
|
sleep 0.8
|
|
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 "main" 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
|
|
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 '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 'main m' "$D/model.out"
|
|
|
|
# ------------------------------------------------- an approval is a question
|
|
[ -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/denied.txt" "$D/sent2.log" ok \
|
|
> "$D/fake2.out" 2>&1 &
|
|
F2=$!
|
|
sleep 0.8
|
|
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/deny.out" 2> "$D/deny.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")
|
|
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
|
|
while True:
|
|
ev = json.loads(f.readline())
|
|
if ev.get("ev") == "approval":
|
|
asked = True
|
|
f.write(json.dumps({"cmd": "approve", "allow": False}) + "\n")
|
|
f.flush()
|
|
if ev.get("ev") == "turn":
|
|
print("asked" if asked else "no question")
|
|
print("ok" if ev.get("ok") else "failed")
|
|
break
|
|
PY
|
|
checkgrep 'asked' "$D/deny.out"
|
|
checkgrep 'ok' "$D/deny.out"
|
|
# the denial is the observation: the tool never ran
|
|
check test ! -e "$D/denied.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
|