import json, sys, subprocess

data = json.loads(sys.stdin.read())

# Nur nach Datei-Änderungen prüfen
if data.get("tool_name") in ["Write", "Edit"]:
    results = []
    
    # Tests
    r = subprocess.run(["npm", "test", "--", "--passWithNoTests"], capture_output=True)
    results.append(("Tests", r.returncode == 0))
    
    # Linting
    r = subprocess.run(["npm", "run", "lint"], capture_output=True)
    results.append(("Lint", r.returncode == 0))
    
    failed = [name for name, ok in results if not ok]
    if failed:
        print(f"⚠️ Quality Gate FAILED: {', '.join(failed)}", file=sys.stderr)
        print("Bitte Fehler beheben bevor du fortfährst.", file=sys.stderr)
