From 266fbf94b24b7c1ffafb0476b3ca9f2ce8e7abcf Mon Sep 17 00:00:00 2001 From: creazyfrog Date: Sun, 21 Jun 2026 22:40:03 -0700 Subject: [PATCH] fix(tests): resolve shellcheck warnings in Claude Code test helpers - SC2155: declare local vars separately from assignment so that mktemp or grep failures are not silently masked by 'local' exit-code 0 - SC2320: capture $? into exit_code before the first echo in the failure handler; without this the error message always printed 'exit code: 0' regardless of the real failure exit code - SC2064: replace inline trap string expansion with a _cleanup() wrapper so shellcheck can verify the variable reference is intentional - SC2088: add disable comments on tilde literals in test-worktree- path-policy.sh where ~ is intentionally not expanded (grep -F checks for the literal string '~/.config/...' in skill Markdown text) --- tests/claude-code/test-helpers.sh | 14 +++++++++----- ...test-subagent-driven-development-integration.sh | 6 ++++-- tests/claude-code/test-worktree-path-policy.sh | 4 ++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/tests/claude-code/test-helpers.sh b/tests/claude-code/test-helpers.sh index 1b5ead3b44..b165183e54 100755 --- a/tests/claude-code/test-helpers.sh +++ b/tests/claude-code/test-helpers.sh @@ -7,7 +7,8 @@ run_claude() { local prompt="$1" local timeout="${2:-60}" local allowed_tools="${3:-}" - local output_file=$(mktemp) + local output_file + output_file=$(mktemp) # Build command as an argv array so timeout wraps claude directly. local cmd=(claude -p "$prompt") @@ -74,7 +75,8 @@ assert_count() { local expected="$3" local test_name="${4:-test}" - local actual=$(echo "$output" | grep -c "$pattern" || echo "0") + local actual + actual=$(echo "$output" | grep -c "$pattern" || echo "0") if [ "$actual" -eq "$expected" ]; then echo " [PASS] $test_name (found $actual instances)" @@ -98,8 +100,9 @@ assert_order() { local test_name="${4:-test}" # Get line numbers where patterns appear - local line_a=$(echo "$output" | grep -n "$pattern_a" | head -1 | cut -d: -f1) - local line_b=$(echo "$output" | grep -n "$pattern_b" | head -1 | cut -d: -f1) + local line_a line_b + line_a=$(echo "$output" | grep -n "$pattern_a" | head -1 | cut -d: -f1) + line_b=$(echo "$output" | grep -n "$pattern_b" | head -1 | cut -d: -f1) if [ -z "$line_a" ]; then echo " [FAIL] $test_name: pattern A not found: $pattern_a" @@ -125,7 +128,8 @@ assert_order() { # Create a temporary test project directory # Usage: test_project=$(create_test_project) create_test_project() { - local test_dir=$(mktemp -d) + local test_dir + test_dir=$(mktemp -d) echo "$test_dir" } diff --git a/tests/claude-code/test-subagent-driven-development-integration.sh b/tests/claude-code/test-subagent-driven-development-integration.sh index a783648314..dec53991c1 100755 --- a/tests/claude-code/test-subagent-driven-development-integration.sh +++ b/tests/claude-code/test-subagent-driven-development-integration.sh @@ -37,7 +37,8 @@ TEST_PROJECT=$(create_test_project) echo "Test project: $TEST_PROJECT" # Trap to cleanup -trap "cleanup_test_project $TEST_PROJECT" EXIT +_cleanup() { cleanup_test_project "$TEST_PROJECT"; } +trap _cleanup EXIT # Set up minimal Node.js project cd "$TEST_PROJECT" @@ -165,9 +166,10 @@ PLUGIN_DIR=$(cd "$SCRIPT_DIR/../.." && pwd) echo "Running Claude (plugin-dir: $PLUGIN_DIR, cwd: $TEST_PROJECT)..." echo "================================================================================" cd "$TEST_PROJECT" && timeout 1800 claude -p "$PROMPT" --plugin-dir "$PLUGIN_DIR" --allowed-tools=all --permission-mode bypassPermissions 2>&1 | tee "$OUTPUT_FILE" || { + exit_code=$? echo "" echo "================================================================================" - echo "EXECUTION FAILED (exit code: $?)" + echo "EXECUTION FAILED (exit code: $exit_code)" exit 1 } echo "================================================================================" diff --git a/tests/claude-code/test-worktree-path-policy.sh b/tests/claude-code/test-worktree-path-policy.sh index 58caad7a09..5185dfbdc7 100755 --- a/tests/claude-code/test-worktree-path-policy.sh +++ b/tests/claude-code/test-worktree-path-policy.sh @@ -47,15 +47,19 @@ assert_not_contains() { echo "=== Worktree Path Policy Test ===" echo "" +# shellcheck disable=SC2088 # Tilde is intentional: checking for the literal string "~/.config/..." in skill file text assert_not_contains "$USING_SKILL" "~/.config/superpowers/worktrees" "using-git-worktrees does not mention old global path" assert_not_contains "$USING_SKILL" "global legacy" "using-git-worktrees does not use unclear global legacy shorthand" assert_not_contains "$USING_SKILL" "Global path" "using-git-worktrees has no global path quick-reference row" assert_contains "$USING_SKILL" 'default to `.worktrees/` at the project root' "using-git-worktrees defaults new manual worktrees to .worktrees/" +# shellcheck disable=SC2088 # Tilde is intentional: checking for the literal string "~/.config/..." in skill file text assert_not_contains "$FINISHING_SKILL" "~/.config/superpowers/worktrees" "finishing-a-development-branch does not treat old global path as owned" assert_contains "$FINISHING_SKILL" '`.worktrees/` or `worktrees/`' "finishing-a-development-branch keeps project-local cleanup ownership" +# shellcheck disable=SC2088 # Tilde is intentional: checking for the literal string "~/.config/..." in skill file text assert_not_contains "$ROTOTILL_SPEC" "~/.config/superpowers/worktrees" "rototill spec does not preserve old global path policy" +# shellcheck disable=SC2088 # Tilde is intentional: checking for the literal string "~/.config/..." in skill file text assert_not_contains "$ROTOTILL_PLAN" "~/.config/superpowers/worktrees" "rototill plan does not preserve old global path policy" assert_not_contains "$ROTOTILL_PLAN" "legacy path compat" "rototill plan does not advertise legacy path compatibility"