run.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/usr/bin/env bash
  2. # Offline self-test for the mapbox-ops skill — structure, frontmatter, script contract.
  3. #
  4. # Usage: tests/run.sh
  5. # Input: none (self-contained; no network, no playwright, no browser)
  6. # Output: TAP-ish progress on stderr; final PASS/FAIL line.
  7. # Exit: 0 all pass (or skipped on unsupported platform), 1 any failure.
  8. #
  9. # Examples:
  10. # tests/run.sh
  11. # bash skills/mapbox-ops/tests/run.sh
  12. set -uo pipefail
  13. here="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
  14. fail=0
  15. pass=0
  16. note() { printf ' %s %s\n' "$1" "$2" >&2; }
  17. ok() { pass=$((pass+1)); note "ok " "$1"; }
  18. bad() { fail=$((fail+1)); note "FAIL" "$1"; }
  19. # Resolve a *working* python (python3, else python). The bare `command -v` is not
  20. # enough on Windows, where `python3` is a Microsoft Store stub that exits nonzero.
  21. PY=""
  22. for cand in python3 python; do
  23. if command -v "$cand" >/dev/null 2>&1 && "$cand" --version >/dev/null 2>&1; then
  24. PY="$cand"; break
  25. fi
  26. done
  27. if [ -z "$PY" ]; then
  28. echo "SKIP: no working python interpreter on this platform" >&2
  29. exit 0
  30. fi
  31. # 1. Required directories exist
  32. for d in scripts references assets tests; do
  33. [ -d "$here/$d" ] && ok "dir $d/ exists" || bad "missing dir $d/"
  34. done
  35. # 2. SKILL.md frontmatter house rules (SKILL-SUBAGENT-REFERENCE)
  36. skill="$here/SKILL.md"
  37. if [ -f "$skill" ]; then
  38. ok "SKILL.md present"
  39. grep -q '^name: mapbox-ops$' "$skill" && ok "name matches directory" || bad "name != mapbox-ops"
  40. grep -q '^license: MIT$' "$skill" && ok "license: MIT" || bad "missing license: MIT"
  41. grep -q '^ author: claude-mods$' "$skill" && ok "metadata.author" || bad "missing metadata.author"
  42. else
  43. bad "SKILL.md missing"
  44. fi
  45. # 3. Every reference cited from SKILL.md actually exists, and vice-versa
  46. for ref in "$here"/references/*.md; do
  47. base="references/$(basename "$ref")"
  48. grep -qF "$base" "$skill" && ok "cited: $base" || bad "uncited reference: $base"
  49. done
  50. # 4. Bundled resources referenced from SKILL.md exist on disk
  51. for res in assets/circular_image_marker.js scripts/screenshot_map.py; do
  52. [ -f "$here/$res" ] && ok "resource present: $res" || bad "missing resource: $res"
  53. done
  54. # 5. screenshot_map.py — script contract (§10)
  55. py="$here/scripts/screenshot_map.py"
  56. if [ -f "$py" ]; then
  57. "$PY" -m py_compile "$py" && ok "py_compile clean" || bad "py_compile failed"
  58. head -25 "$py" | grep -Eq '^(# )?Examples:' && ok "has Examples block" || bad "no Examples block"
  59. "$PY" "$py" --help >/dev/null 2>&1 && ok "--help exits 0" || bad "--help nonzero"
  60. # USAGE (exit 2) on a file:// URL — happens before the playwright import, so this is offline-safe
  61. "$PY" "$py" "file:///tmp/x.html" /tmp/o.png >/dev/null 2>&1
  62. [ "$?" -eq 2 ] && ok "file:// URL → exit 2 (USAGE)" || bad "file:// URL did not exit 2"
  63. else
  64. bad "screenshot_map.py missing"
  65. fi
  66. # 5b. check-mapbox-facts.py — staleness verifier contract (§7, §10), offline-safe
  67. facts="$here/scripts/check-mapbox-facts.py"
  68. if [ -f "$facts" ]; then
  69. ok "resource present: scripts/check-mapbox-facts.py"
  70. "$PY" -m py_compile "$facts" && ok "facts: py_compile clean" || bad "facts: py_compile failed"
  71. head -30 "$facts" | grep -Eq '^# +Examples:' && ok "facts: has Examples block" || bad "facts: no Examples block"
  72. "$PY" "$facts" --help >/dev/null 2>&1 && ok "facts: --help exits 0" || bad "facts: --help nonzero"
  73. # Offline mode must pass on the skill's own content (internal consistency).
  74. "$PY" "$facts" --offline >/dev/null 2>&1 && ok "facts: --offline consistent (exit 0)" || bad "facts: --offline found drift"
  75. # Bad flag → USAGE (exit 2); stays offline.
  76. "$PY" "$facts" --bogus >/dev/null 2>&1
  77. [ "$?" -eq 2 ] && ok "facts: bad flag → exit 2 (USAGE)" || bad "facts: bad flag did not exit 2"
  78. # stdout is data-only: --offline --json must emit parseable JSON with no stderr leakage.
  79. "$PY" "$facts" --offline --json -q 2>/dev/null | "$PY" -c 'import json,sys; d=json.load(sys.stdin); assert d["meta"]["schema"].startswith("claude-mods.mapbox-ops")' \
  80. && ok "facts: --json envelope parses (stdout clean)" || bad "facts: --json envelope broken"
  81. # cited from SKILL.md
  82. grep -qF "scripts/check-mapbox-facts.py" "$skill" && ok "facts: cited from SKILL.md" || bad "facts: uncited"
  83. else
  84. bad "check-mapbox-facts.py missing"
  85. fi
  86. # 6. circular_image_marker.js — node --check if node present (optional)
  87. js="$here/assets/circular_image_marker.js"
  88. if command -v node >/dev/null 2>&1; then
  89. node --check "$js" >/dev/null 2>&1 && ok "js syntax (node --check)" || bad "js syntax error"
  90. else
  91. note "skip" "node absent — js syntax check skipped"
  92. fi
  93. echo "mapbox-ops self-test: $pass passed, $fail failed" >&2
  94. [ "$fail" -eq 0 ]