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.
135 lines
5.3 KiB
Python
Executable File
135 lines
5.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""skilld muss Git benutzen: jede Änderung festgeschrieben, Verlauf abfragbar.
|
|
|
|
Der Test legt ein leeres Repository an, hängt ein bare-Repo als "remote" daneben
|
|
und prüft über MCP:
|
|
|
|
1. Anlegen einer Fähigkeit erzeugt einen Commit
|
|
2. Ändern erzeugt einen zweiten Commit, der Verlauf nennt beide
|
|
3. skill_diff zeigt, was von Hand geändert wurde, und der nächste skilld-Schreib-
|
|
vorgang schreibt es mit fest
|
|
4. skill_sync --push bringt die Commits ins Remote
|
|
5. ohne Repository sagt skilld ehrlich, dass nichts versioniert wird
|
|
"""
|
|
import json
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
BIN = os.path.join(HERE, "..", "skilld")
|
|
failures = []
|
|
|
|
|
|
def call(payload, n=1):
|
|
p = subprocess.run([BIN], input=json.dumps(payload) + "\n",
|
|
capture_output=True, text=True, env=os.environ.copy(), timeout=60)
|
|
lines = [l for l in p.stdout.splitlines() if l.strip()]
|
|
if len(lines) < n:
|
|
raise RuntimeError(f"keine Antwort: rc={p.returncode} err={p.stderr[-300:]}")
|
|
return [json.loads(l) for l in lines[:n]]
|
|
|
|
|
|
def tool(name, args, lib):
|
|
env = os.environ.copy()
|
|
env["SKILLLIB"] = lib
|
|
p = subprocess.run([BIN], input=json.dumps({
|
|
"jsonrpc": "2.0", "id": 1, "method": "tools/call",
|
|
"params": {"name": name, "arguments": args}}) + "\n",
|
|
capture_output=True, text=True, env=env, timeout=120)
|
|
line = [l for l in p.stdout.splitlines() if l.strip()]
|
|
if not line:
|
|
raise RuntimeError(f"keine Antwort auf {name}: {p.stderr[-300:]}")
|
|
d = json.loads(line[0])
|
|
if "error" in d:
|
|
return {"error": d["error"]}
|
|
content = d["result"].get("content", [])
|
|
return {"text": "".join(c.get("text", "") for c in content),
|
|
"isError": bool(d["result"].get("isError"))}
|
|
|
|
|
|
def git(lib, *args):
|
|
return subprocess.run(["git", "-C", lib] + list(args), capture_output=True, text=True)
|
|
|
|
|
|
def main():
|
|
work = tempfile.mkdtemp(prefix="skilld-git-")
|
|
lib = os.path.join(work, "skilllib")
|
|
remote = os.path.join(work, "remote.git")
|
|
os.makedirs(lib)
|
|
|
|
git(lib, "init", "-q")
|
|
git(lib, "config", "user.name", "test")
|
|
git(lib, "config", "user.email", "test@local")
|
|
git(lib, "branch", "-M", "main")
|
|
git(lib, "commit", "-q", "--allow-empty", "-m", "empty")
|
|
subprocess.run(["git", "init", "-q", "--bare", remote], check=True)
|
|
git(lib, "remote", "add", "origin", remote)
|
|
git(lib, "push", "-q", "-u", "origin", "HEAD:main")
|
|
|
|
try:
|
|
# 1. Anlegen -> Commit
|
|
r = tool("skill_create", {"name": "git-probe", "description": "Use when testing git",
|
|
"body": "# Zweck\nPrüfen.\n"}, lib)
|
|
if r.get("isError"):
|
|
failures.append(f"skill_create: {r}")
|
|
n = git(lib, "rev-list", "--count", "HEAD").stdout.strip()
|
|
if n != "2":
|
|
failures.append(f"nach dem Anlegen stehen {n} Commits statt 2")
|
|
|
|
# 2. Ändern -> zweiter Commit
|
|
r = tool("skill_update", {"name": "git-probe", "append": "\n## Neu\nMehr.\n"}, lib)
|
|
if r.get("isError"):
|
|
failures.append(f"skill_update: {r}")
|
|
n = git(lib, "rev-list", "--count", "HEAD").stdout.strip()
|
|
if n != "3":
|
|
failures.append(f"nach dem Ändern stehen {n} Commits statt 3")
|
|
|
|
r = tool("skill_history", {"name": "git-probe"}, lib)
|
|
text = r.get("text", "")
|
|
if "create git-probe" not in text or "update git-probe" not in text:
|
|
failures.append(f"Verlauf nennt die Änderungen nicht: {text[:200]}")
|
|
|
|
# 3. Änderung von Hand -> skill_diff sieht sie, der nächste Schreibvorgang nimmt sie mit
|
|
with open(os.path.join(lib, "git-probe", "SKILL.md"), "a") as f:
|
|
f.write("\n## Von Hand\n")
|
|
r = tool("skill_diff", {"name": "git-probe"}, lib)
|
|
if "SKILL.md" not in r.get("text", ""):
|
|
failures.append(f"skill_diff zeigt die Änderung nicht: {r}")
|
|
tool("skill_update", {"name": "git-probe", "append": "\n## Nochwas\n"}, lib)
|
|
st = git(lib, "status", "--porcelain").stdout.strip()
|
|
if st:
|
|
failures.append(f"nach dem Schreiben bleibt etwas offen: {st}")
|
|
|
|
# 4. Abgleich mit dem Remote
|
|
r = tool("skill_sync", {"push": True}, lib)
|
|
if r.get("isError"):
|
|
failures.append(f"skill_sync push: {r}")
|
|
log_remote = subprocess.run(["git", "-C", remote, "log", "--oneline", "main"],
|
|
capture_output=True, text=True).stdout
|
|
if "update git-probe" not in log_remote:
|
|
failures.append(f"das Remote kennt die Änderung nicht: {log_remote[:200]}")
|
|
|
|
# 5. ohne Repository ehrlich bleiben
|
|
plain = os.path.join(work, "plainlib")
|
|
os.makedirs(plain)
|
|
r = tool("skill_history", {}, plain)
|
|
if not r.get("isError"):
|
|
failures.append(f"ohne Repository wurde trotzdem ein Verlauf behauptet: {r.get('text','')[:120]}")
|
|
finally:
|
|
shutil.rmtree(work, ignore_errors=True)
|
|
|
|
if failures:
|
|
print("FAIL")
|
|
for f in failures:
|
|
print(" -", f)
|
|
sys.exit(1)
|
|
print("PASS: 5 Prüfungen — Commit beim Anlegen, Commit beim Ändern, Verlauf, "
|
|
"Handänderung erkannt und mitgeschrieben, Push ins Remote, ehrlich ohne Repo")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|