Files
splinter/tests/test_mcpsession.sh
T
lotherk 6813fff1b5 model: every choice is provider/model; no main row
The picker and the text list now say what goes on the command line:
junction/qwen3.6-35b-judged, local/qwen3.6-35b. Labels and selectors are the
same string, so there is no second format to explain.

- the core endpoint (the endpoint/model without a provider block) is called
  "local" in every choice; its old name "main" is still accepted as a selector
  so existing drop-ins and session files keep working.
- sp_provider_choose("local/model") resolves to the core endpoint; a configured
  provider with that name wins if one exists.
- /model, /model probe and the served-model list all emit provider/model.
- the session sidecar stores provider/model (junction/qwen3.6-35b).
- the sidebar and /usage print "local" for the core endpoint.
- -m provider/model no longer produces an extra main row, and 90-model.conf
  (the old global /model file) was moved aside; the config's provider wins.
- tests and docs use local/test-model and local/m.

make check: all tests passed.
2026-11-18 12:22:52 +00:00

90 lines
2.6 KiB
Bash
Executable File

#!/bin/sh
# The MCP server's session tools, over a real socket.
#
# A script transport stands in for the model ("answer hello"), so no network is
# touched: tools/list must offer the session tools, and say/history/sessions/
# models must round-trip through the engine.
set -e
cd "$(dirname "$0")/.."
D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-mcps-XXXXXX") || exit 1
port=$((21000 + ($$ % 20000)))
pid=
cleanup() { [ -n "$pid" ] && kill "$pid" 2>/dev/null; rm -rf "$D"; }
trap cleanup EXIT INT TERM
mkdir -p "$D/home"
echo "answer hello" > "$D/replies"
HOME=$D/home ./splinter --no-config --autonomous --model m \
--script "$D/replies" --mcp-server-listen 127.0.0.1 \
--mcp-listen-port "$port" > "$D/srv.out" 2>&1 &
pid=$!
i=0
while [ $i -lt 50 ]; do
if python3 - "$port" <<'PY'
import socket, sys
s = socket.socket(); s.settimeout(0.2)
try:
s.connect(("127.0.0.1", int(sys.argv[1])))
except OSError:
sys.exit(1)
finally:
s.close()
PY
then
break
fi
i=$((i + 1)); sleep 0.1
done
python3 - "$port" <<'PY'
import json, socket, sys
s = socket.create_connection(("127.0.0.1", int(sys.argv[1])), 5)
# a turn is a turn: the script transport is fast, but the machine may be busy
s.settimeout(120)
f = s.makefile("rw", encoding="utf-8")
def req(i, method, params=None):
o = {"jsonrpc": "2.0", "id": i, "method": method}
if params is not None:
o["params"] = params
f.write(json.dumps(o) + "\n"); f.flush()
return json.loads(f.readline())
def call(i, name, args):
r = req(i, "tools/call", {"name": name, "arguments": args})
if "error" in r:
print("error:", r["error"], file=sys.stderr); sys.exit(1)
return r["result"]["content"][0]["text"]
init = req(1, "initialize", {})
assert init["result"]["serverInfo"]["name"] == "splinter", init
tools = [t["name"] for t in req(2, "tools/list")["result"]["tools"]]
for want in ("splinter_sessions", "splinter_state", "splinter_models",
"splinter_history", "splinter_say", "splinter_steer",
"splinter_cancel", "splinter_approve"):
assert want in tools, (want, tools)
state = call(3, "splinter_state", {})
assert "model: m" in state, state
assert "session: sess-" in state, state
say = call(4, "splinter_say", {"text": "hi"})
assert "hello" in say, say
hist = call(5, "splinter_history", {"limit": 10})
assert "[user] hi" in hist and "[assistant] hello" in hist, hist
sessions = call(6, "splinter_sessions", {})
assert "sess-" in sessions and "*" in sessions, sessions
models = call(7, "splinter_models", {})
assert "local/m" in models, models
cancel = call(8, "splinter_cancel", {})
assert "no turn is running" in cancel, cancel
print("test_mcpsession: ok")
PY