test-sdd-workspace.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env bash
  2. # Tests for the SDD workspace: scripts/sdd-workspace resolves a self-ignoring
  3. # working-tree directory for SDD artifacts, and the SDD scripts write into it.
  4. set -euo pipefail
  5. SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
  6. REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
  7. SDD_SCRIPTS="$REPO_ROOT/skills/subagent-driven-development/scripts"
  8. FAILURES=0
  9. TEST_ROOT=""
  10. pass() { echo " [PASS] $1"; }
  11. fail() {
  12. echo " [FAIL] $1"
  13. FAILURES=$((FAILURES + 1))
  14. }
  15. cleanup() {
  16. if [[ -n "$TEST_ROOT" && -d "$TEST_ROOT" ]]; then
  17. rm -rf "$TEST_ROOT"
  18. fi
  19. }
  20. main() {
  21. echo "=== Test: sdd-workspace ==="
  22. TEST_ROOT="$(mktemp -d)"
  23. trap cleanup EXIT
  24. # Resolve repo to its physical path so string comparisons match the
  25. # helper's output (git rev-parse --show-toplevel resolves symlinks; on
  26. # macOS mktemp lives under /var -> /private/var).
  27. git init -q -b main "$TEST_ROOT/repo"
  28. local repo
  29. repo="$(cd "$TEST_ROOT/repo" && git rev-parse --show-toplevel)"
  30. local dir
  31. dir="$(cd "$repo" && "$SDD_SCRIPTS/sdd-workspace")"
  32. if [[ "$dir" == "$repo/.superpowers/sdd" ]]; then
  33. pass "prints <repo-root>/.superpowers/sdd"
  34. else
  35. fail "prints <repo-root>/.superpowers/sdd"
  36. echo " got: $dir"
  37. fi
  38. if [[ -f "$repo/.superpowers/sdd/.gitignore" && "$(cat "$repo/.superpowers/sdd/.gitignore")" == "*" ]]; then
  39. pass "self-ignoring .gitignore created with '*'"
  40. else
  41. fail "self-ignoring .gitignore created with '*'"
  42. fi
  43. printf 'x\n' > "$repo/.superpowers/sdd/artifact.md"
  44. local status
  45. status="$(cd "$repo" && git status --porcelain)"
  46. if [[ -z "$status" ]]; then
  47. pass "workspace invisible to git status"
  48. else
  49. fail "workspace invisible to git status"
  50. echo " status: $status"
  51. fi
  52. ( cd "$repo" && git add -A )
  53. local staged
  54. staged="$(cd "$repo" && git diff --cached --name-only)"
  55. if [[ -z "$staged" ]]; then
  56. pass "git add -A does not stage the workspace"
  57. else
  58. fail "git add -A does not stage the workspace"
  59. echo " staged: $staged"
  60. fi
  61. echo ""
  62. if [[ "$FAILURES" -ne 0 ]]; then
  63. echo "FAILED: $FAILURES assertion(s)."
  64. exit 1
  65. fi
  66. echo "PASS"
  67. }
  68. main "$@"