Der Export an ein beliebiges Ziel war unter ProtectSystem=strict ohnehin nicht möglich — jeder Pfad außerhalb der Bibliothek ist für den Dienst schreibgeschützt, und das ist richtig so. Statt die Sandbox aufzuweichen, fällt das Werkzeug weg: wer einen Skill woandershin braucht, liest ihn mit skill_load und schreibt seine Kopie selbst. Damit zehn Werkzeuge. Der Test prüft jetzt, dass nach allen Aufrufen unter HOME nichts entstanden ist — die Zusage "keine Schreibzugriffe außerhalb der Bibliothek" als Prüfung, nicht als Satz im README.
127 lines
5.3 KiB
Python
127 lines
5.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Prove skilld's MCP surface: handshake, every tool, and the notification rule."""
|
|
import json
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
|
|
BIN = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "skilld")
|
|
LIB = tempfile.mkdtemp(prefix="skilllib-test-")
|
|
HOME = tempfile.mkdtemp(prefix="skilld-home-")
|
|
fails = []
|
|
|
|
|
|
def run(lines):
|
|
env = dict(os.environ)
|
|
env["SKILLLIB"] = LIB
|
|
env["HOME"] = HOME
|
|
proc = subprocess.run([BIN], input="\n".join(json.dumps(x) for x in lines) + "\n",
|
|
capture_output=True, text=True, env=env, timeout=60)
|
|
out = [l for l in proc.stdout.splitlines() if l.strip()]
|
|
return [json.loads(l) for l in out]
|
|
|
|
|
|
def check(name, cond, detail=""):
|
|
if cond:
|
|
print("PASS %s" % name)
|
|
else:
|
|
print("FAIL %s %s" % (name, detail))
|
|
fails.append(name)
|
|
|
|
|
|
msgs = [
|
|
{"jsonrpc": "2.0", "id": 1, "method": "initialize",
|
|
"params": {"protocolVersion": "2024-11-05", "capabilities": {}}},
|
|
{"jsonrpc": "2.0", "method": "notifications/initialized"},
|
|
{"jsonrpc": "2.0", "id": 2, "method": "tools/list"},
|
|
{"jsonrpc": "2.0", "id": 3, "method": "tools/call",
|
|
"params": {"name": "skill_create", "arguments": {
|
|
"name": "netbsd-kernel-build",
|
|
"description": "Use when building a NetBSD kernel after editing sys files.",
|
|
"body": "# NetBSD kernel build\n\nRun build.sh tools then kernel=GENERIC.",
|
|
"tags": "netbsd,kernel,build"}}},
|
|
{"jsonrpc": "2.0", "id": 4, "method": "tools/call",
|
|
"params": {"name": "skill_create", "arguments": {
|
|
"name": "audio-mastering",
|
|
"description": "Use when mastering audio to streaming loudness targets.",
|
|
"body": "# Mastering\n\nTarget -14 LUFS integrated, true peak -1 dBTP.",
|
|
"tags": "audio,mastering,lufs"}}},
|
|
{"jsonrpc": "2.0", "id": 5, "method": "tools/call",
|
|
"params": {"name": "skill_search", "arguments": {"query": "build a netbsd kernel"}}},
|
|
{"jsonrpc": "2.0", "id": 6, "method": "tools/call",
|
|
"params": {"name": "skill_load", "arguments": {"name": "audio-mastering"}}},
|
|
{"jsonrpc": "2.0", "id": 7, "method": "tools/call",
|
|
"params": {"name": "skill_update", "arguments": {
|
|
"name": "audio-mastering", "append": "Check with ffmpeg ebur128 before delivery."}}},
|
|
{"jsonrpc": "2.0", "id": 9, "method": "tools/call",
|
|
"params": {"name": "skill_clone", "arguments": {
|
|
"name": "audio-mastering", "new_name": "audio-mastering-dnb"}}},
|
|
{"jsonrpc": "2.0", "id": 10, "method": "tools/call",
|
|
"params": {"name": "skill_list", "arguments": {}}},
|
|
{"jsonrpc": "2.0", "id": 11, "method": "tools/call",
|
|
"params": {"name": "skill_delete", "arguments": {"name": "audio-mastering-dnb"}}},
|
|
{"jsonrpc": "2.0", "id": 12, "method": "tools/call",
|
|
"params": {"name": "nope", "arguments": {}}},
|
|
]
|
|
|
|
res = run(msgs)
|
|
by_id = {r.get("id"): r for r in res}
|
|
|
|
check("one answer per request, none for the notification", len(res) == 11,
|
|
"got %d answers for 11 requests + 1 notification" % len(res))
|
|
check("initialize names skilld",
|
|
by_id.get(1, {}).get("result", {}).get("serverInfo", {}).get("name") == "skilld")
|
|
|
|
tools = by_id.get(2, {}).get("result", {}).get("tools", [])
|
|
names = {t["name"] for t in tools}
|
|
check("ten tools advertised", len(tools) == 10, sorted(names))
|
|
check("search description carries the trigger",
|
|
any("skill_search" == t["name"] and len(t["description"]) > 200 for t in tools))
|
|
|
|
def text_of(r):
|
|
try:
|
|
return r["result"]["content"][0]["text"]
|
|
except Exception:
|
|
return ""
|
|
|
|
check("create writes the skill", "created" in text_of(by_id.get(3, {})))
|
|
check("create refuses nothing silently", os.path.isdir(os.path.join(LIB, "netbsd-kernel-build")))
|
|
|
|
hits = json.loads(text_of(by_id.get(5, {})))
|
|
check("search ranks the kernel skill first",
|
|
hits["results"] and hits["results"][0]["name"] == "netbsd-kernel-build",
|
|
json.dumps(hits.get("results", [])[:2]))
|
|
check("search excludes the unrelated skill", all(r["name"] != "audio-mastering" for r in hits["results"]))
|
|
|
|
loaded = text_of(by_id.get(6, {}))
|
|
check("load returns the body", "-14 LUFS" in loaded, loaded[:80])
|
|
|
|
upd = text_of(by_id.get(7, {}))
|
|
check("update appends", "updated" in upd)
|
|
|
|
# Der Dienst schreibt ausschließlich in seine Bibliothek: nach allen Aufrufen ist unter
|
|
# HOME nichts entstanden (HOME ist in diesem Test die Umgebung des Dienstes).
|
|
check("the service writes nothing outside its library",
|
|
not os.path.exists(os.path.join(HOME, "exported")),
|
|
"something appeared under HOME: %s" % sorted(os.listdir(HOME)))
|
|
|
|
# the variant is proven by the inventory, because the delete below removes it
|
|
# before the checks run - the skill_list answer was taken while it existed
|
|
lst_names = []
|
|
_lst = json.loads(text_of(by_id.get(10, {})))
|
|
lst_names = [x["name"] for x in _lst.get("skills", [])]
|
|
check("clone makes the variant", "audio-mastering-dnb" in lst_names, lst_names)
|
|
|
|
check("list counts three skills", _lst.get("total") == 3, _lst.get("total"))
|
|
|
|
check("delete removes it", not os.path.exists(os.path.join(LIB, "audio-mastering-dnb")))
|
|
check("unknown tool is an error", by_id.get(12, {}).get("error", {}).get("code") == -32601)
|
|
|
|
shutil.rmtree(LIB, ignore_errors=True)
|
|
shutil.rmtree(HOME, ignore_errors=True)
|
|
print()
|
|
print("FAILURES: %d" % len(fails))
|
|
sys.exit(1 if fails else 0)
|