test-sdd-workspace.sh 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #!/usr/bin/env bash
  2. # Tests for the SDD workspace: scripts/sdd-workspace resolves a self-ignoring,
  3. # PER-PLAN working-tree directory for SDD artifacts, and the SDD scripts write
  4. # into their plan's directory.
  5. set -euo pipefail
  6. SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
  7. REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
  8. SDD_SCRIPTS="$REPO_ROOT/skills/subagent-driven-development/scripts"
  9. FAILURES=0
  10. TEST_ROOT=""
  11. pass() { echo " [PASS] $1"; }
  12. fail() {
  13. echo " [FAIL] $1"
  14. FAILURES=$((FAILURES + 1))
  15. }
  16. cleanup() {
  17. if [[ -n "$TEST_ROOT" && -d "$TEST_ROOT" ]]; then
  18. rm -rf "$TEST_ROOT"
  19. fi
  20. }
  21. main() {
  22. echo "=== Test: sdd-workspace ==="
  23. TEST_ROOT="$(mktemp -d)"
  24. trap cleanup EXIT
  25. # Resolve repo to its physical path so string comparisons match the
  26. # helper's output (git rev-parse --show-toplevel resolves symlinks; on
  27. # macOS mktemp lives under /var -> /private/var).
  28. git init -q -b main "$TEST_ROOT/repo"
  29. local repo
  30. repo="$(cd "$TEST_ROOT/repo" && git rev-parse --show-toplevel)"
  31. cat > "$repo/plan-a.md" <<'PLAN'
  32. # Plan A
  33. ## Task 1: First thing
  34. Do the first thing.
  35. PLAN
  36. cat > "$repo/plan-b.md" <<'PLAN'
  37. # Plan B
  38. ## Task 1: Other thing
  39. Do the other thing.
  40. PLAN
  41. # --- argument validation ---
  42. local rc=0
  43. (cd "$repo" && "$SDD_SCRIPTS/sdd-workspace" >/dev/null 2>&1) || rc=$?
  44. if [[ "$rc" -eq 2 ]]; then
  45. pass "sdd-workspace without a plan errors with exit 2"
  46. else
  47. fail "sdd-workspace without a plan errors with exit 2"
  48. echo " exit: $rc"
  49. fi
  50. rc=0
  51. (cd "$repo" && "$SDD_SCRIPTS/sdd-workspace" no-such-plan.md >/dev/null 2>&1) || rc=$?
  52. if [[ "$rc" -eq 2 ]]; then
  53. pass "sdd-workspace with a missing plan file errors with exit 2"
  54. else
  55. fail "sdd-workspace with a missing plan file errors with exit 2"
  56. echo " exit: $rc"
  57. fi
  58. # --- per-plan resolution ---
  59. local dir_a dir_b
  60. dir_a="$(cd "$repo" && "$SDD_SCRIPTS/sdd-workspace" plan-a.md)"
  61. dir_b="$(cd "$repo" && "$SDD_SCRIPTS/sdd-workspace" plan-b.md)"
  62. if [[ "$dir_a" == "$repo/.superpowers/sdd/plan-a" ]]; then
  63. pass "prints <repo-root>/.superpowers/sdd/<plan-basename>"
  64. else
  65. fail "prints <repo-root>/.superpowers/sdd/<plan-basename>"
  66. echo " got: $dir_a"
  67. fi
  68. if [[ "$dir_a" != "$dir_b" && -d "$dir_a" && -d "$dir_b" ]]; then
  69. pass "two plans resolve to two distinct directories"
  70. else
  71. fail "two plans resolve to two distinct directories"
  72. echo " a: $dir_a"
  73. echo " b: $dir_b"
  74. fi
  75. if [[ -f "$repo/.superpowers/sdd/.gitignore" && "$(cat "$repo/.superpowers/sdd/.gitignore")" == "*" ]]; then
  76. pass "self-ignoring .gitignore created at .superpowers/sdd/ with '*'"
  77. else
  78. fail "self-ignoring .gitignore created at .superpowers/sdd/ with '*'"
  79. fi
  80. printf 'x\n' > "$dir_a/artifact.md"
  81. local status
  82. status="$(cd "$repo" && git status --porcelain)"
  83. # plan-a.md/plan-b.md are intentionally untracked fixture files; only the
  84. # workspace must be invisible.
  85. if [[ "$status" != *".superpowers"* ]]; then
  86. pass "workspace invisible to git status"
  87. else
  88. fail "workspace invisible to git status"
  89. echo " status: $status"
  90. fi
  91. ( cd "$repo" && git add -A )
  92. local staged
  93. staged="$(cd "$repo" && git diff --cached --name-only)"
  94. if [[ "$staged" != *".superpowers"* ]]; then
  95. pass "git add -A does not stage the workspace"
  96. else
  97. fail "git add -A does not stage the workspace"
  98. echo " staged: $staged"
  99. fi
  100. # --- task-brief lands in its plan's directory ---
  101. local brief_out brief_path
  102. brief_out="$(cd "$repo" && "$SDD_SCRIPTS/task-brief" plan-a.md 1)"
  103. brief_path="$(printf '%s\n' "$brief_out" | sed -n 's/^wrote \(.*\): [0-9][0-9]* lines$/\1/p')"
  104. if [[ "$brief_path" == "$repo/.superpowers/sdd/plan-a/task-1-brief.md" ]]; then
  105. pass "task-brief writes its brief under the plan's workspace"
  106. else
  107. fail "task-brief writes its brief under the plan's workspace"
  108. echo " got: $brief_path"
  109. fi
  110. # --- review-package takes the plan first and lands in its directory ---
  111. local git_id=(-c user.email=t@example.com -c user.name=t -c commit.gpgsign=false)
  112. ( cd "$repo" \
  113. && git "${git_id[@]}" commit -qm c1 \
  114. && printf 'y\n' > f && git add f \
  115. && git "${git_id[@]}" commit -qm c2 )
  116. local rp_out rp_path
  117. rp_out="$(cd "$repo" && "$SDD_SCRIPTS/review-package" plan-a.md HEAD~1 HEAD)"
  118. rp_path="$(printf '%s\n' "$rp_out" | sed -n 's/^wrote \(.*\): [0-9].*$/\1/p')"
  119. case "$rp_path" in
  120. "$repo/.superpowers/sdd/plan-a/review-"*.diff)
  121. pass "review-package writes its diff under the plan's workspace" ;;
  122. *)
  123. fail "review-package writes its diff under the plan's workspace"
  124. echo " got: $rp_path"
  125. ;;
  126. esac
  127. rc=0
  128. (cd "$repo" && "$SDD_SCRIPTS/review-package" HEAD~1 HEAD >/dev/null 2>&1) || rc=$?
  129. if [[ "$rc" -eq 2 ]]; then
  130. pass "review-package without a plan errors with exit 2"
  131. else
  132. fail "review-package without a plan errors with exit 2"
  133. echo " exit: $rc"
  134. fi
  135. local rp_explicit
  136. rp_explicit="$(cd "$repo" && "$SDD_SCRIPTS/review-package" plan-a.md HEAD~1 HEAD "$TEST_ROOT/explicit.diff")"
  137. if [[ -s "$TEST_ROOT/explicit.diff" && "$rp_explicit" == *"$TEST_ROOT/explicit.diff"* ]]; then
  138. pass "review-package honors an explicit OUTFILE"
  139. else
  140. fail "review-package honors an explicit OUTFILE"
  141. echo " got: $rp_explicit"
  142. fi
  143. # --- Worktree isolation: a linked worktree resolves its own workspace ---
  144. local wt="$TEST_ROOT/wt"
  145. ( cd "$repo" && git worktree add -q "$wt" -b wt-feature )
  146. local wt_root wt_dir
  147. wt_root="$(cd "$wt" && git rev-parse --show-toplevel)"
  148. wt_dir="$(cd "$wt" && "$SDD_SCRIPTS/sdd-workspace" plan-a.md)"
  149. if [[ "$wt_dir" == "$wt_root/.superpowers/sdd/plan-a" && "$wt_dir" != "$dir_a" ]]; then
  150. pass "linked worktree resolves its own distinct workspace"
  151. else
  152. fail "linked worktree resolves its own distinct workspace"
  153. echo " main: $dir_a"
  154. echo " wt: $wt_dir"
  155. fi
  156. printf 'y\n' > "$wt_dir/artifact.md"
  157. local wt_status
  158. wt_status="$(cd "$wt" && git status --porcelain)"
  159. if [[ "$wt_status" != *".superpowers"* ]]; then
  160. pass "worktree workspace invisible to git status"
  161. else
  162. fail "worktree workspace invisible to git status"
  163. echo " status: $wt_status"
  164. fi
  165. echo ""
  166. if [[ "$FAILURES" -ne 0 ]]; then
  167. echo "FAILED: $FAILURES assertion(s)."
  168. exit 1
  169. fi
  170. echo "PASS"
  171. }
  172. main "$@"