test-task-brief.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
  4. REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
  5. TASK_BRIEF="$REPO_ROOT/skills/subagent-driven-development/scripts/task-brief"
  6. FAILURES=0
  7. TEST_ROOT=""
  8. pass() {
  9. echo " [PASS] $1"
  10. }
  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. extract_written_path() {
  21. local output="$1"
  22. printf '%s\n' "$output" | sed -n 's/^wrote \(.*\): [0-9][0-9]* lines$/\1/p'
  23. }
  24. assert_not_equals() {
  25. local actual="$1"
  26. local expected="$2"
  27. local description="$3"
  28. if [[ "$actual" != "$expected" ]]; then
  29. pass "$description"
  30. else
  31. fail "$description"
  32. echo " both were: $actual"
  33. fi
  34. }
  35. assert_file_contains() {
  36. local path="$1"
  37. local needle="$2"
  38. local description="$3"
  39. if grep -Fq -- "$needle" "$path"; then
  40. pass "$description"
  41. else
  42. fail "$description"
  43. echo " expected $path to contain: $needle"
  44. fi
  45. }
  46. main() {
  47. echo "=== Test: task-brief output paths ==="
  48. TEST_ROOT="$(mktemp -d)"
  49. trap cleanup EXIT
  50. local repo="$TEST_ROOT/repo"
  51. local plan="$repo/plan.md"
  52. local output_one
  53. local output_two
  54. local path_one
  55. local path_two
  56. git init -q -b main "$repo"
  57. cat > "$plan" <<'EOF'
  58. # Implementation Plan
  59. ## Task 1: First thing
  60. Do the first thing.
  61. ## Task 2: Second thing
  62. Do the second thing.
  63. EOF
  64. output_one="$(cd "$repo" && "$TASK_BRIEF" "$plan" 1)"
  65. output_two="$(cd "$repo" && "$TASK_BRIEF" "$plan" 1)"
  66. path_one="$(extract_written_path "$output_one")"
  67. path_two="$(extract_written_path "$output_two")"
  68. assert_not_equals "$path_one" "$path_two" "Default task brief paths are unique per invocation"
  69. assert_file_contains "$path_one" "## Task 1: First thing" "First default brief contains the requested task"
  70. assert_file_contains "$path_two" "## Task 1: First thing" "Second default brief contains the requested task"
  71. if [[ "$path_one" == "$repo/.git/sdd/"* ]]; then
  72. pass "First default brief stays under the repo git metadata directory"
  73. else
  74. fail "First default brief stays under the repo git metadata directory"
  75. echo " actual: $path_one"
  76. fi
  77. if [[ "$path_two" == "$repo/.git/sdd/"* ]]; then
  78. pass "Second default brief stays under the repo git metadata directory"
  79. else
  80. fail "Second default brief stays under the repo git metadata directory"
  81. echo " actual: $path_two"
  82. fi
  83. if [[ $FAILURES -ne 0 ]]; then
  84. echo ""
  85. echo "FAILED: $FAILURES assertion(s) failed."
  86. exit 1
  87. fi
  88. echo ""
  89. echo "PASS"
  90. }
  91. main "$@"