# Scripts को सामान्य कोड की तरह परखना — Claude Code Skills और SKILL.md

Source: https://www.geekswithgeeks.com/hi/claude-code-skills/t-scripts

> Scripts को fixtures पर चलाएँ और आउटपुट व exit codes जाँचें।

## Scripts परखने योग्य हिस्सा हैं

Skill के भीतर की scripts सामान्य प्रोग्राम हैं, इसलिए उन्हें किसी भी कोड की तरह परखें: functions के **unit tests**, और **command-स्तर tests** जो script को नमूना arguments से चलाकर **exit code** और **आउटपुट** जाँचें (Claude यही देखेगा)। **अप्रिय रास्ते** कवर करें: ग़ायब arguments, न मौजूद file, ग़लत इनपुट, विफल network call। **Fixtures** (छोटे सहेजे इनपुट) उपयोग करें ताकि tests तेज़ हों और network न चाहिए। सुनिश्चित करें कि error संदेश user (और agent) को बताएँ क्या करना है। Skill साझा repository में हो तो tests CI में चलाएँ। Scripts को अच्छी तरह परखने का अर्थ है कि skill का निश्चित हिस्सा वाक़ई भरोसेमंद है, और केवल मॉडल का विवेक आँकने को बचता है।

## Command-स्तर test harness, चलाकर

मैंने यह सादे Python 3 (सिर्फ़ standard library) से चलाया। Harness छोटी सहायक script लिखता है, उसे तीन argument समूहों से चलाता है, और exit code तथा JSON आउटपुट दोनों जाँचता है। ऋणात्मक इनपुट code 2 से बाहर निकलता है और फिर भी parse-योग्य JSON छापता है। तीनों मामले पास होते हैं।

```python
import subprocess, sys, tempfile, os, json, textwrap

SCRIPT = textwrap.dedent("""
    import sys, json
    n = int(sys.argv[1])
    print(json.dumps({"n": n, "even": n % 2 == 0}))
    sys.exit(0 if n >= 0 else 2)          # exit code 2 = invalid input
""")
CASES = [(["4"], 0, {"n": 4, "even": True}), (["7"], 0, {"n": 7, "even": False}), (["-1"], 2, {"n": -1, "even": False})]

with tempfile.TemporaryDirectory() as d:
    path = os.path.join(d, "helper.py"); open(path, "w").write(SCRIPT)
    for args, want_code, want_json in CASES:
        r = subprocess.run([sys.executable, path, *args], capture_output=True, text=True)
        ok = r.returncode == want_code and json.loads(r.stdout) == want_json
        print(f"helper.py {args[0]:>3} -> exit {r.returncode}, output {r.stdout.strip()}   {'PASS' if ok else 'FAIL'}")

```

Output:

```
helper.py   4 -> exit 0, output {"n": 4, "even": true}   PASS
helper.py   7 -> exit 0, output {"n": 7, "even": false}   PASS
helper.py  -1 -> exit 2, output {"n": -1, "even": false}   PASS
```

## Network नहीं, fixtures उपयोग करें

सहेजे नमूना इनपुट script tests को तेज़ और दोहराने योग्य रखते हैं।

**Quiz:** Command-स्तर script test को क्या जाँचना चाहिए?

- [ ] आउटपुट का रंग
- [ ] सिर्फ़ कि file मौजूद है
- [x] Exit code और वह आउटपुट जो agent देखेगा, error मामलों समेत
- [ ] कुछ नहीं; scripts को tests नहीं चाहिए

*Answer:* Exit code और वह आउटपुट जो agent देखेगा, error मामलों समेत. Exit codes और आउटपुट script का agent के साथ अनुबंध हैं।
