91 lines
4.3 KiB
Python
91 lines
4.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Automatische Vorprüfung des Plugins (Tests skill2plugin.1 bis .4), vor dem Lauf in echter Installation (bestand2plugin.1 bis .3).
|
|
|
|
Aufruf: python3 skill/tests/skill2plugin.py (aus dem Projektordner)
|
|
Ausgabe je Test `- id: ✓|✗ Notiz`, Exit-Code 1 wenn einer ✗ ist.
|
|
"""
|
|
import json
|
|
import os
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import time
|
|
import urllib.request
|
|
|
|
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
|
SKILL = os.path.join(ROOT, "skill")
|
|
alle = []
|
|
|
|
|
|
def melde(tid, ok, notiz):
|
|
alle.append(ok)
|
|
print(f"- {tid}: {'✓' if ok else '✗'} {notiz}")
|
|
|
|
|
|
def main():
|
|
# .1 Manifeste zeigen aufeinander
|
|
fehler = []
|
|
try:
|
|
m = json.load(open(os.path.join(ROOT, ".claude-plugin", "marketplace.json"), encoding="utf-8"))
|
|
src = m["plugins"][0]["source"]
|
|
pj = json.load(open(os.path.join(ROOT, src, ".claude-plugin", "plugin.json"), encoding="utf-8"))
|
|
if pj["name"] != m["plugins"][0]["name"]:
|
|
fehler.append("Name in marketplace.json und plugin.json verschieden")
|
|
for f in ("commands/viewer.md", "skills/projekt-steuerung/SKILL.md", "skills/projekt-steuerung/ARBEITSWEISE.md"):
|
|
if not os.path.exists(os.path.join(ROOT, src, f)):
|
|
fehler.append(f"fehlt: {f}")
|
|
except Exception as e: # noqa: BLE001
|
|
fehler.append(str(e))
|
|
melde("skill2plugin.1", not fehler, "Marketplace zeigt auf ./skill, plugin.json und alle Dateien da" if not fehler else "; ".join(fehler))
|
|
|
|
# .2 jeder Pfad mit ${CLAUDE_PLUGIN_ROOT} in Skill und Befehl existiert
|
|
fehler = []
|
|
for f in ("skills/projekt-steuerung/SKILL.md", "commands/viewer.md"):
|
|
text = open(os.path.join(SKILL, f), encoding="utf-8").read()
|
|
for pfad in re.findall(r"\$\{CLAUDE_PLUGIN_ROOT\}/([\w./-]+)", text):
|
|
if not os.path.exists(os.path.join(SKILL, pfad)):
|
|
fehler.append(f"{f}: {pfad} fehlt")
|
|
if "check_ids" in text:
|
|
fehler.append(f"{f}: verweist noch auf check_ids.py")
|
|
melde("skill2plugin.2", not fehler, "alle Pfade aus Skill und Befehl existieren, kein Verweis auf check_ids.py" if not fehler else "; ".join(fehler))
|
|
|
|
# .3 mitgelieferter Viewer ist der gebaute aus viewer/ und läuft
|
|
fehler = []
|
|
if subprocess.run(["diff", "-r", os.path.join(ROOT, "viewer", "dist"), os.path.join(SKILL, "viewer", "dist")], capture_output=True).returncode != 0:
|
|
fehler.append("skill/viewer/dist weicht von viewer/dist ab (skill/build.sh ausführen)")
|
|
if subprocess.run(["diff", os.path.join(ROOT, "viewer", "server.mjs"), os.path.join(SKILL, "viewer", "server.mjs")], capture_output=True).returncode != 0:
|
|
fehler.append("server.mjs weicht ab")
|
|
port = "4391"
|
|
proc = subprocess.Popen(["node", os.path.join(SKILL, "viewer", "server.mjs"), ROOT], env={**os.environ, "PORT": port}, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
try:
|
|
html = ""
|
|
for _ in range(30):
|
|
try:
|
|
html = urllib.request.urlopen(f"http://127.0.0.1:{port}/", timeout=2).read().decode()
|
|
break
|
|
except Exception: # noqa: BLE001
|
|
time.sleep(0.2)
|
|
if "<div" not in html:
|
|
fehler.append("Viewer liefert keine Oberfläche")
|
|
finally:
|
|
proc.terminate()
|
|
melde("skill2plugin.3", not fehler, "mitgelieferter Viewer entspricht viewer/dist, startet und liefert die Oberfläche (nur Abruf, nicht im Browser angesehen)" if not fehler else "; ".join(fehler))
|
|
|
|
# .4 init.sh legt Git-Repo an, OHNE_GIT verhindert es
|
|
base = tempfile.mkdtemp(prefix="skill2plugin-")
|
|
try:
|
|
a, b = os.path.join(base, "a"), os.path.join(base, "b")
|
|
subprocess.run(["bash", os.path.join(SKILL, "scripts", "init.sh"), "T", a, "P-0007"], capture_output=True)
|
|
subprocess.run(["bash", os.path.join(SKILL, "scripts", "init.sh"), "T", b, "P-0007"], capture_output=True, env={**os.environ, "OHNE_GIT": "1"})
|
|
ok = os.path.isdir(os.path.join(a, ".git")) and not os.path.exists(os.path.join(b, ".git"))
|
|
melde("skill2plugin.4", ok, "init.sh legt ohne Git-Repo eines an, mit OHNE_GIT=1 nicht" if ok else "Git-Verhalten von init.sh falsch")
|
|
finally:
|
|
shutil.rmtree(base, ignore_errors=True)
|
|
sys.exit(0 if all(alle) else 1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|