|
| 1 | +#!/usr/bin/env bash |
| 2 | +# tests/scripts/test-dso-setup.sh |
| 3 | +# TDD red-phase tests for scripts/dso-setup.sh |
| 4 | +# |
| 5 | +# Verifies that dso-setup.sh installs the dso shim into a host project's |
| 6 | +# .claude/scripts/ directory and writes dso.plugin_root to workflow-config.conf. |
| 7 | +# |
| 8 | +# RED PHASE: All tests are expected to FAIL until scripts/dso-setup.sh is created. |
| 9 | +# |
| 10 | +# Usage: |
| 11 | +# bash tests/scripts/test-dso-setup.sh |
| 12 | +# Returns: exit 0 if all tests pass, exit 1 if any fail |
| 13 | + |
| 14 | +set -uo pipefail |
| 15 | + |
| 16 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 17 | +PLUGIN_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" |
| 18 | +SETUP_SCRIPT="$PLUGIN_ROOT/scripts/dso-setup.sh" |
| 19 | + |
| 20 | +source "$PLUGIN_ROOT/tests/lib/assert.sh" |
| 21 | + |
| 22 | +TMPDIRS=() |
| 23 | +trap 'rm -rf "${TMPDIRS[@]}"' EXIT |
| 24 | + |
| 25 | +echo "=== test-dso-setup.sh ===" |
| 26 | + |
| 27 | +# ── test_setup_creates_shim ─────────────────────────────────────────────────── |
| 28 | +# Running dso-setup.sh must create .claude/scripts/dso in the target directory. |
| 29 | +test_setup_creates_shim() { |
| 30 | + local T |
| 31 | + T=$(mktemp -d) |
| 32 | + TMPDIRS+=("$T") |
| 33 | + |
| 34 | + bash "$SETUP_SCRIPT" "$T" "$PLUGIN_ROOT" >/dev/null 2>&1 || true |
| 35 | + |
| 36 | + if [[ -f "$T/.claude/scripts/dso" ]]; then |
| 37 | + assert_eq "test_setup_creates_shim" "exists" "exists" |
| 38 | + else |
| 39 | + assert_eq "test_setup_creates_shim" "exists" "missing" |
| 40 | + fi |
| 41 | +} |
| 42 | + |
| 43 | +# ── test_setup_shim_executable ──────────────────────────────────────────────── |
| 44 | +# The installed shim must be executable (chmod +x). |
| 45 | +test_setup_shim_executable() { |
| 46 | + local T |
| 47 | + T=$(mktemp -d) |
| 48 | + TMPDIRS+=("$T") |
| 49 | + |
| 50 | + bash "$SETUP_SCRIPT" "$T" "$PLUGIN_ROOT" >/dev/null 2>&1 || true |
| 51 | + |
| 52 | + if [[ -x "$T/.claude/scripts/dso" ]]; then |
| 53 | + assert_eq "test_setup_shim_executable" "executable" "executable" |
| 54 | + else |
| 55 | + assert_eq "test_setup_shim_executable" "executable" "not-executable" |
| 56 | + fi |
| 57 | +} |
| 58 | + |
| 59 | +# ── test_setup_writes_plugin_root ───────────────────────────────────────────── |
| 60 | +# Running dso-setup.sh must write dso.plugin_root=<path> to workflow-config.conf |
| 61 | +# in the target directory. |
| 62 | +test_setup_writes_plugin_root() { |
| 63 | + local T |
| 64 | + T=$(mktemp -d) |
| 65 | + TMPDIRS+=("$T") |
| 66 | + |
| 67 | + bash "$SETUP_SCRIPT" "$T" "$PLUGIN_ROOT" >/dev/null 2>&1 || true |
| 68 | + |
| 69 | + local result="missing" |
| 70 | + if grep -q "^dso.plugin_root=" "$T/workflow-config.conf" 2>/dev/null; then |
| 71 | + result="exists" |
| 72 | + fi |
| 73 | + assert_eq "test_setup_writes_plugin_root" "exists" "$result" |
| 74 | +} |
| 75 | + |
| 76 | +# ── test_setup_is_idempotent ────────────────────────────────────────────────── |
| 77 | +# Running dso-setup.sh twice must not duplicate the dso.plugin_root entry. |
| 78 | +# Also: running setup on a target that already has a different dso.plugin_root |
| 79 | +# entry must update it (not add a second line). |
| 80 | +test_setup_is_idempotent() { |
| 81 | + local T |
| 82 | + T=$(mktemp -d) |
| 83 | + TMPDIRS+=("$T") |
| 84 | + |
| 85 | + # Run twice — must not duplicate the entry |
| 86 | + bash "$SETUP_SCRIPT" "$T" "$PLUGIN_ROOT" >/dev/null 2>&1 || true |
| 87 | + bash "$SETUP_SCRIPT" "$T" "$PLUGIN_ROOT" >/dev/null 2>&1 || true |
| 88 | + |
| 89 | + local count=0 |
| 90 | + count=$(grep -c "^dso.plugin_root=" "$T/workflow-config.conf" 2>/dev/null || echo "0") |
| 91 | + assert_eq "test_setup_is_idempotent" "1" "$count" |
| 92 | + |
| 93 | + # Also verify: pre-existing entry with different path is replaced, not duplicated |
| 94 | + local T2 |
| 95 | + T2=$(mktemp -d) |
| 96 | + TMPDIRS+=("$T2") |
| 97 | + echo "dso.plugin_root=/old/path" > "$T2/workflow-config.conf" |
| 98 | + bash "$SETUP_SCRIPT" "$T2" "$PLUGIN_ROOT" >/dev/null 2>&1 || true |
| 99 | + |
| 100 | + local count2=0 |
| 101 | + count2=$(grep -c "^dso.plugin_root=" "$T2/workflow-config.conf" 2>/dev/null || echo "0") |
| 102 | + assert_eq "test_setup_is_idempotent (pre-existing entry)" "1" "$count2" |
| 103 | +} |
| 104 | + |
| 105 | +# ── test_setup_dso_tk_help_works ────────────────────────────────────────────── |
| 106 | +# After setup, invoking the installed shim with 'tk --help' (without |
| 107 | +# CLAUDE_PLUGIN_ROOT set — forcing the shim to read from workflow-config.conf) |
| 108 | +# must exit 0. |
| 109 | +test_setup_dso_tk_help_works() { |
| 110 | + local T |
| 111 | + T=$(mktemp -d) |
| 112 | + TMPDIRS+=("$T") |
| 113 | + |
| 114 | + bash "$SETUP_SCRIPT" "$T" "$PLUGIN_ROOT" >/dev/null 2>&1 || true |
| 115 | + |
| 116 | + local exit_code=0 |
| 117 | + ( |
| 118 | + cd "$T" |
| 119 | + unset CLAUDE_PLUGIN_ROOT |
| 120 | + "./.claude/scripts/dso" tk --help >/dev/null 2>&1 |
| 121 | + ) || exit_code=$? |
| 122 | + assert_eq "test_setup_dso_tk_help_works" "0" "$exit_code" |
| 123 | +} |
| 124 | + |
| 125 | +# REVIEW-DEFENSE: Error-path tests (missing arguments, invalid TARGET_DIR) are out of |
| 126 | +# scope for this RED-phase task. The RED phase covers the happy-path contract that the |
| 127 | +# script must satisfy. Error-path and edge-case coverage belongs in the GREEN implementation |
| 128 | +# task (dso-jl2z), where the script's full interface is defined and tested. |
| 129 | + |
| 130 | +# ── Run all tests ───────────────────────────────────────────────────────────── |
| 131 | +test_setup_creates_shim |
| 132 | +test_setup_shim_executable |
| 133 | +test_setup_writes_plugin_root |
| 134 | +test_setup_is_idempotent |
| 135 | +test_setup_dso_tk_help_works |
| 136 | + |
| 137 | +print_summary |
0 commit comments