test-executing-plans-scripts.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #!/usr/bin/env bash
  2. # Tests for executing-plans' bookkeeping helpers: scripts/task-start extracts
  3. # the brief and records BASE in one call; scripts/task-done runs the task's
  4. # test command, records the result in the ledger, and refuses to record a
  5. # failing task.
  6. set -euo pipefail
  7. SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
  8. REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
  9. EP_SCRIPTS="$REPO_ROOT/skills/executing-plans/scripts"
  10. FAILURES=0
  11. TEST_ROOT=""
  12. pass() { echo " [PASS] $1"; }
  13. fail() {
  14. echo " [FAIL] $1"
  15. FAILURES=$((FAILURES + 1))
  16. }
  17. cleanup() {
  18. if [[ -n "$TEST_ROOT" && -d "$TEST_ROOT" ]]; then
  19. rm -rf "$TEST_ROOT"
  20. fi
  21. }
  22. main() {
  23. echo "=== Test: executing-plans scripts ==="
  24. TEST_ROOT="$(mktemp -d)"
  25. trap cleanup EXIT
  26. git init -q -b main "$TEST_ROOT/repo"
  27. local repo
  28. repo="$(cd "$TEST_ROOT/repo" && git rev-parse --show-toplevel)"
  29. local git_id=(-c user.email=t@example.com -c user.name=t -c commit.gpgsign=false)
  30. cat > "$repo/plan.md" <<'PLAN'
  31. # Plan
  32. ## Task 1: First thing
  33. Do the first thing.
  34. ## Task 2: Second thing
  35. Do the second thing.
  36. PLAN
  37. ( cd "$repo" && git add plan.md && git "${git_id[@]}" commit -qm fixture )
  38. local base
  39. base="$(cd "$repo" && git rev-parse HEAD)"
  40. # --- task-start: argument validation ---
  41. local rc=0
  42. (cd "$repo" && "$EP_SCRIPTS/task-start" plan.md >/dev/null 2>&1) || rc=$?
  43. if [[ "$rc" -eq 2 ]]; then
  44. pass "task-start without a task number errors with exit 2"
  45. else
  46. fail "task-start without a task number errors with exit 2 (got $rc)"
  47. fi
  48. # --- task-start: brief path + BASE in one call ---
  49. local out
  50. out="$(cd "$repo" && "$EP_SCRIPTS/task-start" plan.md 1)"
  51. if [[ "$out" == *"brief: $repo/.superpowers/sdd/plan/task-1-brief.md"* ]]; then
  52. pass "task-start prints the brief path under the plan's workspace"
  53. else
  54. fail "task-start prints the brief path under the plan's workspace"
  55. echo " got: $out"
  56. fi
  57. if [[ "$out" == *"base: $base"* ]]; then
  58. pass "task-start prints BASE as the current HEAD"
  59. else
  60. fail "task-start prints BASE as the current HEAD"
  61. echo " got: $out"
  62. fi
  63. if [[ -s "$repo/.superpowers/sdd/plan/task-1-brief.md" ]]; then
  64. pass "task-start writes the brief file"
  65. else
  66. fail "task-start writes the brief file"
  67. fi
  68. # --- task-done: records a passing task ---
  69. ( cd "$repo" && echo x > work.txt && git add work.txt && git "${git_id[@]}" commit -qm "task 1" )
  70. local head
  71. head="$(cd "$repo" && git rev-parse HEAD)"
  72. out="$(cd "$repo" && "$EP_SCRIPTS/task-done" plan.md 1 "$base" -- sh -c 'echo "Ran 3 tests"; echo OK')"
  73. rc=$?
  74. local ledger="$repo/.superpowers/sdd/plan/progress.md"
  75. local expected="Task 1: complete (commits ${base:0:7}..${head:0:7}, tests: sh -c 'echo \"Ran 3 tests\"; echo OK' → OK)"
  76. if [[ -f "$ledger" ]] && grep -qF "$expected" "$ledger"; then
  77. pass "task-done appends the completion line with commit range and test result"
  78. else
  79. fail "task-done appends the completion line with commit range and test result"
  80. echo " expected: $expected"
  81. echo " ledger:"; sed 's/^/ /' "$ledger" 2>/dev/null || echo " (missing)"
  82. fi
  83. if [[ "$out" == *"OK"* ]]; then
  84. pass "task-done prints the tail of the test output"
  85. else
  86. fail "task-done prints the tail of the test output"
  87. echo " got: $out"
  88. fi
  89. if [[ -s "$repo/.superpowers/sdd/plan/task-1-tests.log" ]]; then
  90. pass "task-done keeps the full test output in the workspace"
  91. else
  92. fail "task-done keeps the full test output in the workspace"
  93. fi
  94. # --- task-done: refuses to record a failing task ---
  95. rc=0
  96. out="$(cd "$repo" && "$EP_SCRIPTS/task-done" plan.md 2 "$head" -- sh -c 'echo "FAILED (errors=1)"; exit 1' 2>&1)" || rc=$?
  97. if [[ "$rc" -ne 0 ]]; then
  98. pass "task-done exits non-zero when the test command fails"
  99. else
  100. fail "task-done exits non-zero when the test command fails"
  101. fi
  102. if ! grep -q "Task 2: complete" "$ledger"; then
  103. pass "task-done does not record a failing task as complete"
  104. else
  105. fail "task-done does not record a failing task as complete"
  106. fi
  107. if [[ "$out" == *"FAILED"* ]]; then
  108. pass "task-done shows the failing output"
  109. else
  110. fail "task-done shows the failing output"
  111. echo " got: $out"
  112. fi
  113. echo
  114. if [[ "$FAILURES" -eq 0 ]]; then
  115. echo "PASS"
  116. else
  117. echo "FAIL ($FAILURES)"
  118. exit 1
  119. fi
  120. }
  121. main "$@"