fix(tests): add --version handler to mock claude commands in prd_import tests

Mock claude commands in test_prd_import.bats were hanging on test 240
because they started with 'cat > /dev/null' which blocks waiting for stdin.
When ralph_import.sh calls 'claude --version' during dependency check,
no stdin is provided, causing indefinite hang.

Changes:
- Added --version flag handler to all 7 mock claude command generators
- Handler returns "Claude Code CLI version 2.0.80" and exits before stdin read
- Fixes hang in test 240 and ensures all 33 prd_import tests pass

This fix allows the quickstart installation to complete successfully
without test stalls.

Fixes #N/A (discovered during quickstart installation)
This commit is contained in:
Marty 2026-01-20 21:34:00 +00:00
parent 509a9699a8
commit 558b1518b5

View file

@ -105,6 +105,13 @@ create_mock_claude_success() {
cat > "$MOCK_BIN_DIR/claude" << 'MOCK_CLAUDE_EOF' cat > "$MOCK_BIN_DIR/claude" << 'MOCK_CLAUDE_EOF'
#!/bin/bash #!/bin/bash
# Mock Claude Code CLI that creates expected output files # Mock Claude Code CLI that creates expected output files
# Handle --version flag first (before reading stdin)
if [[ "$1" == "--version" ]]; then
echo "Claude Code CLI version 2.0.80"
exit 0
fi
# Read from stdin (conversion prompt) # Read from stdin (conversion prompt)
cat > /dev/null cat > /dev/null
@ -255,6 +262,13 @@ create_mock_claude_failure() {
cat > "$MOCK_BIN_DIR/claude" << 'MOCK_CLAUDE_FAIL_EOF' cat > "$MOCK_BIN_DIR/claude" << 'MOCK_CLAUDE_FAIL_EOF'
#!/bin/bash #!/bin/bash
# Mock Claude Code CLI that fails # Mock Claude Code CLI that fails
# Handle --version flag first
if [[ "$1" == "--version" ]]; then
echo "Claude Code CLI version 2.0.80"
exit 0
fi
echo "Error: Mock Claude Code failed" echo "Error: Mock Claude Code failed"
exit 1 exit 1
MOCK_CLAUDE_FAIL_EOF MOCK_CLAUDE_FAIL_EOF
@ -699,6 +713,13 @@ create_mock_claude_json_success() {
cat > "$MOCK_BIN_DIR/claude" << 'MOCK_CLAUDE_JSON_EOF' cat > "$MOCK_BIN_DIR/claude" << 'MOCK_CLAUDE_JSON_EOF'
#!/bin/bash #!/bin/bash
# Mock Claude Code CLI that outputs JSON format and creates expected files # Mock Claude Code CLI that outputs JSON format and creates expected files
# Handle --version flag first
if [[ "$1" == "--version" ]]; then
echo "Claude Code CLI version 2.0.80"
exit 0
fi
# Read from stdin (conversion prompt) # Read from stdin (conversion prompt)
cat > /dev/null cat > /dev/null
@ -776,6 +797,13 @@ create_mock_claude_json_partial() {
cat > "$MOCK_BIN_DIR/claude" << 'MOCK_CLAUDE_PARTIAL_EOF' cat > "$MOCK_BIN_DIR/claude" << 'MOCK_CLAUDE_PARTIAL_EOF'
#!/bin/bash #!/bin/bash
# Mock Claude Code CLI that outputs JSON but only creates some files # Mock Claude Code CLI that outputs JSON but only creates some files
# Handle --version flag first
if [[ "$1" == "--version" ]]; then
echo "Claude Code CLI version 2.0.80"
exit 0
fi
cat > /dev/null cat > /dev/null
# Only create PROMPT.md (missing @fix_plan.md and specs/requirements.md) # Only create PROMPT.md (missing @fix_plan.md and specs/requirements.md)
@ -811,6 +839,13 @@ create_mock_claude_json_error() {
cat > "$MOCK_BIN_DIR/claude" << 'MOCK_CLAUDE_JSON_ERROR_EOF' cat > "$MOCK_BIN_DIR/claude" << 'MOCK_CLAUDE_JSON_ERROR_EOF'
#!/bin/bash #!/bin/bash
# Mock Claude Code CLI that outputs JSON error response # Mock Claude Code CLI that outputs JSON error response
# Handle --version flag first
if [[ "$1" == "--version" ]]; then
echo "Claude Code CLI version 2.0.80"
exit 0
fi
cat > /dev/null cat > /dev/null
# Output JSON error response # Output JSON error response
@ -838,6 +873,13 @@ create_mock_claude_text_output() {
cat > "$MOCK_BIN_DIR/claude" << 'MOCK_CLAUDE_TEXT_EOF' cat > "$MOCK_BIN_DIR/claude" << 'MOCK_CLAUDE_TEXT_EOF'
#!/bin/bash #!/bin/bash
# Mock Claude Code CLI that outputs text (older CLI version) # Mock Claude Code CLI that outputs text (older CLI version)
# Handle --version flag first
if [[ "$1" == "--version" ]]; then
echo "Claude Code CLI version 2.0.80"
exit 0
fi
cat > /dev/null cat > /dev/null
# Create files # Create files
@ -1057,6 +1099,13 @@ CAPTURE_ARGS_EOF
@test "ralph-import handles malformed JSON and falls back to text parsing" { @test "ralph-import handles malformed JSON and falls back to text parsing" {
cat > "$MOCK_BIN_DIR/claude" << 'MALFORMED_JSON_EOF' cat > "$MOCK_BIN_DIR/claude" << 'MALFORMED_JSON_EOF'
#!/bin/bash #!/bin/bash
# Handle --version flag first
if [[ "$1" == "--version" ]]; then
echo "Claude Code CLI version 2.0.80"
exit 0
fi
cat > /dev/null cat > /dev/null
# Create files # Create files
@ -1097,6 +1146,13 @@ MALFORMED_JSON_EOF
@test "ralph-import extracts specific error message from JSON error" { @test "ralph-import extracts specific error message from JSON error" {
cat > "$MOCK_BIN_DIR/claude" << 'DETAILED_ERROR_EOF' cat > "$MOCK_BIN_DIR/claude" << 'DETAILED_ERROR_EOF'
#!/bin/bash #!/bin/bash
# Handle --version flag first
if [[ "$1" == "--version" ]]; then
echo "Claude Code CLI version 2.0.80"
exit 0
fi
cat > /dev/null cat > /dev/null
# Output detailed JSON error # Output detailed JSON error