skill_create, skill_update, skill_clone und skill_delete committen ihre Änderung selbst (skilld: create/update/… <name>). Dazu vier Werkzeuge: skill_history, skill_diff, skill_sync (pull --rebase, push:true für die Gegenrichtung). Ist die Bibliothek kein Repository, behauptet das Werkzeug keinen Verlauf, sondern sagt es; beim Start steht im Log, in welchem Modus skilld läuft. Dazu --http PORT über den gemeinsamen Transport aus libmcp. tests/git.py legt ein echtes Repo mit bare-Remote an und prüft fünf Fälle, darunter eine Änderung von Hand, die der nächste Schreibvorgang mitschreibt.
129 lines
5.3 KiB
Python
129 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": 8, "method": "tools/call",
|
|
"params": {"name": "skill_assign", "arguments": {
|
|
"name": "audio-mastering", "profile": "coder"}}},
|
|
{"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) == 12,
|
|
"got %d answers for 12 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("eleven tools advertised", len(tools) == 11, 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)
|
|
|
|
asg = text_of(by_id.get(8, {}))
|
|
check("assign copies into the profile",
|
|
os.path.isfile(os.path.join(HOME, ".hermes/profiles/coder/skills/audio-mastering/SKILL.md")),
|
|
asg)
|
|
|
|
# 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)
|